我正在尝试使用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)
答案 0 :(得分:0)
您可以使用提供程序包装组件,如下所示:
Navigation.registerComponent(key, () => (props) =>
<Provider>
<ScreenComponent {...props} />
</Provider>,
() => ScreenComponent);