React|React Native Button封装

【React|React Native Button封装】react native 开发时,自带的button组件不能满足我们的开发需求。不支持背景图等设置。所以封装了一个简单的button 。代码如下

import React from "react"; import { Text, View, StyleSheet, TouchableOpacity, Image } from "react-native"; const styles = StyleSheet.create({ ButtonStyle: { justifyContent: "center", alignItems: "center" }, contentStyle: { backgroundColor: "transparent" }, Text: { textAlign: "center" }, backgroundImage: { width: "100%", height: "100%", position: "absolute", zIndex: -2, alignSelf: "center" } }); class Button extends React.Component { constructor(props) { super(props); } static defaultProps = { style: {}, enable: true, textStyle: {}, backgroundImage: null, backgroundImageStyle: {}, type: "default" }; render() { return ( //可点击 {this.props.hasOwnProperty("title") ? ( {this.props.title} ) : null} {this.props.hasOwnProperty("backgroundImage") ? ( ) : null} ); } }export default Button;

    推荐阅读