Edit: There seems to be a bug in React Native. I have created a bug on GitHub. For everyone coming for a solution: There seems to be none at the moment.
https://github.com/facebook/react-native/issues/23988
––––
I'm using a translucent header, which is why I gave the ScrollView
a paddingTop
to offset the content. When I pull down to refresh, the spinner is still at the top.
I have tried to use contentInset={{ top: 80 }}
to offset everything, but there is an issue on iOS where it sometimes is not picked up correctly and set to 0
.
Are there any other ways to get the RefreshControl to start lower?
This is my component:
<Animated.ScrollView
scrollEventThrottle={1}
onScroll={Animated.event(
[{ nativeEvent: { contentOffset: { y: this.state.scrollY } } }],
{ useNativeDriver: true },
)}
contentInset={{ top: headerHeight() + 10 }}
>
Setup Pull to Refresh Pull to Refresh functionality is implemented using RefreshControl component in React Native. RefreshControl is used inside a ScrollView or ListView to add pull to refresh functionality. When the ScrollView is at scrollY: 0 , swiping down triggers an onRefresh event.
React Native RefreshControl If you're rendering a list of data using the ScrollView or FlatList component, you can use RefreshControl to add the pull-to-refresh capability. When you initiate the pull-to-refresh gesture, RefreshControl triggers an onRefresh event.
To refresh a page, you need to use the javascript window. location. reload() in React apps.
Pull to Refresh functionality is implemented using RefreshControl component in React Native. RefreshControl is used inside a ScrollView or ListView to add pull to refresh functionality. When the ScrollView is at scrollY: 0, swiping down triggers an onRefresh event. In our example, we are using a FlatList component to display the list.
The closest rivals of React Native are Flutter and Ionic. TLDR; — React Native (RN) apps are more “native” than web-view apps made by Cordova / Ionic. React Native crates actual Java and Swift codes for apps, unlike the web-view apps which essentially run in a … web-view.
We will implement this in a simple React Native app and test on device. Pull-to-refresh is the functionality we use to refresh data in our apps, where we pull the screen towards bottom to load new data. See example below
Because most of the code you write can be shared between platforms, React Native makes it easy to simultaneously develop for both Android and iOS. React Native applications render using real mobile UI components, not web-views, and will look and feel like any other native mobile application.
Did you set padding for the style
or for the contentContainerStyle
?
Can you provide some code snippet what properties does your ScrollView have and by what is wrapped?
I resolved like this.
contentInset={{ top: headerHeight }}
contentOffset={{y: -headerHeight}}
I use these props to FlatList.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With