我需要用ThemeProvider标签封装我的应用程序主组件,但我不知道在哪里封装它,因为我使用的是来自react-navigation的appContainer,看起来我需要改为封装appContainer。
我在一个没有expo的react-native项目中工作。我正在导入反应原生元素和反应导航。我需要封装已经被appContainer包装的app.js
App.js
import { createSwitchNavigator, createStackNavigator, createAppContainer } from 'react-navigation';
import PantallaInicio from './components/home/PantallaInicio';
import PantallaLogin from './components/auth/PantallaLogin';
import PantallaRegistro from './components/auth/PantallaRegistro';
import PantallaCargando from './components/auth/PantallaCargando';
const AppStack = createStackNavigator({ Home: PantallaInicio, });
const AuthStack = createStackNavigator({ Login: PantallaLogin, Registro: PantallaRegistro });
export default createAppContainer(createSwitchNavigator(
{
AuthLoading: PantallaCargando,
App: AppStack,
Auth: AuthStack,
},
{
initialRouteName: 'AuthLoading',
}
));index.js
/**
* @format
*/
import {AppRegistry} from 'react-native';
import App from './src/App';
import {name as appName} from './app.json';
AppRegistry.registerComponent(appName, () => App);很抱歉,我还没有任何输出,感谢您的时间。
发布于 2019-07-02 21:19:16
createAppContainer返回React Component。因此,您可以使用任何provider对其进行包装。
import React from 'react';
import {AppRegistry} from 'react-native';
import App from './src/App';
import { ThemeProvider } from 'react-native-elements';
import theme from './your-theme';
import {name as appName} from './app.json';
const ProvidedApp = () => {
return <ThemeProvider theme={theme} ><App /></ThemeProvider>
}
AppRegistry.registerComponent(appName, () => ProvidedApp);发布于 2020-04-20 08:18:50
我借用这个帖子是为了解决关于Jeff Gu Kang所说的一个问题..
Jeff Gu Kang:“你可以使用任何ThemeProvider”
我从react-native-elements中使用了<ThemeProvider/>,包装了createAppContainer返回的组件。主题道具可以是lightTheme och darkTheme对象,具体取决于lightThemeState。
使用screenProps,我向下发送了一个函数,屏幕组件可以使用该函数将主题从浅色更改为深色。但是屏幕不会更新...如果我将lightThemeNav的状态更改为false,所有内容都会更改并正常工作,但由于某些原因,当我切换按钮时,它不会更新主题。(按钮将正确更改状态)
代码如下:
const TabNavigator = createMaterialBottomTabNavigator(
{
FindDestinationScreen: {
screen: FindDestinationScreen,
navigationOptions: {
title: "Search",
tabBarIcon: ({ tintColor }) => (
<SafeAreaView>
<Icon
style={[{ color: tintColor }]}
size={25}
name={"ios-search"}
/>
</SafeAreaView>
),
},
},
},
{
barStyleDark: {
backgroundColor: "#212121",
shadowColor: "#000",
shadowOffset: { width: 3, height: 2 },
shadowOpacity: 0.8,
shadowRadius: 2,
elevation: 1,
},
barStyleLight: {
backgroundColor: "#3c5e82",
},
shifting: false,
labeled: true,
initialRouteName: "FindDestinationScreen",
activeColor: "#E4DC93",
inactiveColor: "#fff",
barStyle: { backgroundColor: "transparent", height: 80, paddingTop: 10 },
}
);
const AllRoutes = createSwitchNavigator(
{
PersonalSettings: {
title: "Personal Settings",
screen: PersonalSettings,
header: ({ goBack }) => ({
left: (
<Icon
name={"chevron-left"}
onPress={() => {
goBack();
}}
/>
),
}),
},
Tabs: {
screen: TabNavigator,
},
},
{
initialRouteName: "Tabs",
}
);
const AppContainer = createAppContainer(AllRoutes);
export default App = () => {
const [lightThemeState, setLightThemeState] = useState(true);
return (
<ThemeProvider theme={lightThemeState ? lightTheme : darkTheme}>
<AppContainer
theme={lightThemeState ? "light" : "dark"}
screenProps={{
setLightThemeState: setLightThemeState,
}}
/>
</ThemeProvider>
);
};我还在这里提出了一个更详细的问题..changing theme with react native elements not working?
会非常感谢任何形式的帮助..谢谢!
https://stackoverflow.com/questions/56840117
复制相似问题