让触摸在 React Native Android 嵌入式片段中传递?
Let touches pass through in React Native Android embedded fragment?
我有一个片段,它嵌入了一个 React Native 应用程序,该应用程序在本机片段上加载视图。我的观点在两个移动平台上都有展示,并且在 iOS 上完美运行。我能够激活名为 RCTRootView.passThroughTouches
的 属性
有没有什么方法可以让触摸通过视图与后面的原生视图交互?
我的片段是按照 https://reactnative.dev/docs/integration-with-android-fragment 中的步骤创建的,并像这样添加到我的布局中:
val reactNativeFragment = ReactFragment.Builder()
.setComponentName("MainFABActionsContainer")
.build()
childFragmentManager
.beginTransaction()
.add(R.id.fab_actions, reactNativeFragment)
.commit()
我的 XML 中的框架布局如下所示:
<FrameLayout
android:id="@+id/fab_actions"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
谢谢!
已经很长时间了,但我只是回答一下,以防将来有人遇到这个问题。问题的原因是 React Native 在自定义视图调用 ReactRootView
中绘制了所有内容。此视图将实现 onTouchEvent
和 return true
,这意味着它将处理触摸事件而不是将其分派给下面的所有视图。为了修复它,我覆盖了根视图的 onTouchEvent
并将 return 值更改为 false
.
所以步骤是
- 创建
CustomReactFragment
喜欢 this
- 创建
CustomReactDelegate
喜欢 this
- 为我的屁股sheet创建
CustomReactRootView
如this. Note that in CustomReactRootView
, I extend RNGestureHandlerEnabledRootView
because I use React Native getsure handler,你可以将其更改为ReactRootView
。
现在您可以将 ReactFragment.Builder()
替换为 CustomReactFragment.Builder()
以启动您的 React Native Fragment。
我有一个片段,它嵌入了一个 React Native 应用程序,该应用程序在本机片段上加载视图。我的观点在两个移动平台上都有展示,并且在 iOS 上完美运行。我能够激活名为 RCTRootView.passThroughTouches
的 属性有没有什么方法可以让触摸通过视图与后面的原生视图交互?
我的片段是按照 https://reactnative.dev/docs/integration-with-android-fragment 中的步骤创建的,并像这样添加到我的布局中:
val reactNativeFragment = ReactFragment.Builder()
.setComponentName("MainFABActionsContainer")
.build()
childFragmentManager
.beginTransaction()
.add(R.id.fab_actions, reactNativeFragment)
.commit()
我的 XML 中的框架布局如下所示:
<FrameLayout
android:id="@+id/fab_actions"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
谢谢!
已经很长时间了,但我只是回答一下,以防将来有人遇到这个问题。问题的原因是 React Native 在自定义视图调用 ReactRootView
中绘制了所有内容。此视图将实现 onTouchEvent
和 return true
,这意味着它将处理触摸事件而不是将其分派给下面的所有视图。为了修复它,我覆盖了根视图的 onTouchEvent
并将 return 值更改为 false
.
所以步骤是
- 创建
CustomReactFragment
喜欢 this - 创建
CustomReactDelegate
喜欢 this - 为我的屁股sheet创建
CustomReactRootView
如this. Note that inCustomReactRootView
, I extendRNGestureHandlerEnabledRootView
because I use React Native getsure handler,你可以将其更改为ReactRootView
。
现在您可以将 ReactFragment.Builder()
替换为 CustomReactFragment.Builder()
以启动您的 React Native Fragment。