将ThemeProvider包装为wix react-native-navigation V2

时间:2019-02-19 20:05:34

标签: react-native-navigation wix-react-native-navigation react-native-navigation-v2 react-native-elements

我正在尝试使用react-native-elements ThemeProvider包装基于RNN v2的应用程序。 如果将ThemeProvider包裹在单个组件中,则可以与同一主题配合使用,但是如果在Navigation中注册则不能,我在做什么错了?

    const theme = {
  colors: {
    primary: 'pink'
  }
};
// Register screens
Screens.forEach((ScreenComponent, key) =>
  // Navigation.registerComponent(key, () => ScreenComponent, Provider)
  Navigation.registerComponent(
    key,
    () => ScreenComponent,
    () => <ThemeProvider theme={theme}>{ScreenComponent}</ThemeProvider>
  )
);

我也尝试过这种方式。

import { Platform } from 'react-native';
import { colors, ThemeProvider } from 'react-native-elements';
import React from 'react';

const theme = {
  colors: {
    primary: 'pink'
  }
};

const Provider = ({ children }) => <ThemeProvider theme={theme}>{children}</ThemeProvider>;

export default Provider;

App.js
Screens.forEach((ScreenComponent, key) =>
  Navigation.registerComponent(key, () => ScreenComponent, Provider)

1 个答案:

答案 0 :(得分:0)

您可以使用提供程序包装组件,如下所示:

Navigation.registerComponent(key, () => (props) =>
    <Provider>
      <ScreenComponent {...props} />
    </Provider>,
    () => ScreenComponent);
  • 第一个参数:注册名称
  • 第二个参数:生成器函数 返回由Provider包装的组件
  • 第三个参数:生成器函数,它返回实际组件。这是必需的 因为RNN需要提升非反应性静力学