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