reactjs – React Native:导出后StyleSheet对象中的所有样式都
发布时间:2020-12-15 20:11:26 所属栏目:百科 来源:网络整理
导读:我的样式对象:mainModule / styles.js export default StyleSheet.create({ container: { width: 0 },basicInfo: { height: 167,backgroundColor: 'red,justifyContent: 'center',alignItems: 'center' }} 当我从’@ mainModule / styles’导入import gener
我的样式对象:mainModule / styles.js
export default StyleSheet.create({ container: { width: 0 },basicInfo: { height: 167,backgroundColor: 'red,justifyContent: 'center',alignItems: 'center' } } 当我从’@ mainModule / styles’导入import generalStyle时(我创建了一个package.json文件以使该路径有效) 对象{ 这里的任何人都可以帮助我吗? 解决方法
@NellyNgo,您可能试图压缩StyleSheet.create返回的整个对象.我做了同样的事情,这让我发疯,因为它似乎对其他所有人都有用,但对我来说,它返回了我传给它的相同价值.实际上,flatten将适用于StyleSheet.create创建的对象的单独属性.像这样:
const styles = StyleSheet.create({prop: {...},prop2: {...}) 然后你可以做StyleSheet.flatten(styles.prop) 检查node_modules / react-native / Libraries / StyleSheet / flattenStyle.js中的代码.那是我失败的地方. function getStyle(style) { if (typeof style === 'number') { return ReactNativePropRegistry.getByID(style); } return style; } 如果感兴趣,请检查整个来源 我的RN版本是0.41.2 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容