-
Notifications
You must be signed in to change notification settings - Fork 14
/
CircleIconButton.js
executable file
·98 lines (88 loc) · 2.91 KB
/
CircleIconButton.js
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
import React from 'react'
import {
View,
TouchableOpacity
} from 'react-native'
import PropTypes from 'prop-types'
import FontAwesome5 from 'react-native-vector-icons/FontAwesome5'
import SimpleLineIcons from 'react-native-vector-icons/SimpleLineIcons'
import EStyleSheet from 'react-native-extended-stylesheet'
import DeviceInfo from 'react-native-device-info';
import * as colorModes from '../../displayOptions/colorModes'
const CircleIconButton = ({ style, activated, type, onPress, disabled, radius, inMuseumMode }) => {
const circleStyle = {
width: radius * 2,
height: radius * 2,
borderRadius: radius,
backgroundColor: activated ?
colorModes.activeIconBackgroundColorFor(inMuseumMode)
: 'transparent',
borderWidth: DeviceInfo.isTablet() ? 2 : 1,
borderColor: colorModes.activeIconBackgroundColorFor(inMuseumMode),
}
const iconColor = activated ?
colorModes.activeIconForegroundColorFor(inMuseumMode)
: colorModes.inactiveIconForegroundColorFor(inMuseumMode)
const opacity = {opacity: disabled ? 0.5 : 1}
return (
<View style={style}>
<View style={[circleStyle, opacity]}>
<TouchableOpacity style={styles.buttonStyle} onPress={onPress} disabled={disabled}>
<View style={[styles.iconContainer, iconStyleFromType(type)]}>
<ButtonIcon type={type} size={radius} color={iconColor} />
</View>
</TouchableOpacity>
</View>
</View>
)
}
const ButtonIcon = ({type, ...props}) => {
switch (type) {
case 'share':
return <SimpleLineIcons name={'share-alt'} {...props} />
case 'expand':
return <SimpleLineIcons name={'size-fullscreen'} {...props} />
case 'edit':
return <FontAwesome5 name={'edit'} {...props} solid />
case 'draw':
return <FontAwesome5 name={'plus'} {...props} />
case 'erase':
return <FontAwesome5 name={'trash'} {...props} />
case 'undo':
return <FontAwesome5 name={'undo'} {...props} />
}
}
ButtonIcon.propTypes = {
type: PropTypes.oneOf(['edit', 'draw', 'erase', 'undo', 'expand', 'share'])
}
const iconStyleFromType = (type) => {
switch (type) {
case 'edit':
return { paddingLeft: 3 }
default:
return {}
}
}
CircleIconButton.propTypes = {
radius: PropTypes.number,
activated: PropTypes.bool,
disabled: PropTypes.bool,
onPress: PropTypes.func,
type: PropTypes.string,
style: PropTypes.object,
inMuseumMode: PropTypes.bool,
}
const styles = EStyleSheet.create({
buttonStyle: {
flex: 1
},
iconPadding: {
paddingLeft: 5
},
iconContainer: {
flex: 1,
justifyContent: 'center',
alignItems: 'center'
}
})
export default CircleIconButton