React-native-navigation: setOnNavigatorEvent throws in debug saying navigatorEventHandler is frozen

Created on 12 Feb 2018  路  3Comments  路  Source: wix/react-native-navigation

Issue Description

After adding rightButtons to a Screen and setting up the handler as documented, when I run the app and open the screen using showModal I get the following error

Unhandled JS Exception: Error: You attempted to set the key navigatorEventHandler with the value undefined on an object that is meant to be immutable and has been frozen.

This error is located at:
in ModalLinkPopup (at Navigation.js:83)
in Provider (at Navigation.js:82)
in _class2 (at renderApplication.js:35)
in RCTView (at View.js:71)
in View (at AppContainer.js:102)
in RCTView (at View.js:71)
in View (at AppContainer.js:122)
in AppContainer (at renderApplication.js:34)

If I remove the line shown below, the component displays properly.

Steps to Reproduce / Code Snippets / Screenshots

Related component:

import React from "react";
import { ScrollView } from "react-native";
import {
    NavigatorButtons,
    NavigationComponentProps,
} from "react-native-navigation";

export type ModalLinkPopupProps = NavigationComponentProps<{
    content: any;
}>;

export class ModalLinkPopup extends React.Component<ModalLinkPopupProps> {
    static navigatorButtons: NavigatorButtons = {
        rightButtons: [
            {
                title: "Zav艡铆t",
                id: "back",
                systemItem: "done",
            },
        ],
    };

    constructor(props: ModalLinkPopupProps) {
        super(props);
        // the next line throws
        this.props.navigator.setOnNavigatorEvent(this.onNavigatorEvent);
    }

    onNavigatorEvent = event => {
        if (event.type === "NavBarButtonPress") {
            if (event.id === "back") {
                this.props.navigator.dismissModal();
            }
        }
    };

    render(): JSX.Element {
        return (
            <ScrollView>
                {/* Content goes here */}
            </ScrollView>
        );
    }
}

Environment

  • React Native Navigation version: 1.1.375
  • React Native version: 0.52.2
  • Platform(s): both iOS and Android
  • Device info: iOS Simulator debug / Android Emulator (Android 7.1.1) debug

Most helpful comment

Are you passing the navigator to the new modal in "passProps", if so that would cause this problem. The new modal has a navigator from the get go, so passing one will cause a double render.

All 3 comments

Are you passing the navigator to the new modal in "passProps", if so that would cause this problem. The new modal has a navigator from the get go, so passing one will cause a double render.

@M-Jas yes, that was it! Thank you!

@no23reason Nice! I got tripped up on this also.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

EliSadaka picture EliSadaka  路  3Comments

bdrobinson picture bdrobinson  路  3Comments

edcs picture edcs  路  3Comments

zhanguangao picture zhanguangao  路  3Comments

birkir picture birkir  路  3Comments