-
-
Notifications
You must be signed in to change notification settings - Fork 439
Description
My
project has
react-native-draggable-flatlist": "^4.0.3
react-native-gesture-handler": "^2.25.0
react-native-reanimated": "^3.17.0
And My Code is
<DraggableFlatList data={productData ?? []} keyExtractor={(item: { id: number }) => item?.id.toString()} renderItem={renderItem} containerStyle={{ flex: 1 }} onRelease={() => setTimeout(() => setTransparentLoad(true))} onDragEnd={({ data }) => { if (JSON?.stringify(productData) != JSON.stringify(data)) { setProductData(data); dispatch(setIsDirtyPage(true)); setTimeout(() => { setIsChanged(true); setTransparentLoad(false); }); } else { // Use a timeout here too, to avoid layout jitter setTimeout(() => setTransparentLoad(false), 50); } }} autoscrollSpeed={150} autoscrollThreshold={80} showsVerticalScrollIndicator={false} contentContainerStyle={{ flex: productData?.length ? undefined : 1, paddingBottom: productData?.length ? 100 : undefined }} ListEmptyComponent={<ListEmpty image={"no-featured-products.png"} text={translate("NO_PRODUCTS_TEXT")} />} />
And my render Item is
const renderItem = ({ item, drag, index }: any) => { return ( <ScaleDecorator> <TouchableOpacity key={index} onPress={() => { selectProducts({ id: item?.id }) }} style={{ flex: 1, marginHorizontal: 13, marginTop: 15, paddingHorizontal: width > 600 ? 20 : 10, paddingVertical: width > 600 ? 10 : 5, borderWidth: item?.select ? 1.1 : 1, borderRadius: 5, borderColor: item?.select ? appColors?.primary : appColors?.borderColor }}> <View style={{ flex: 1, flexDirection: "row", justifyContent: "space-between", gap: 10, backgroundColor: "" }}> <View style={{ flex: 1, flexDirection: "row", gap: 20, alignItems: "center", backgroundColor: "" }}> <Image style={{ height: 60, width: 60 }} source={{ uri: config.AWSImageUrl + (item?.featuredImage ?? "mobileAdmin/no-image.jpg") }} resizeMode="contain" resizeMethod='resize' PlaceholderContent={ <Image style={{ height: 60, width: 60 }} source={{ uri: config?.AWSImageUrl + "mobileAdmin/no-image.jpg" }} resizeMode="contain" resizeMethod='resize' /> } /> <View style={{ flex: 1 }}> <Text ellipsizeMode="tail" numberOfLines={2} style={{ color: appColors?.primary, flexWrap: "wrap", fontFamily: appFonts?.bold, fontSize: smallerFontSize }}>{item?.name?.replace(/\s+/g, " ")}</Text> <Text style={{ fontSize: tinyFontSize, color: appColors?.lightDark, fontFamily: appFonts?.bold }}>{
${translate("PRICE")} : }{CommonService?.currencyFormatter(item?.price)}</Text> </View> </View> <TouchableOpacity hitSlop={{ bottom: 10, left: 10, right: 10, top: 10 }} onPressIn={() => !item?.select ? drag() : undefined} style={{ backgroundColor: "", justifyContent: "center", flex: 0.15, alignItems: "flex-end", marginRight: 10 }}> {item?.select ? <MaterialCommunityIcons name={'check-circle'} color={appColors?.checkCircleGreen} size={22} /> : <MaterialCommunityIcons name="drag-horizontal-variant" color={appColors?.iconColor} size={25} /> } </TouchableOpacity> </View> </TouchableOpacity> </ScaleDecorator > ) }
And I Attached Video