Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Offset RefreshControl in React Native

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?

enter image description here

This is my component:

  <Animated.ScrollView
    scrollEventThrottle={1}
    onScroll={Animated.event(
      [{ nativeEvent: { contentOffset: { y: this.state.scrollY } } }],
      { useNativeDriver: true },
    )}
    contentInset={{ top: headerHeight() + 10 }}
  >
like image 553
mxmtsk Avatar asked Feb 28 '19 21:02

mxmtsk


People also ask

How do you implement pull down to refresh in react native?

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.

How do I reload screen in react native automatically?

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.

How do you refresh a react app?

To refresh a page, you need to use the javascript window. location. reload() in React apps.

How to add pull to refresh functionality in React Native?

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.

What are the rivals of React Native?

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.

What is pull-to-refresh in React Native?

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

Can I use React Native on both Android and iOS?

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.


2 Answers

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?

like image 132
kodeusz Avatar answered Oct 18 '22 17:10

kodeusz


I resolved like this.

contentInset={{ top: headerHeight }}
contentOffset={{y: -headerHeight}}

I use these props to FlatList.

like image 29
Wayne Kim Avatar answered Oct 18 '22 19:10

Wayne Kim