React native 无法在已设置样式的组件中使用全局样式
我正在尝试在react native中设置全局样式。 我已经进口了React native 无法在已设置样式的组件中使用全局样式,react-native,styled-components,React Native,Styled Components,我正在尝试在react native中设置全局样式。 我已经进口了 从“样式化组件”导入{injectGlobal} 而且 class XoxoContainer extends Component { render() { return <Xoxo {...this.props} /> } } injectGlobal` font-family: '20' `; 类XoxoContainer扩展组件{ render(){ 返回 } } 注入全球` 字体系列
从“样式化组件”导入{injectGlobal}代码>
而且
class XoxoContainer extends Component {
render() {
return <Xoxo {...this.props} />
}
}
injectGlobal`
font-family: '20'
`;
类XoxoContainer扩展组件{
render(){
返回
}
}
注入全球`
字体系列:“20”
`;
但是我一直得到
styledComponents.injectGlobals不是一个函数。
在控制台中。该函数不是react native上的库的一部分,这就是为什么它一直说它不是函数,因为它找不到它。该函数不是react native上的库的一部分,这就是为什么它一直说它不是函数,因为它找不到它。使用以下模式创建js文件:
'use strict';
var React = require('react-native');
var myStyle = React.StyleSheet.create({
style1: { },
style2: { }
)}
module.exports = myStyle;
您的组件js需要使用该样式表
var customStyle = require('../the/path/to/commonStyleSheet');
现在就这样使用:
<View style = {customStyle .style1} />
import React, {Component} from 'react';
import {
Platform,
StyleSheet
} from 'react-native';
export const styles = StyleSheet.create({
view_flex_one_white: {
flex: 1,
backgroundColor: white
}});
使用以下模式创建js文件:
'use strict';
var React = require('react-native');
var myStyle = React.StyleSheet.create({
style1: { },
style2: { }
)}
module.exports = myStyle;
您的组件js需要使用该样式表
var customStyle = require('../the/path/to/commonStyleSheet');
现在就这样使用:
<View style = {customStyle .style1} />
import React, {Component} from 'react';
import {
Platform,
StyleSheet
} from 'react-native';
export const styles = StyleSheet.create({
view_flex_one_white: {
flex: 1,
backgroundColor: white
}});
创建一个styles.js文件,如下所示:
<View style = {customStyle .style1} />
import React, {Component} from 'react';
import {
Platform,
StyleSheet
} from 'react-native';
export const styles = StyleSheet.create({
view_flex_one_white: {
flex: 1,
backgroundColor: white
}});
并在应用程序中的任何位置使用此功能
import {styles} from "...link to file/styles";
render(){
return(
<View style={styles.view_flex_one_white}>
</View>
)
}
从“…链接到文件/样式”导入{style};
render(){
返回(
)
}
创建一个styles.js文件,如下所示:
<View style = {customStyle .style1} />
import React, {Component} from 'react';
import {
Platform,
StyleSheet
} from 'react-native';
export const styles = StyleSheet.create({
view_flex_one_white: {
flex: 1,
backgroundColor: white
}});
并在应用程序中的任何位置使用此功能
import {styles} from "...link to file/styles";
render(){
return(
<View style={styles.view_flex_one_white}>
</View>
)
}
从“…链接到文件/样式”导入{style};
render(){
返回(
)
}