Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is it possible to separate var styles = StyleSheet.create from React.component into different script in react native?

is it possible to separate var styles = StyleSheet.create from React.component into different script in react native?

like image 443
phongyewtong Avatar asked Oct 04 '15 06:10

phongyewtong


1 Answers

that's possible. just create a js file with this pattern:

'use strict';

var React = require('react-native');

var myStyles = React.StyleSheet.create({
   style1: { },
   style2: { }
)}

module.exports = myStyles;

then in your component js use require to use that style sheet e.g. assuming your style js file is named phongyewtong.js

var s = require('../the/path/to/phongyewtong');

usage:

<View style = {s.style1} />
like image 130
boredgames Avatar answered Nov 14 '22 21:11

boredgames