自定義組件

1.樣式文件style.jsreact

代碼以下:react-native

            import {ide

             StyleSheet,this

            } from 'react-native';spa

            

            export let styles = StyleSheet.create({get

             greetingView: {it

             alignItems: 'center'class

             },import

             lotsOfGreetingsView: {cli

             alignItems: 'center'

             }

            });

截圖以下:

1.png

2.業務文件App.js

代碼以下:

            import React, {

              Component

            } from 'react';

            import {

              View,

              Text,

              AppRegistry

            } from 'react-native';

            // 加載樣式文件

            import {

              styles

            } from './static/style/style';

            

            class Greeting extends Component {

              render() {

                return (

                  <View style={styles.greetingView}>

                    <Text>Hello {this.props.name}</Text>

                  </View>

                );

              }

            }

            

            export default class LotsOfGreetings extends Component {

              render() {

                return (

                  <View style={styles.lotsOfGreetingsView}>

                    <Greeting name='React' />

                    <Greeting name='React Native' />

                  </View>

                );

              }

            }

            

            AppRegistry.registerComponent('LotsOfGreetings', () => LotsOfGreetings);

截圖以下:

2.png

3.運行代碼截圖:

3.jpg

QQ截圖20181128104305.png

相關文章
相關標籤/搜索