com.facebook.react.uimanager.IllegalViewOperationException:试图添加未知的视图标签 [英] com.facebook.react.uimanager.IllegalViewOperationException: Trying to add unknown view tag

查看:26
本文介绍了com.facebook.react.uimanager.IllegalViewOperationException:试图添加未知的视图标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

com.facebook.react.uimanager.IllegalViewOperationException:试图添加未知的视图标签:1122

如何解决这个bug,如何找到导致崩溃的原因?

解决方案

我设法在 react-native 中准确找出导致该问题的原因.

那么幕后发生的事情是,react-native 试图操纵 shadowNode list 同时其他线程正在操作它.

特别是 UIImplementation 使用以下方法操作该列表

  1. 创建视图
  2. setChildren
  3. 管理孩子
  4. removeRootShadowNode

因此,如果其中任何一个同时被调用,则应用程序崩溃的可能性非常高.

在我们的应用中,我们通过提供如下所示的自定义 UIImplementation 解决了该问题:

https://gist.github.com/SudoPlz/23ea2dee9772cb39e1e74>p>b

如您所见,我们不再允许那些 UIImplementation 方法以非同步方式运行.

我们可以不断地重现这个问题,但现在已经完全解决了.我们通过这个方法传递了新的 UIImplementation 这里.

如果你不知道如何传递一个新的UIImplementationProvider你必须去你的MainApplication.java文件,找到ReactNativeHost的创建代码>:

private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {@覆盖公共布尔 getUseDeveloperSupport() {返回 BuildConfig.DEBUG;}……呜呜呜

并添加以下函数:

protected UIImplementationProvider getUIImplementationProvider() {返回新的 YourCustomUIImplementationProvider();}

现在看起来像这样:

private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {@覆盖公共布尔 getUseDeveloperSupport() {返回 BuildConfig.DEBUG;}受保护的 UIImplementationProvider getUIImplementationProvider() {返回新的 YourCustomUIImplementationProvider();}……呜呜呜

这是原始反应本机问题

com.facebook.react.uimanager.IllegalViewOperationException: Trying to add unknown view tag: 1122

How to resole this bug,How to find where cause this crash?

解决方案

I managed to spot exactly what's causing that problem in react-native.

So what happens behind the scenes is, react-native is trying to manipulate the shadowNode list at the same time some other thread is manipulating it.

Specifically UIImplementation manipulates that list with the following methods

  1. createView
  2. setChildren
  3. manageChildren
  4. removeRootShadowNode

so if any of those get invoked at the same time, there's a really high chance that the app will crash.

In our app we fixed that issue by providing a custom UIImplementation that looks like this:

https://gist.github.com/SudoPlz/23ea2dee9772cb39e1e742034cdf8b98

as you can see we don't allow those UIImplementation methods to run unsynchronised anymore.

We could constantly reproduce the issue on our end, but now that's totally fixed. We pass the new UIImplementation provided through this method here.

If you don't know how to pass a new UIImplementationProvider you have to go to your MainApplication.java file, find the creation of ReactNativeHost:

private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
    @Override
    public boolean getUseDeveloperSupport() {
      return BuildConfig.DEBUG;
    }
...bla bla blah

and add the following function:

protected UIImplementationProvider getUIImplementationProvider() {
    return new YourCustomUIImplementationProvider();
}

so that it now looks like this:

private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
    @Override
    public boolean getUseDeveloperSupport() {
      return BuildConfig.DEBUG;
    }

    protected UIImplementationProvider getUIImplementationProvider() {
        return new YourCustomUIImplementationProvider();
    }
...bla bla blah

Here's the original react-native issue

这篇关于com.facebook.react.uimanager.IllegalViewOperationException:试图添加未知的视图标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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