import React from 'react'; import { Image, ImageRequireSource, ImageStyle, ImageURISource, StyleProp, StyleSheet, Text, TextStyle, TouchableOpacity, View, ViewStyle, } from 'react-native'; type IconProps = { /** 按钮图标 */ source: ImageRequireSource | ImageURISource; /** 按钮的样式 */ style?: StyleProp; /** 按钮和文字之间的距离 */ distance?: number; }; interface ButtonProps { /** 按钮的样式 */ style?: StyleProp; /** 文字样式 */ fontStyle?: StyleProp; /** 按钮是否禁止点击 */ disabled?: boolean; /** 点击事件 */ onPress: () => void; /** 长按点击事件 */ onLongPress?: () => void; /** 按钮的图标 */ icon?: IconProps; /** 按钮被点击的透明度 */ activeOpacity?: number; } const Button: React.FC = props => { const { style, fontStyle = {}, disabled = false, onPress, icon, onLongPress, activeOpacity = 0.88, } = props; let fontSize = fontStyle.hasOwnProperty('fontSize') ? // @ts-ignore fontStyle.fontSize : 16; const loadIcon = () => { if (icon) { const {source, style = {tintColor: 'white'}, distance = 8} = icon; return ( ); } else { return null; } }; return ( { onPress?.(); }} activeOpacity={activeOpacity} onLongPress={() => { onLongPress?.(); }}> {loadIcon()} {props?.children} ); }; const styles = StyleSheet.create({ view: { flexDirection: 'row', alignItems: 'center', backgroundColor: '#987123', borderRadius: 4, height: 44, justifyContent: 'center', paddingHorizontal: 4, }, fontStyle: { color: 'white', fontSize: 16, }, }); export default Button;