是否可以在 React Native 中将 var styles = StyleSheet.create 从 React.component 分离到不同的脚本中?
最佳答案
这是可能的。只需使用此模式创建一个 js 文件:
'use strict';
var React = require('react-native');
var myStyles = React.StyleSheet.create({
style1: { },
style2: { }
)}
module.exports = myStyles;
然后在您的组件 js 中使用 require 来使用该样式表,例如假设你的样式 js 文件被命名为 phongyewtong.js
var s = require('../the/path/to/phongyewtong');
用法:
<View style = {s.style1} />
关于javascript - 是否可以将 var styles = StyleSheet.create 从 React.component 分离到不同的脚本中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32930680/