1 | function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
2 |
|
3 | import * as React from 'react';
|
4 | import { View, StyleSheet } from 'react-native';
|
5 | import color from 'color';
|
6 | import TouchableRipple from './TouchableRipple/TouchableRipple';
|
7 | import Icon from './Icon';
|
8 | import CrossFadeIcon from './CrossFadeIcon';
|
9 | import { withTheme } from '../core/theming';
|
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 | const IconButton = _ref => {
|
46 | let {
|
47 | icon,
|
48 | color: customColor,
|
49 | size = 24,
|
50 | accessibilityLabel,
|
51 | disabled,
|
52 | onPress,
|
53 | animated = false,
|
54 | theme,
|
55 | style,
|
56 | ...rest
|
57 | } = _ref;
|
58 | const iconColor = typeof customColor !== 'undefined' ? customColor : theme.colors.text;
|
59 | const rippleColor = color(iconColor).alpha(0.32).rgb().string();
|
60 | const IconComponent = animated ? CrossFadeIcon : Icon;
|
61 | const buttonSize = size * 1.5;
|
62 | return React.createElement(TouchableRipple, _extends({
|
63 | borderless: true,
|
64 | centered: true,
|
65 | onPress: onPress,
|
66 | rippleColor: rippleColor,
|
67 | style: [styles.container, {
|
68 | width: buttonSize,
|
69 | height: buttonSize,
|
70 | borderRadius: buttonSize / 2
|
71 | }, disabled && styles.disabled, style],
|
72 | accessibilityLabel: accessibilityLabel
|
73 | ,
|
74 | accessibilityTraits: disabled ? ['button', 'disabled'] : 'button',
|
75 | accessibilityComponentType: "button",
|
76 | accessibilityRole: "button",
|
77 | accessibilityState: {
|
78 | disabled
|
79 | },
|
80 | disabled: disabled,
|
81 | hitSlop: TouchableRipple.supported ? {
|
82 | top: 10,
|
83 | left: 10,
|
84 | bottom: 10,
|
85 | right: 10
|
86 | } : {
|
87 | top: 6,
|
88 | left: 6,
|
89 | bottom: 6,
|
90 | right: 6
|
91 | }
|
92 | }, rest), React.createElement(View, null, React.createElement(IconComponent, {
|
93 | color: iconColor,
|
94 | source: icon,
|
95 | size: size
|
96 | })));
|
97 | };
|
98 |
|
99 | const styles = StyleSheet.create({
|
100 | container: {
|
101 | alignItems: 'center',
|
102 | justifyContent: 'center',
|
103 | overflow: 'hidden',
|
104 | margin: 6
|
105 | },
|
106 | disabled: {
|
107 | opacity: 0.32
|
108 | }
|
109 | });
|
110 | export default withTheme(IconButton);
|
111 |
|
\ | No newline at end of file |