【发布时间】:2021-04-15 14:41:28
【问题描述】:
我在我的 react-native 应用程序中使用 react-native-elements。
我的应用使用 ThemeProvider 进行包装,以将主题传递给所有组件。
<SafeAreaProvider>
<ThemeProvider theme={Theme}>
<Loader visible={loader.loading} text={loader.message} absolute={true} />
<RootNavigation />
</ThemeProvider>
</SafeAreaProvider>
在主题文件中,我定义了我想在整个应用程序中使用的值。
const theme = {
colors: {
primary: '#6A69E2',
primaryDark: '#4747c2',
primaryLight: 'rgba(106, 105, 226, 0.35)',
gray: {
dark: '#242424',
default: '#666',
medium: '#999',
light: '#ccc',
lightest: '#e7e7e7',
},
},
text: {
size: {
small: 12,
default: 16,
large: 18,
h1: 26,
h2: 22,
h3: 20,
},
},
Text: {
style: {
fontSize: 16,
color: '#242424',
fontFamily: 'Roboto',
},
},
Button: {
style: {
borderRadius: 50,
},
disabledStyle: {
backgroundColor: 'rgba(106, 105, 226, 0.35)',
},
},
};
export default theme;
对于值,提供此功能的 react-native-elements 的原始主题是有效的。例如,我可以通过使用访问颜色
const theme = useTheme()
theme.colors.primary
但是当我想添加一些新的属性,比如 primaryDark 时,我会得到一个 linter 错误。
Object literal may only specify known properties, and 'primaryDark' does not exist in type 'RecursivePartial<Colors>'.ts(2322)
在 react-native-elements 的文档中是关于声明合并的一部分,但我不明白如何存档 https://reactnativeelements.com/docs/customization/#typescript-definitions-extending-the-default-theme.
有人可以帮我解决这个问题吗?
【问题讨论】:
-
什么是 linter 错误?
-
对象字面量只能指定已知属性,并且'recursivePartial
'类型中不存在'primaryDark'.ts(2322) -
看起来他们刚刚修复了它#2964
标签: javascript typescript react-native react-native-elements