在 withStyles 函数之外访问主题变量 (react-native-ui-kitten)
Access theme variables outside withStyles function (react-native-ui-kitten)
我想使用主题变量相应地设置我的图标样式。但是我不能使用样式 属性 来填充 react-native-ui-kitten 的图标元素,而是必须使用填充 属性。如何在 react-native-ui-kitten
的 withStyles 函数之外访问主题变量
我不太确定我完全理解你的问题。通常当你有问题时,你应该 post 一些你的上下文代码。
这是我的答案,假设 'Theme variable' 是一个散列...尝试字符串插值:
fill={`${theme.HEX_COLOR}`}
@xk2tm5ah5c
如果将组件包装到 withStyles
.
中,则可以使用 theme
属性
这是一个示例代码:
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);
我想使用主题变量相应地设置我的图标样式。但是我不能使用样式 属性 来填充 react-native-ui-kitten 的图标元素,而是必须使用填充 属性。如何在 react-native-ui-kitten
的 withStyles 函数之外访问主题变量我不太确定我完全理解你的问题。通常当你有问题时,你应该 post 一些你的上下文代码。
这是我的答案,假设 'Theme variable' 是一个散列...尝试字符串插值:
fill={`${theme.HEX_COLOR}`}
@xk2tm5ah5c
如果将组件包装到 withStyles
.
theme
属性
这是一个示例代码:
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);