2.2.3 修改JSX代码
Posted 绿茵好莱坞
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2.2.3 修改JSX代码相关的知识,希望对你有一定的参考价值。
/** * Sample React Native App * https://github.com/facebook/react-native * @flow */ import React, { Component } from \'react\'; import { AppRegistry, StyleSheet, Text, View } from \'react-native\'; export default class MyProject8 extends Component { render() { return ( <View style={styles.container}> <Text style={styles.welcome}> Welcome to React Native! </Text> <Text style={styles.instructions}> To get started, edit index.android.js </Text> <Text style={styles.instructions}> Double tap R on your keyboard to reload,{\'\\n\'} Shake or press menu button for dev menu </Text> </View> ); } } const styles = StyleSheet.create({ container: { flex: 1, justifyContent: \'center\', alignItems: \'center\', backgroundColor: \'#F5FCFF\', }, welcome: { fontSize: 20, textAlign: \'center\', margin: 10, }, instructions: { textAlign: \'center\', color: \'#333333\', marginBottom: 5, }, }); AppRegistry.registerComponent(\'MyProject8\', () => MyProject8);
修改之后:
/** * Sample React Native App * https://github.com/facebook/react-native * @flow */ import React, { Component } from \'react\'; import { //为了节约版面,将下面的多行写为一行,读者可以不修改 AppRegistry, StyleSheet, Text, View } from \'react-native\'; let Dimensions = require(\'Dimensions\'); //请读者增加此行代码 let PixelRatio = require(\'PixelRatio\'); //请读者增加此行代码 let totalWidth = Dimensions.get(\'window\').width; //请读者增加此行代码 let totalHeight = Dimensions.get(\'window\').height; //请读者增加此行代码 let pixelRatio = PixelRatio.get(); //请读者增加此行代码 export default class MyProject8 extends Component { render() { return ( <View style={styles.container}> <Text style={styles.welcome}> pixelRatio = {pixelRatio} //需要修改的第一行 </Text> <Text style={styles.instructions}> totalHeight = {totalHeight}; //需要修改的第二行 </Text> <Text style={styles.instructions}> totalWidth = {totalWidth} //需要修改的第三行 </Text> </View> ); } } const styles = StyleSheet.create({ container: { flex: 1, justifyContent: \'center\', alignItems: \'center\', backgroundColor: \'#F5FCFF\', }, welcome: { fontSize: 20, textAlign: \'center\', margin: 10, }, instructions: { textAlign: \'center\', color: \'#333333\', marginBottom: 5, }, }); AppRegistry.registerComponent(\'MyProject8\', () => MyProject8);
以上是关于2.2.3 修改JSX代码的主要内容,如果未能解决你的问题,请参考以下文章