应用虽然已经运行起来了,但是到现在还没有看到或修改任何代码。那么,接下来,就一起看看React Native源码吧。

打开index.ios.js文件,可以看到与显示在设备上内容直接相关的代码:

export default class LearnDay 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.ios.js
        </Text>
        <Text style={styles.instructions}>
          Press Cmd+R to reload,{'\n'}
          Cmd+D or shake for dev menu
        </Text>
      </View>
    );
  }
}

为了证实我们的想法,将代码中的文字‘Welcome to React Native! ’ 修改为“我的第一个React Native应用!”,然后在iOS 模拟器中使用快捷键command +R 重新加载应用,界面更新如下:

接着,再来看看显示样式的代码:

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,
  },
});

在welcome样式中添加color:'red'属性:

 welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
    color:'red'
  },

重新加载应用,效果截图如下:

results matching ""

    No results matching ""