Repository navigation
Expand file tree
/
Copy pathButton.js
More file actions
executable file
·77 lines (70 loc) · 1.54 KB
/
Copy pathButton.js
File metadata and controls
executable file
·77 lines (70 loc) · 1.54 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
/*
Copyright © SuperMap. All rights reserved.
Author: Yang Shanglong
E-mail: yangshanglong@supermap.com
*/
import React, { PureComponent } from 'react'
import { Text, StyleSheet, TouchableOpacity } from 'react-native'
import styles from './styles'
export default class Button extends PureComponent {
props: {
style?: StyleSheet,
titleStyle?: StyleSheet,
title: string,
activeOpacity?: number,
type?: string,
onPress: () => {},
}
static defaultProps = {
activeOpacity: 0.8,
type: 'BLUE',
}
constructor(props) {
super(props)
}
action = () => {
this.props.onPress && this.props.onPress()
}
render() {
let color, textColor
switch (this.props.type) {
case 'GRAY':
color = styles.gray
textColor = 'white'
break
case 'RED':
color = styles.red
textColor = 'white'
break
case 'BLUE':
default:
color = styles.blue
textColor = 'white'
break
}
return (
<TouchableOpacity
accessible={true}
accessibilityLabel={this.props.title}
activeOpacity={this.props.activeOpacity}
style={[styles.baseStyle, color, this.props.style]}
onPress={this.action}
>
<Text
style={[
styles.btnTitle,
textColor && { color: textColor },
this.props.titleStyle,
]}
>
{this.props.title}
</Text>
</TouchableOpacity>
)
}
}
Button.Type = {
BLUE: 'BLUE',
RED: 'RED',
GRAY: 'GRAY',
}