使用react-navigation怎么动态修改title的内容(react-navigation,title,web开发)

时间:2024-05-03 04:26:23 作者 : 石家庄SEO 分类 : web开发
  • TAG :

动态修改title内容:

staticnavigationOptions={title:({state})=>`Chatwith${state.params.user}`};

ps:`Chat with ${state.params.user}` 这里有个注意的地方,是这个符号·而不是单引号‘

index.android.js

/***SampleReactNativeApp*https://github.com/facebook/react-native*@flow*/import{AppRegistry,}from'react-native';importrootAppfrom'./js/rootApp'AppRegistry.registerComponent('GankProject',()=>rootApp);

rootApp.js:

/***CreatedbyAdministratoron2017/3/310031.*/'usestrict'importReactfrom'react';import{AppRegistry,Text,View,Button,}from'react-native';import{StackNavigator}from'react-navigation';importChatScreenfrom'./ChatScreen';classHomeScreenextendsReact.Component{staticnavigationOptions={title:'Welcome',//设置标题内容};render(){const{navigate}=this.props.navigation;return(<View><Text>Hello,Navigation!</Text><ButtononPress={()=>navigate('Chat',{user:'Lucy'})}title="ChatwithLucy"/></View>);}}constSimpleApp=StackNavigator({Home:{screen:HomeScreen},Chat:{screen:ChatScreen},});exportdefaultSimpleApp;

ChatScreen.js:

/***CreatedbyAdministratoron2017/3/310031.*/'usestrict'importReact,{Component}from'react';import{View,Text}from'react-native';classChatScreenextendsComponent{staticnavigationOptions={title:({state})=>`Chatwith${state.params.user}`};render(){const{params}=this.props.navigation.state;return(<View><Text>Chatwith{params.user}</Text></View>);}}exportdefaultChatScreen;

效果2:

使用react-navigation怎么动态修改title的内容

/***CreatedbyAdministratoron2017/3/310031.*/'usestrict'importReact,{Component}from'react';import{View,Text,Button}from'react-native';classChatScreenextendsComponent{staticnavigationOptions={title:({state})=>{if(state.params.mode==='info'){return`${state.params.user}'sContactInfo`;}return`Chatwith${state.params.user}`;},header:({state,setParams})=>{//ThenavigationprophasfunctionslikesetParams,goBack,andnavigate.letright=(<Buttontitle={`${state.params.user}'sinfo`}onPress={()=>setParams({mode:'info'})}/>);if(state.params.mode==='info'){right=(<Buttontitle="Done"onPress={()=>setParams({mode:'none'})}/>);}return{right};},};render(){const{params}=this.props.navigation.state;return(<View><Text>Chatwith{params.user}</Text></View>);}}exportdefaultChatScreen;
 </div> <div class="zixun-tj-product adv-bottom"></div> </div> </div> <div class="prve-next-news">
本文:使用react-navigation怎么动态修改title的内容的详细内容,希望对您有所帮助,信息来源于网络。
上一篇:使用Python怎么对BAM进行处理下一篇:

2 人围观 / 0 条评论 ↓快速评论↓

(必须)

(必须,保密)

阿狸1 阿狸2 阿狸3 阿狸4 阿狸5 阿狸6 阿狸7 阿狸8 阿狸9 阿狸10 阿狸11 阿狸12 阿狸13 阿狸14 阿狸15 阿狸16 阿狸17 阿狸18