如何动态地更改一个反应本机应用程序的标题标题文本?

问题描述 投票:2回答:1

我一直在努力的东西,听起来很简单。我一直在努力当onpressed被称为获得按钮。尝试了好几种组合程序但没有任何工程。有任何想法吗?

export default class JobScreen extends React.Component {

    constructor(props) {
        super(props);
    }

    static navigationOptions = ({navigation}) => ({
        title: "Chat with"
    });

    onPressLearnMore(nav) {

        // how do I update the title header 

        console.log("On Pressed" + nav)
    }

    render() {
        const {navigate} = this.props.navigation;


        return (
            <View style={styles.container}>
                <Button
                    onPress={() => {this.onPressLearnMore(navigate)}}
                    title="Learn More"
                    color="#841584"
                />

            </View>
        );
    }
}
react-native
1个回答
4
投票

由于navigationOptions可以访问navigation对象,您可以设置当前屏幕this.props.navigation.setParam({ title: ‘some title’ })一些PARAM,然后访问它在navigationOptions这样

static navigationOptions = ({ navigation }) => {
  const { state: { params = {} } } = navigation;
  return {
    title: params.title || ‘default title’,
  };
}
© www.soinside.com 2019 - 2024. All rights reserved.