How to dynamically change the header title text in a react native app? -
i have been struggling sounds simple. have been trying button when onpressed called. have tried several combinators nothing works. ideas?
export default class jobscreen extends react.component { constructor(props) { super(props); } static navigationoptions = ({navigation}) => ({ title: "chat with" }); onpresslearnmore(nav) { // how update 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> ); } }
since navigationoptions
has access navigation
object, can set param on current screen this.props.navigation.setparam({ title: ‘some title’ })
, access in navigationoptions
this
static navigationoptions: ({ navigation }) => { const { state: { params = {} } } = navigation; return { title: params.title || ‘default title’, }; }
Comments
Post a Comment