React Native是否真的支持Android片段? [英] Does React Native Really Support Android Fragments?

查看:60
本文介绍了React Native是否真的支持Android片段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题很难回答.

  • ReactFragmentActivity确实存在于React Native BUT的主分支中

  • ReactFragmentActivity does exist in master branch of React Native, BUT

创建React片段存在一个未解决的问题,请参见 https://github.com/facebook/react-native/pull/12199/commits/e5b68717f57c41f5f1e77c289bdb4f673bb242f1 //这尚未获得批准,但已确认需要.

There is an open issue to create a React Fragment see https://github.com/facebook/react-native/pull/12199/commits/e5b68717f57c41f5f1e77c289bdb4f673bb242f1 // This has not been approved yet, but the need was acknowledged.

我已经在github等上查看了数十个React Native示例,并且从未显示过片段.请证明我错了!

I have looked at dozens of React Native examples on github etc, and fragments are never shown. Prove me wrong please!

显然并非不可能,请参见:片段内的本机但是此解决方案似乎无法完全处理触摸事件.

It's apparently not impossible see: React-native inside a Fragment but this solution seems not to fully deal with touch events.

我的印象是,React Native主要集中在控制布局整个活动的根视图上.我认为在处理碎片时要格外小心.附带说明一下,React本身(不是React Native)似乎有其自己的片段概念.我猜甚至React Native flexible内部的Yoga布局管理器也是如此,因为它不想处理Android Fragments.对于新应用程序而言,这并不是什么大问题,但对于将React Native集成到现有应用程序中来说,这是真正的问题!

My impression is that React Native is primarily focused around controlling the root view of the whole activity for layouts. I think there is some caution being used in taking on fragments. As a side note React itself (not React Native) seems to have its own concept of a fragment. I am guessing even Yoga layout manager inside React Native flexible as it is does not want to deal with Android Fragments. Not an issue so much for new apps but for integrating React Native into existing apps this is real issue!

推荐答案

2021年初:我还创建了与此相关的博客文章:

early 2021: I have created also blog post about it: https://stefanmajiros.medium.com/integration-of-native-android-fragments-and-views-into-react-native-a4156621543b

通常,您只需要在React Native(作为本机UI组件)中渲染占位符,然后就需要在React Native中找到该占位符的ID,将ID发送给本机部件,并执行将片段附加到其中的命令.视图,类似于此:

In general, you just render placeholder in React Native (as native UI component), then you would need find the id of that placeholder in React Native, send the id to the native part, and execute command that will attach fragment to the view, similar to this:

getSupportFragmentManager()
.beginTransaction()
.add(placeholderId, yourfragment, "sometag")
.commit();

这篇关于React Native是否真的支持Android片段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆