reactnativecn / react-native-website

React Native 中文网
https://reactnative.cn
MIT License
216 stars 327 forks source link

ScrollView嵌套,手势问题 #704

Closed guoyw closed 1 year ago

guoyw commented 1 year ago

问题

大概效果:父ScrollView内嵌子ScrollView,子ScrollView先做第一响应者,滚动过程中当到达某个条件,切换到父ScrollView作为第一响应者。子ScrollView不再滚动,父ScrollView继续滚动。

代码

const App = () => {
  const [enableScroll, setEnableScroll] = React.useState(false)
  return (
    <View style={{ flex:1 }} >
      <ScrollView 
      onMoveShouldSetResponderCapture={() => enableScroll}           
      scrollEventThrottle={1} >
        <ScrollView style={{ height: 500, }}
          onTouchStart={() => {
            setEnableScroll(false)
          }}
          scrollEventThrottle={1}
          onScroll={({ nativeEvent }) => {
            const offsetY = nativeEvent.contentOffset.y
            if (offsetY > 50) {
              setEnableScroll(true)
            } else {
              setEnableScroll(false)
            }
          }}>
          <View style={{  height: 1000, backgroundColor: 'lightgreen' }}></View>
        </ScrollView>
        <View style={{ height: 1000,  backgroundColor: 'skyblue' }}></View>
      </ScrollView>
    </View>
  )
}

预期结果

如代码所示 ,滚动过程中 ,enableScroll = true了,响应者还是子ScrollView。这是哪里出来问题?

sunnylqm commented 1 year ago

这个思路实现不了的,只能用 react-native-gesture-handler + reanimated 去模拟

sunnylqm commented 1 year ago

参考 https://github.com/gorhom/react-native-bottom-sheet/blob/master/src/components/bottomSheetScrollable/createBottomSheetScrollableComponent.tsx

guoyw commented 1 year ago

这个思路实现不了的,只能用 react-native-gesture-handler + reanimated 去模拟

是什么原因导致的?发现ScrollView对onShouldSetResponderCapture 、onResponder 等触发都很混乱。滚动的级别更高。

sunnylqm commented 1 year ago

简单来说,官方的手势系统没有实现这些复杂的交互

guoyw commented 1 year ago

简单来说,官方的手势系统没有实现这些复杂的交互

了解,谢谢