2015-12-15 77 views
0

在本地做出反應,你可以有造型和訪問一個單獨的文件,從其他的網頁文件指的花式。使用物業的JS文件陣營本地

'use strict'; 

var React = require('react-native'); 
const Dimensions = require('Dimensions'); 
var { 
    StyleSheet, 
    } = React; 

var styles = StyleSheet.create({ 
    defaultBackground: { 
     flex: 1, 
     justifyContent: 'center', 
     alignItems: 'center', 
     backgroundColor: '#ffffff', 
    }, 
    menuButton: { 
     fontSize: 22, 
     color: '#ffffff', 
     paddingHorizontal: 20, 
    }, 
    container: { 
     flex: 1 
    } 
}); 

module.exports = styles; 

這裏是通過React的「StyleSheet」獲得的。

說像以下的樣品,

myName: 'Username', 
myURL: 'www.google.com', 
reactNativeUser: true, 
age: 22, 

像這樣在一個單獨的文件作爲一個屬性文件中使用,並且在應用程序中使用。

如何實現這一目標?

回答

1

導出普通對象

您可以導出普通對象。 並根據需要創建樣式表。

// style.js 
export const Style = { 
    defaultBackground: { 
     flex: 1, 
     justifyContent: 'center', 
     alignItems: 'center', 
     backgroundColor: '#ffffff', 
    }, 
    menuButton: { 
     fontSize: 22, 
     color: '#ffffff', 
     paddingHorizontal: 20, 
    }, 
    container: { 
     flex: 1 
    } 
} 

// component.js 
import React, {StyleSheet} from 'react-native'; 
import {Style as Globalstyle} from 'style' 

var styles = StyleSheet.create(Globalstyle); 

也許我不明白你的問題。要導出這些常量,你可以使用相同的方法。

//propertyfile.js 
export const myName = "Username"; 
export const myURL = "www.google.com", 
export const reactNativeUser = true; 
export const age = 22; 

//component.js 
import {myName, myURL, reactNativeUser, age} from 'propertyfile' 
+0

導出平原對象的工作。謝謝。 –