UNPKG

npmchenwei111

Version:

test1111

66 lines (55 loc) 1.23 kB
/** * Created by chenwei on 2017/7/17. */ import React, { Component } from 'react' import { Text, TouchableOpacity } from 'react-native' import { ClickUtils } from '../../utils/ClickUtils' /** * 可点击的Text,使用方法与Text一致, */ class ClickText extends Component { /** * 属性说明 * * 基本用法与Text一致 * * onPress() :function 点击函数 * * * */ constructor (props) { super(props) this._initData() } //初始化 _initData () { this.data = { enable: true, ...this.props.data } } render () { const copyProps = {...this.props} copyProps['onPress'] = undefined copyProps['data'] = undefined return ( <TouchableOpacity activeOpacity={this.props.onPress && this.data.enable ? 0.7 : 1.0} onPress={ ClickUtils.onPress(this.data.enable ? this.props.onPress : null) }> <Text {...copyProps} style={[{ textAlign: 'center', backgroundColor: '#00000000', color: '#232323' }, this.props.style]}> {this.props.children} </Text> </TouchableOpacity> ) } } export default ClickText