Dynamic data loading #404
Replies: 6 comments 1 reply
-
Can you share your code showing what you are trying to do?
What do you exactly mean? |
Beta Was this translation helpful? Give feedback.
-
![]() there is empty grids in the image it comes when i fetch the data again |
Beta Was this translation helpful? Give feedback.
-
import React from 'react';
import { View, StyleSheet } from 'react-native';
// import type { SortableGridRenderItem } from 'react-native-sortables';
import Sortable from 'react-native-sortables';
import Animated, { useAnimatedRef } from 'react-native-reanimated';
import { isTablet } from 'react-native-device-info';
export default function Grid({ data, renderItem, handleEndReached }) {
console.log('data -----', data);
const scrollableRef = useAnimatedRef<Animated.ScrollView>();
const handleScroll = (event) => {
const { layoutMeasurement, contentOffset, contentSize } = event.nativeEvent;
// Define a threshold (e.g., 50 pixels from the bottom)
// You can adjust this value based on how early you want to trigger the load
const scrollThreshold = 5;
// Check if the sum of visible height and current scroll position
// is greater than or equal to the total content height minus the threshold.
const isCloseToBottom =
layoutMeasurement.height + contentOffset.y >=
contentSize.height - scrollThreshold;
// Now, you can use 'isCloseToBottom' in your logic:
if (isCloseToBottom) {
// console.log('Scroll has reached near the bottom!');
handleEndReached();
// Trigger your load more function here,
// e.g., fetchMoreData();
}
};
return (
<View style={styles.container}>
<Animated.ScrollView
ref={scrollableRef}
showsVerticalScrollIndicator={false}
onScroll={handleScroll}
// scrollEventThrottle={16}
>
<Sortable.Grid
columns={isTablet() ? 3 : 1}
data={data} // Pass your data here
renderItem={renderItem}
rowGap={10}
columnGap={10}
autoScrollEnabled={true}
scrollableRef={scrollableRef}
autoScrollActivationOffset={75}
// onScroll={handleScroll}
// scrollEventThrottle={16}
customHandle
// onDragStart={() => {
// console.log('--- SORTABLE.GRID DRAG BEGINNING! (Problem Page) ---'); // ADD THIS LINE
// }}
// onDragEnd={(data) => {
// console.log('drag ended---', data);
// }}
// customHandle
/>
</Animated.ScrollView>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
}); |
Beta Was this translation helpful? Give feedback.
-
handleEndReached() |
Beta Was this translation helpful? Give feedback.
-
I have an example in the example app that tests similar case, when new data is added to the Simulator.Screen.Recording.-.iPhone.16.Pro.-.2025-06-19.at.16.54.03.mp4Would you be able to prepare a reproduction repository with this code or give me the source code of the complete reproduction that I would be able to copy and paste to test it locally on my side? Can you also give me more details:
|
Beta Was this translation helpful? Give feedback.
-
i have doubt like is this library have any rendering issue when we give data of 40 to 80 items |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have tried to render 100+ items with pagination
first i have rendered 20 items
then using pagination i have fetched 20 again
But there comes empty grids
how can i over come this i already seen a response of how to list 100+ items question
but here i am not trying to render 100 at a time.
Beta Was this translation helpful? Give feedback.
All reactions