React Native IllegalViewOperationException-尝试删除上方的视图索引0视图标签:



我在我的app.js中找到了以下渲染方法: -

render() {
        if (this.state.isDownloading) {
            return (
                <View>
                    <Spinner
                        visible={this.state.isDownloading}
                        textContent={this.state.loadingText}
                        overlayColor={Colors.COLOR_MODAL_BACKDROP}
                        animation={UIConst.ANIMATION_TYPE.NONE}
                        textStyle={styles.spinnerTextStyle}
                    />
                </View>
            );
        }
        return (
            <Provider store={Store}>
                <Router />
            </Provider>
        );
    }

我仅在Android发布的APK上发现此问题,它适用于 ios。基本上,我已经使用了CodePush。因此,一旦Code-Push下载, 安装更新显示。 - ISDOWNLOADING:状态哪些Boolean可以检查应用程序是否正在更新。 - :将在Code-Push更新应用程序时显示。 - :React-Redux - :React-Native-Router-Flux崩溃发生在Code-Push安装完成并重新启动应用程序后发生。

Libraries used are :-
1. "react-native-code-push": "^5.2.0-beta",
2. "react-native-loading-spinner-overlay": "^0.5.2",
3. "react-native-router-flux": "^4.0.0-beta.24",
4. "react-redux": "^5.0.5"

崩溃报告: -

Fatal Exception: com.facebook.react.uimanager.IllegalViewOperationException: Trying to remove a view index above child count 0 view tag: 1
 detail: View tag:-1
  children(0): [
 ],
  indicesToRemove(1): [
0,
 ],
  tagsToDelete(1): [
113,
 ]
       at com.facebook.react.uimanager.NativeViewHierarchyManager.manageChildren(NativeViewHierarchyManager.java:346)
       at com.facebook.react.uimanager.UIViewOperationQueue$ManageChildrenOperation.execute(UIViewOperationQueue.java:177)
       at com.facebook.react.uimanager.UIViewOperationQueue$1.run(UIViewOperationQueue.java:776)
       at com.facebook.react.uimanager.UIViewOperationQueue.flushPendingBatches(UIViewOperationQueue.java:855)
       at com.facebook.react.uimanager.UIViewOperationQueue.access$1600(UIViewOperationQueue.java:46)
       at com.facebook.react.uimanager.UIViewOperationQueue$2.runGuarded(UIViewOperationQueue.java:813)
       at com.facebook.react.bridge.GuardedRunnable.run(GuardedRunnable.java:21)
       at android.os.Handler.handleCallback(Handler.java:751)
       at android.os.Handler.dispatchMessage(Handler.java:95)
       at android.os.Looper.loop(Looper.java:154)
       at android.app.ActivityThread.main(ActivityThread.java:6123)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)

我刚出现了类似的错误。我也在使用Redux和CodePush。

在CodePush repo上查看此问题

您是否在代码中使用codePushStatusDidChange事件挂钩?

在删除UPDATE_INSTALLED情况下的所有状态更改后,我的问题似乎已解决。

,例如

codePushStatusDidChange(status: number): void {
    switch(status) {
        // ...
        case codePush.SyncStatus.UPDATE_INSTALLED:
            // REMOVE ALL STATE CHANGES FROM HERE !!!!
            // empty case to prevent android APK crash
        break
        // ...
    }
}

将其他一些情况添加到 @niklasj的答案:

1.对于那些不使用codePushStatusDidChange的人,请确保您在执行codepush.sync()时没有做很多setState

2.对于使用react-native-restart的人,最好确保您在codepush.sync()也重新启动应用程序时不会调用restart()

最新更新