Repository navigation
Expand file tree
/
Copy pathImageButton.js
More file actions
executable file
·114 lines (108 loc) · 2.87 KB
/
Copy pathImageButton.js
File metadata and controls
executable file
·114 lines (108 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
图片按钮
Copyright © SuperMap. All rights reserved.
Author: Yang Shanglong
E-mail: ysl19910917@qq.com
*/
import * as React from 'react'
import { View, StyleSheet, Image, TouchableOpacity, Text } from 'react-native'
import PropTypes from 'prop-types'
import { scaleSize, setSpText } from '../utils'
import { color } from '../styles'
export default class ImageButton extends React.Component {
static propTypes = {
activeOpacity: PropTypes.number,
containerStyle: PropTypes.any,
titleStyle: PropTypes.any,
iconBtnStyle: PropTypes.any,
iconStyle: PropTypes.any,
onPress: PropTypes.func,
icon: PropTypes.any,
title: PropTypes.string,
// type: PropTypes.string,
resizeMode: PropTypes.string,
direction: PropTypes.string,
enabled: PropTypes.bool,
}
static defaultProps = {
activeOpacity: 0.8,
resizeMode: 'contain',
direction: 'column',
enabled: true,
}
render() {
if (!this.props.icon) {
return null
}
return (
<TouchableOpacity
enabled={this.props.enabled}
accessible={true}
accessibilityLabel={'图片按钮'}
style={[
styles.container,
{ flexDirection: this.props.direction },
this.props.containerStyle,
]}
activeOpacity={this.props.activeOpacity}
onPress={() => {
if (this.props.enabled) {
this.props.onPress && this.props.onPress()
}
}}
>
<View
style={[
// this.props.type === 'normal' ? styles.iconBgNormal : styles.iconBg,
styles.iconBg,
this.props.iconBtnStyle,
]}
>
<Image
resizeMode={this.props.resizeMode}
style={[styles.icon, this.props.iconStyle]}
source={this.props.icon}
/>
</View>
{this.props.title && (
<Text
numberOfLines={2}
style={[
styles.iconTitle,
this.props.direction === 'column' && { marginTop: scaleSize(10) },
this.props.titleStyle,
]}
>
{this.props.title}
</Text>
)}
</TouchableOpacity>
)
}
}
const styles = StyleSheet.create({
container: {
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
},
iconBg: {
// borderRadius: scaleSize(80),
height: scaleSize(80),
width: scaleSize(80),
justifyContent: 'center',
alignItems: 'center',
// backgroundColor: color.white,
backgroundColor: 'transparent',
},
icon: {
height: scaleSize(50),
width: scaleSize(50),
},
iconTitle: {
flexWrap: 'wrap',
fontSize: setSpText(20),
color: color.blue2,
backgroundColor: 'transparent',
},
})