react-native组件Button封装与传值
2017-03-30 10:32
525 查看
感觉React native开发就是要先写组件(component),然后用组件去组装页面。组件写好了,后续开发就简单多了。不多说了。
1.下面介绍下自定义圆角Button的封装。
注意:this.props.style 、this.props.onPress、this.props.TextStyle、this.props.text都是接收参数。
2.实现类如下:
样式
1.下面介绍下自定义圆角Button的封装。
/** * Created by chenjialin on 17/3/30. */ 'use strict'; import React, { PureComponent,Component} from 'react'; import {observer} from 'mobx-react/native'; import { StyleSheet, Text, TouchableOpacity, TouchableHighlight, View } from 'react-native'; @observer class NButton extends Component { render() { return ( <TouchableHighlight style={this.props.style} activeOpacity={0.5} underlayColor="#B5B5B5" onPress={this.props.onPress}> <Text style={this.props.TextStyle}>{this.props.text}</Text> </TouchableHighlight> ); } } module.exports = NButton;
注意:this.props.style 、this.props.onPress、this.props.TextStyle、this.props.text都是接收参数。
2.实现类如下:
<NButton text="启动应用" style={styles.button1} TextStyle={styles.welcome} onPress={() => Alert.alert( 'Alert Title', 'Massege', [ {text: 'Foo', onPress: () => console.log('Foo Pressed!')}, {text: 'Bar', onPress: () => console.log('Bar Pressed!')}, ] )} />
样式
button1: { alignSelf:'center', borderWidth: 1, borderColor: '#B5B5B5', borderRadius: 5, },
welcome: { fontSize: 18, textAlign: 'center', margin: 10, },
相关文章推荐
- react-native组件传值与封装
- react-native组件封装与传值
- react native组件封装及传值
- 第四章、ReactNative组件的封装
- React Native 自定义圆角button的封装
- 《React-Native系列》13、 组件封装之Dialog(iOS和Android通用)
- ReactNative之从HelloWorld中看环境搭建、组件封装、Props及State
- react-native封装原生下拉刷新组件
- React Native组件之Button
- 【react-native-0.31-iOS】封装原生组件并调用(02)
- React-Native踩坑之路:react-native原生组件封装(iOS)
- 《React-Native系列》组件封装之Dialog(iOS和Android通用)
- React Native中组件的封装使用
- 《React-Native系列》38、 ReactNative混合组件封装
- 从零开始 React Native(6) 计时器案例(模块化_组件封装)有图有demo
- react-native 组件封装示例
- react-native组件封装与传值
- 《React-Native系列》38、 ReactNative混合组件封装
- react-native之上拉加载,下拉刷新组件封装
- react-native新导航组件react-navigation详解