-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathCustomFAB.tsx
More file actions
64 lines (54 loc) · 1.38 KB
/
CustomFAB.tsx
File metadata and controls
64 lines (54 loc) · 1.38 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
import React from 'react';
import { Animated, Platform, StyleSheet, ViewStyle } from 'react-native';
import { AnimatedFAB } from 'react-native-paper';
import { useExampleTheme } from '../../hooks/useExampleTheme';
type CustomFABProps = {
animatedValue: Animated.Value;
visible: boolean;
extended: boolean;
label: string;
animateFrom: 'left' | 'right';
iconMode?: 'static' | 'dynamic';
style?: ViewStyle;
};
const CustomFAB = ({
animatedValue,
visible,
extended,
label,
animateFrom,
style,
iconMode,
}: CustomFABProps) => {
const [isExtended, setIsExtended] = React.useState(true);
const { isV3 } = useExampleTheme();
const isIOS = Platform.OS === 'ios';
React.useEffect(() => {
if (!isIOS) {
animatedValue.addListener(({ value }: { value: number }) => {
setIsExtended(value <= 0);
});
} else setIsExtended(extended);
}, [animatedValue, extended, isIOS]);
const fabStyle = { [animateFrom]: 16 };
return (
<AnimatedFAB
icon={'plus'}
label={label}
extended={isExtended}
uppercase={!isV3}
onPress={() => console.log('Pressed')}
visible={visible}
animateFrom={animateFrom}
iconMode={iconMode}
style={[styles.fabStyle, style, fabStyle]}
/>
);
};
export default CustomFAB;
const styles = StyleSheet.create({
fabStyle: {
bottom: 16,
position: 'absolute',
},
});