React Native External Stylesheet

前端 未结 9 883
你的背包
你的背包 2021-02-03 23:12

Is there a way in React Native that I can put all of my styles in a single file so it can easily be maintained (from my perspective) like in HTML we have a .css fil

9条回答
  •  执念已碎
    2021-02-03 23:27

    This works for me on the latest React:

    I have my stylesheet named CoolTextStyle.js (which is in the same directory as my index.ios.js). And it turns out you dont even need the 'StyleSheet' class

    module.exports = 
    {
      borderRadius:5
    }); 
    

    Then in index.ios.js

    import React, { Component, PropTypes } from 'react';
    import { View, Text, TextInput,TouchableHighlight,StatusBar } from 'react-native';
    
    var cool_text_style = require('./CoolTextStyle');
    
    export default class delme extends Component 
    {
      render() 
      {
        return (
      
        
    )
      }
    }
    
    
    AppRegistry.registerComponent('delme', () => delme);
    

提交回复
热议问题