npmchenwei111
Version:
test1111
67 lines (55 loc) • 1.22 kB
JavaScript
/**
* Created by chenwei on 2017/7/21.
*/
import React, { Component } from 'react'
import { Image, TouchableOpacity } from 'react-native'
import { ClickUtils } from '../../utils/ClickUtils'
/**
* 可点击的Image,使用方法与Image一致,
*/
class ClickImage extends Component {
/**
* 属性说明
*
* 基本用法与Image一致
*
* 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}
onPress={
ClickUtils.onPress(this.data.enable ? this.props.onPress : null)
}>
<Image
{...copyProps}
style={[{
resizeMode: 'center',
backgroundColor: '#00000000',
}, this.props.style]}
>
{this.props.children}
</Image>
</TouchableOpacity>
)
}
}
export default ClickImage