1.样式文件style.js

代码如下:

            import {

             StyleSheet,

            } from 'react-native';

            

            export let styles = StyleSheet.create({

             greetingView: {

             alignItems: 'center'

             },

             lotsOfGreetingsView: {

             alignItems: 'center'

             }

            });

截图如下:

自定义组件_自定义组件属性应用

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

截图如下:

自定义组件_自定义组件属性应用_02

3.运行代码截图:

自定义组件_React Native_03

自定义组件_自定义组件属性应用_04