用于 IOS 刷新控制 React Native 的 ProgressViewOffset

Gow*_*ham 2 scrollview ios react-native react-native-flatlist

我有一个隐藏在滚动条上的标题,所以我用来ProgressViewOffset在标题下方显示刷新控制加载器。
它在 Android 上运行良好。但是在 IOS 中我们不支持偏移。但我最终使用了 contentInset 和 contentOffset 但我没有得到它。

在此处输入图片说明

          refreshControl: (
        <RefreshControl
          // refreshing
          refreshing={this.props.isloading}
          onRefresh={this.onRefresh}
          progressViewOffset={200}
          />
      ),
      contentInset: {top: 200},
      onMomentumScrollBegin,
      onMomentumScrollEnd,
      onScrollEndDrag,
      ItemSeparatorComponent: this.renderSeparator,
      onScrollEventThrottle: 16,
      automaticallyAdjustContentInsets: false, 
      contentOffset: {x: 0, y: -200},
Run Code Online (Sandbox Code Playgroud)

PS:当我使用 contentContainerStyle 和 contentInset 时,refreshcontrol 和内容之间有一个空格...

Gow*_*ham 10

我通过将 HEADER_HEIGHT 传递给 contentInset、contentOffset 而不使用 contentContainerStyle 来修复它。

<AnimatedScrollView
  contentContainerStyle={{
    paddingTop: Platform.OS === 'ios' ? 0 : HEADER_HEIGHT,
  }}
  scrollEventThrottle={16}
  onScroll={Animated.event(
    [{ nativeEvent: { contentOffset: { y: this.state.scrollAnim } } }],
    { useNativeDriver: true }
  )}
  contentInset={{ top: HEADER_HEIGHT }}
  contentOffset={{ x: 0, y: -HEADER_HEIGHT }}
  refreshControl={
    <RefreshControl
      refreshing={this.state.refreshing}
      onRefresh={this.onrefresh}
      progressViewOffset={HEADER_HEIGHT}
    />
  }
  automaticallyAdjustContentInsets={false}

</AnimatedScrollView>
Run Code Online (Sandbox Code Playgroud)

在 Snack 上运行代码:https : //snack.expo.io/@legowtham/9c7a01

PS:当我们使用自定义动画标题时,下拉刷新加载器会导致标题在加载器停止后弹跳。如果您不喜欢这个动画问题,请使用 Animated.diffClamp 来避免这种情况。这篇文章可能有用:https : //medium.com/appandflow/react-native-collapsible-navbar-e51a049b560a