react-navigation之動(dòng)態(tài)修改title的內(nèi)容
本文介紹了react-navigation之動(dòng)態(tài)修改title的內(nèi)容,分享給大家,具體如下:
效果圖:

動(dòng)態(tài)修改title內(nèi)容:
static navigationOptions = {
title: ({ state }) => `Chat with ${state.params.user}`
};
ps:`Chat with ${state.params.user}` 這里有個(gè)注意的地方,是這個(gè)符號(hào)·而不是單引號(hào)‘
index.android.js
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import {
AppRegistry,
}from 'react-native';
import rootApp from './js/rootApp'
AppRegistry.registerComponent('GankProject', () = >rootApp);
rootApp.js:
/**
* Created by Administrator on 2017/3/31 0031.
*/
'use strict'import React from 'react';
import {
AppRegistry,
Text,
View,
Button,
}
from 'react-native';
import {
StackNavigator
}
from 'react-navigation';
import ChatScreen from './ChatScreen';
class HomeScreen extends React.Component {
static navigationOptions = {
title: 'Welcome',
//設(shè)置標(biāo)題內(nèi)容 };
render() {
const {
navigate
} = this.props.navigation;
return ( < View > <Text > Hello, Navigation ! </Text>
<Button
onPress={() => navigate('Chat',{user:'Lucy'})}
title="Chat with Lucy"/ > </View>
);
}
}
const SimpleApp = StackNavigator(
{
Home: {screen: HomeScreen},
Chat:{screen:ChatScreen},
}
);
export default SimpleApp;
ChatScreen.js:
/**
* Created by Administrator on 2017/3/31 0031.
*/
'use strict'
import React,{Component}from 'react';
import {View,Text}from 'react-native';
class ChatScreen extends Component {
static navigationOptions = {
title: ({state}) = >`Chat with $ {state.params.user}`
};
render() {
const {params} = this.props.navigation.state;
return ( < View > <Text > Chat with {
params.user
} < /Text> </View > );
}
}
export default ChatScreen;
效果2:

/** * Created by Administrator on 2017/3/31 0031. */
'use strict'
import React, { Component}from 'react';
import {View, Text, Button}from 'react-native';
class ChatScreen extends Component {
static navigationOptions = {
title: ({
state
}) => {
if (state.params.mode === 'info') {
return `${state.params.user}'s Contact Info`;
}
return `Chat with ${state.params.user}`;
},
header: ({state, setParams}) => {
// The navigation prop has functions like setParams, goBack, and navigate.
let right = ( < Button title = {
`${state.params.user}'s info`
}
onPress = {
() => setParams({
mode: 'info'
})
}
/>
);
if (state.params.mode === 'info') {
right = (
<Button
title="Done"
onPress={() => setParams({ mode: 'none' })}
/ >
);
}
return {right};
},
};
render() {
const {
params
} = this.props.navigation.state;
return (
< View >
< Text > Chat with {params.user} < /Text>
</View >
);
}
}
export default ChatScreen;
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
React Native仿美團(tuán)下拉菜單的實(shí)例代碼
本篇文章主要介紹了React Native仿美團(tuán)下拉菜單的實(shí)例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-08-08
淺談React?Refs?使用場(chǎng)景及核心要點(diǎn)
本文主要介紹了React?Refs?使用場(chǎng)景及核心要點(diǎn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-06-06
React視頻播放控制組件Video Controls的實(shí)現(xiàn)
本文主要介紹了React視頻播放控制組件Video Controls的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2025-02-02
TypeScript在React項(xiàng)目中的使用實(shí)踐總結(jié)
這篇文章主要介紹了TypeScript在React項(xiàng)目中的使用總結(jié),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-04-04
React實(shí)現(xiàn)一個(gè)支持動(dòng)態(tài)插槽的Layout組件
這篇文章主要為大家詳細(xì)介紹了如何使用React實(shí)現(xiàn)一個(gè)支持動(dòng)態(tài)注冊(cè)內(nèi)容的插槽組件,文中的示例代碼簡(jiǎn)潔易懂,有需要的小伙伴可以了解一下2025-02-02
react在安卓中輸入框被手機(jī)鍵盤遮擋問題的解決方法
這篇文章主要給大家介紹了關(guān)于react在安卓中輸入框被手機(jī)鍵盤遮擋問題的解決方法,文中通過圖文以及示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起看看吧2018-09-09
react用Redux中央倉庫實(shí)現(xiàn)一個(gè)todolist
這篇文章主要為大家詳細(xì)介紹了react用Redux中央倉庫實(shí)現(xiàn)一個(gè)todolist,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-09-09
react國際化化插件react-i18n-auto使用詳解
這篇文章主要介紹了react國際化化插件react-i18n-auto使用詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-03-03
windows下create-react-app 升級(jí)至3.3.1版本踩坑記
這篇文章主要介紹了windows下create-react-app 升級(jí)至3.3.1版本踩坑記,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-02-02

