ScrollView:如何为Android重现snapToInterval和snapToAlignment?

Yup*_*aks 5 android react-native

我正在寻找一种以特定间隔滚动水平菜单的方法.

I have multiple children visible on screen

我在屏幕上看到多个孩子

选定的州处于中心位置.

将snapToInterval与snapToAlignement结合使用可以满足我的需求,但这些道具仅适用于iOS.

有没有办法实现这个目标?我想PanResponder API可以使用,但我不知道如何实现它.

我使用0.28 RN版本.谢谢.

<ScrollView
  decelerationRate={0}
  horizontal
  snapToAlignment="center"
  snapToInterval={150}
>
  {this.props.children}
</ScrollView>
Run Code Online (Sandbox Code Playgroud)

Kev*_* Li 2

有一个关于此问题的拉取请求:https://github.com/facebook/react-native/pull/15297

还有一个库https://github.com/machadogj/react-native-carousel-control?files=1支持 Android 和 iOS 滑动,它控制滚动行为本身,但我尝试了,它有效,但与snapToInterval和相比就不那么顺利了snapToAlignment

另一种但更复杂的轮播滑动在这里:https ://github.com/archriss/react-native-snap-carousel

希望您能基于这些获得更多见解。

  • 从 RN 0.53.0 开始,这现在也在 android 中实现 https://github.com/facebook/react-native/releases/tag/v0.53.0 (4认同)