Sujay Naik
Sujay Naik

Reputation: 31

React native IllegalViewOperationException - Trying to remove a view index above child count 0 view tag: 1

I found this issue in my App.js which had the following render method:-

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>
        );
    }

I found this issue only on Android released apk, it works fine for iOS. Basically I've used CodePush. So once the code-push downloads and installs the update the is shown. - isDownloading : State which hold boolean to check if the app is updating. - : will be displayed when code-push updates the app. - : react-redux - : react-native-router-flux Crash happens after code-push installation is completed and the app is restarted.

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"

Crash report :-

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)

Upvotes: 3

Views: 2991

Answers (2)

Stan Luo
Stan Luo

Reputation: 3889

Adding some other cases to @niklasj's answer:

1.For those not using codePushStatusDidChange, make sure you are not doing a lot setState while codepush.sync() is executing.

2.For those using react-native-restart, better to make sure you are not calling restart() when codepush.sync() is also restarting the app.

Upvotes: 0

niklasj
niklasj

Reputation: 11

I just had similiar error. I'm using redux and codepush also.

Take a look at this issue on codepush repo https://github.com/Microsoft/react-native-code-push/issues/986

Are you using codePushStatusDidChange event hook in your code?

My problem seems to be fixed after removing all state changes from UPDATE_INSTALLED case.

e.g.

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
        // ...
    }
}

Upvotes: 1

Related Questions