When bind the "this" in Nav's title, the App crash

Author: bluesky2525Created Nov 1, 2017Updated Jan 15, 2024

Version

Tell us which versions you are using:

  • react-native-router-flux v4.0.0-beta.22 (v3 is not supported)
  • react-native v0.49.3

Expected behaviour

click the Nav's title, show the modal

Actual behaviour

the app crash.

image

Steps to reproduce

For non-obvious bugs, please fork this component, modify Example project to reproduce your issue and include link here.

if modify the <TouchableHighlight>'s onPress function to "onPress={this.showAppSelect} ", the app just have error.

class DashBoard extends React.Component { showAppSelect(){ this.setState({modal:true}) } navTitleRender = (title) => { Actions.refresh({ renderTitle: ( <TouchableHighlight underlayColor="transparent" onPress={this.showAppSelect.bind(this)} delayLongPress={Number(delayLongPress)}> <View style={{justifyContent:'center',alignItems:'center',marginTop:20,height:40}}> <Text>{title}</Text> </View> </TouchableHighlight> ) }) } constructor(props) { super(props); this.state = { modal:: false, }; }

componentWillMount() { this.navTitleRender(appName);

......

render() { return ( <View> <Modal visible={this.state.modal} onClose={()=>this.setState({modal:false,})} > <Home /> </Modal> .....

Source: aksonov/react-native-router-flux