我想使用主题变量来相应地设置我的图标样式。但是我不能使用 style 属性来填充 react-native-ui-kitten 的 Icon 元素,而是必须使用 fill 属性。如何在 react-native-ui-kitten 的 withStyles 函数之外访问主题变量
问问题
1012 次
2 回答
1
@xk2tm5ah5ctheme
如果将组件包装到withStyles
.
这是一个示例代码:
import React from 'react';
import { View } from 'react-native';
import { Button, Icon, withStyles } from 'react-native-ui-kitten';
const ScreenComponent = (props) => {
const iconColor = props.theme['color-primary-default'];
const FacebookIcon = (style) => (
<Icon {...style} fill={iconColor} name='facebook' />
);
return (
<View>
<Button icon={FacebookIcon}>LOGIN WITH FACEBOOK</Button>
</View>
);
};
export const Screen = withStyles(ScreenComponent);
于 2019-10-09T09:35:45.463 回答
0
我不太确定我是否完全理解你的问题。通常当您有问题时,您应该发布一些代码作为上下文。
这是我的答案,假设“主题变量”是一个哈希......尝试字符串插值:
fill={`${theme.HEX_COLOR}`}
于 2019-10-08T21:13:44.860 回答