1 | var __rest = (this && this.__rest) || function (s, e) {
|
2 | var t = {};
|
3 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
4 | t[p] = s[p];
|
5 | if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
6 | for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
7 | if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
8 | t[p[i]] = s[p[i]];
|
9 | }
|
10 | return t;
|
11 | };
|
12 | import React from 'react';
|
13 | import { StyleSheet, Animated } from 'react-native';
|
14 | import Button from './Button';
|
15 | import { withTheme } from '../config';
|
16 | const FAB = (_a) => {
|
17 | var _b, _c;
|
18 | var { color, size = 'large', visible = true, disabled, upperCase, theme, style, titleStyle, buttonStyle, containerStyle, iconContainerStyle, placement } = _a, props = __rest(_a, ["color", "size", "visible", "disabled", "upperCase", "theme", "style", "titleStyle", "buttonStyle", "containerStyle", "iconContainerStyle", "placement"]);
|
19 | const { current: animation } = React.useRef(new Animated.Value(Number(visible)));
|
20 | React.useEffect(() => {
|
21 | Animated.timing(animation, {
|
22 | toValue: Number(visible),
|
23 | duration: 200,
|
24 | useNativeDriver: true,
|
25 | }).start();
|
26 | }, [animation, visible]);
|
27 | return (<Animated.View style={[
|
28 | {
|
29 | opacity: animation,
|
30 | transform: [{ scale: animation }],
|
31 | },
|
32 | styles.content,
|
33 | placement && {
|
34 | [placement]: 0,
|
35 | position: 'absolute',
|
36 | margin: 16,
|
37 | bottom: 0,
|
38 | },
|
39 | style,
|
40 | ]}>
|
41 | <Button buttonStyle={StyleSheet.flatten([
|
42 | props.title
|
43 | ? styles.extendedLabel
|
44 | : size === 'small'
|
45 | ? styles.smallFAB
|
46 | : styles.largeFAB,
|
47 | {
|
48 | backgroundColor: color || ((_b = theme === null || theme === void 0 ? void 0 : theme.colors) === null || _b === void 0 ? void 0 : _b.secondary),
|
49 | },
|
50 | buttonStyle,
|
51 | ])} iconContainerStyle={[
|
52 | props.title
|
53 | ? {}
|
54 | : size === 'small'
|
55 | ? styles.smallFAB
|
56 | : styles.largeFAB,
|
57 | iconContainerStyle,
|
58 | ]} containerStyle={StyleSheet.flatten([
|
59 | styles.container,
|
60 | disabled && styles.disabled,
|
61 | containerStyle,
|
62 | ])} titleStyle={[
|
63 | styles.label,
|
64 | { color: (_c = theme === null || theme === void 0 ? void 0 : theme.colors) === null || _c === void 0 ? void 0 : _c.white },
|
65 | upperCase && styles.upperCaseLabel,
|
66 | titleStyle,
|
67 | ]} {...props} {...{ disabled, theme }}/>
|
68 | </Animated.View>);
|
69 | };
|
70 | const styles = StyleSheet.create({
|
71 | container: {
|
72 | elevation: 4,
|
73 | borderRadius: 28,
|
74 | },
|
75 | largeFAB: {
|
76 | height: 56,
|
77 | width: 56,
|
78 | padding: 16,
|
79 | },
|
80 | smallFAB: {
|
81 | height: 40,
|
82 | width: 40,
|
83 | padding: 8,
|
84 | },
|
85 | content: {
|
86 | flexDirection: 'row',
|
87 | alignItems: 'center',
|
88 | justifyContent: 'center',
|
89 | borderRadius: 28,
|
90 | },
|
91 | label: {
|
92 | marginHorizontal: 8,
|
93 | },
|
94 | upperCaseLabel: {
|
95 | textTransform: 'uppercase',
|
96 | },
|
97 | extendedLabel: {
|
98 | height: 48,
|
99 | paddingHorizontal: 16,
|
100 | },
|
101 | disabled: {
|
102 | elevation: 0,
|
103 | },
|
104 | });
|
105 | export { FAB };
|
106 | export default withTheme(FAB, 'FAB');
|
107 |
|
\ | No newline at end of file |