将 ThemeProvider 包装到 wix react-native-navigation V2
Wrapping ThemeProvider to wix react-native-navigation V2
-
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)
您可以按如下方式使用提供程序包装组件:
Navigation.registerComponent(key, () => (props) =>
<Provider>
<ScreenComponent {...props} />
</Provider>,
() => ScreenComponent);
- 第一个参数:注册名称
- 第二个参数:生成器函数
其中 returns 用 Provider
包装的组件
- 第三个参数:returns 实际组件的生成器函数。这是需要的
因为 RNN 需要提升非反应静力学
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)
您可以按如下方式使用提供程序包装组件:
Navigation.registerComponent(key, () => (props) =>
<Provider>
<ScreenComponent {...props} />
</Provider>,
() => ScreenComponent);
- 第一个参数:注册名称
- 第二个参数:生成器函数 其中 returns 用 Provider 包装的组件
- 第三个参数:returns 实际组件的生成器函数。这是需要的 因为 RNN 需要提升非反应静力学