[英]React Native: How to set background color for the whole app and individual scene in react-native-router-flux?
在使用react-native-router-flux的React Native中,如何為整個應用程序以及單個場景設置背景顏色?
這是我目前的設置:
const RouterWithRedux = connect()(Router)
const store = configureStore()
export default class App extends Component {
render() {
return (
<Provider store={store}>
<RouterWithRedux>
<Scene key='root'>
<Scene initial={true} key='login' component={Login} title='Login Page'/>
<Scene key='register' component={Register} title='Register'/>
</Scene>
</RouterWithRedux>
</Provider>
)
}
}
謝謝
在API文檔中 ,您可以在Router
和Scene
上使用sceneStyle
或getSceneStyle
(雖然只有Router
getSceneStyle
)。
編輯
在Router
您只能使用getSceneStyle
,您必須傳遞一個函數 :
// ..
const getSceneStyle = (/* NavigationSceneRendererProps */ props, computedProps) => {
const style = {
backgroundColor: 'blue',
};
return style;
};
// ..
<Router getSceneStyle={getSceneStyle} {...otherProps}>
// ..
對於Scene
您只需將對象或StyleSheet
對象傳遞給sceneStyle
或使用getSceneStyle
(確保傳遞上述函數):
<Scene
key="my-scene"
component={MyScene}
sceneStyle={{
backgroundColor: 'red',
}}
title="My Scene" />
這將覆蓋藍色背景。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.