React Native无法更改App.js中的变量

时间:2019-09-21 18:10:59

标签: react-native redux react-redux react-native-paper

我正在尝试在我的react本机应用程序中应用多个主题,但是我找不到改变<Provider>周围的<MyApp />中使用的变量的方法,我感到任何改变发生在App.js中是反模式;

我的目标是将更改传递给{ux1提供者之下的react-native-paper提供者;

有没有解决的办法?

  

App.js

    import * as React from 'react';
import {DefaultTheme, Provider as PaperProvider} from 'react-native-paper';
import {mapping, light, dark} from '@eva-design/eva';
import AppNavigator from './src/navigation';
import {Provider} from 'react-redux';
import {configureStore} from './src/store';


export default class App extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      theme: configureStore().getState().app.themeColor,
    };
  }

  render() {
    const {theme} = this.state;
    return (
      <Provider store={configureStore()}>
        <PaperProvider theme={theme === 'light' ? themeLight : themeDark}>
          <AppNavigator />
        </PaperProvider>
      </Provider>
    );
  }
}

const themeLight = {
  ...DefaultTheme,
  roundness: 2,
  colors: {
    ...DefaultTheme.colors,
    primary: '#3498db',
    accent: '#f1c40f',
  },
};

const themeDark = {
  ...DefaultTheme,
  roundness: 2,
  dark: true,
  colors: {
    ...DefaultTheme.colors,
    primary: '#3498db',
    accent: '#f1c40f',
  },
};
  

AppNavigator.js

import {
  createAppContainer,
  createStackNavigator,
  createSwitchNavigator,
  createDrawerNavigator,
} from 'react-navigation';

import Welcome from '../components/welcome';

const HomeStack = createStackNavigator(
  {
    Home: {screen: Welcome},
  },
  {
    headerMode: 'none',
    navigationOptions: {
      header: 'none',
    },
  },
);

export default createAppContainer(
  createSwitchNavigator(
    {
      //Intro: IntroStack,
      Home: HomeStack,
    },
    {
      initialRouteName: 'Home',
    },
  ),
);

0 个答案:

没有答案