requireExternalGestureToFail is not able to block a ScrollView

未关闭
#3,266 5 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
javascript, react-native
领域
mobile

调研方向

首先,使用报告中的 React Native 0.76.3 和 gesture-handler 2.20.2 设置,通过 Gesture.Native().requireExternalGestureToFail(pan) 在链接的 Snack 中重现 iOS 行为。跟踪此入口点背后的原生手势交互,并验证在识别 Pan 时 ScrollView 会被阻塞。

由索引模型根据 Issue 内容生成。

描述

Platform: iOS Repro provided
Description

According to the docs, requireExternalGestureToFail is like the inverse of blocksExternalGesture.

However, I can't actually get requireExternalGestureToFail to do anything useful with a native gesture.

In particular, I want to block ScrollView if my Pan is being recognized.

The docs lead me to believe that this code would work:

import {View} from 'react-native'
import {
  Gesture,
  GestureDetector,
  GestureHandlerRootView,
  ScrollView,
} from 'react-native-gesture-handler'

export default function App() {
  const pan = Gesture.Pan()
    .onBegin(() => {
      'worklet'
      console.log('begin')
    })
    .onUpdate(() => {
      'worklet'
      console.log('update')
    })
    .onEnd(() => {
      'worklet'
      console.log('end')
    })
    .onFinalize(() => {
      'worklet'
      console.log('finalize')
    })
  return (
    <GestureHandlerRootView>
      <GestureDetector gesture={pan}>
        <View style={{flex: 1, backgroundColor: 'blue'}}>
          <ScrollViewExample pan={pan} />
        </View>
      </GestureDetector>
    </GestureHandlerRootView>
  )
}

function ScrollViewExample({pan}) {
  const native = Gesture.Native().requireExternalGestureToFail(pan)
  return (
    <GestureDetector gesture={native}>
      <ScrollView
        horizontal
        pagingEnabled
        style={{
          flex: 1,
          backgroundColor: 'yellow',
        }}>
        <View
          style={{
            width: 200,
            height: '100%',
            backgroundColor: 'green',
          }}
        />
        <View
          style={{
            width: 200,
            height: '100%',
            backgroundColor: 'purple',
          }}
        />
      </ScrollView>
    </GestureDetector>
  )
}

But it doesn't do anything. The ScrollView is still in control of the gesture.

Steps to reproduce
  1. Drag the ScrollView
  2. The ScrollView gets dragged, but it should have been blocked by the Pan

https://github.com/user-attachments/assets/5950c53a-0f46-4060-83ac-6f414b87fe59

Snack or a link to a repository

https://snack.expo.dev/k1-MTyYfvD3wQNk3sr_je

Gesture Handler version

2.20.2

React Native version

0.76.3

Platforms

iOS

JavaScript runtime

Hermes

Workflow

Expo bare workflow

Architecture

Paper (Old Architecture)

Build type

Debug mode

Device

Real device

Device model

No response

Acknowledgements

Yes

主要语言
TypeScript
星标
6.8k
派生
1.1k
平均合并
2 天 17 小时
30 天内合并 PR
28

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

software-mansion/react-native-gesture-handler 的其他 Issue

查看 software-mansion/react-native-gesture-handler 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。