UNPKG

5.24 kBTypeScriptView Raw
1import * as React from 'react';
2import type { AccessibilityState, ColorValue, PressableAndroidRippleConfig } from 'react-native';
3import { Animated, GestureResponderEvent, StyleProp, ViewStyle } from 'react-native';
4import type { $Omit, $RemoveChildren, ThemeProp } from '../../types';
5import type { IconSource } from '../Icon';
6import Surface from '../Surface';
7export type AnimatedFABIconMode = 'static' | 'dynamic';
8export type AnimatedFABAnimateFrom = 'left' | 'right';
9export type Props = $Omit<$RemoveChildren<typeof Surface>, 'mode'> & {
10 /**
11 * Icon to display for the `FAB`.
12 */
13 icon: IconSource;
14 /**
15 * Label for extended `FAB`.
16 */
17 label: string;
18 /**
19 * Make the label text uppercased.
20 */
21 uppercase?: boolean;
22 /**
23 * Type of background drawabale to display the feedback (Android).
24 * https://reactnative.dev/docs/pressable#rippleconfig
25 */
26 background?: PressableAndroidRippleConfig;
27 /**
28 * Accessibility label for the FAB. This is read by the screen reader when the user taps the FAB.
29 * Uses `label` by default if specified.
30 */
31 accessibilityLabel?: string;
32 /**
33 * Accessibility state for the FAB. This is read by the screen reader when the user taps the FAB.
34 */
35 accessibilityState?: AccessibilityState;
36 /**
37 * Custom color for the icon and label of the `FAB`.
38 */
39 color?: string;
40 /**
41 * Color of the ripple effect.
42 */
43 rippleColor?: ColorValue;
44 /**
45 * Whether `FAB` is disabled. A disabled button is greyed out and `onPress` is not called on touch.
46 */
47 disabled?: boolean;
48 /**
49 * Whether `FAB` is currently visible.
50 */
51 visible?: boolean;
52 /**
53 * Function to execute on press.
54 */
55 onPress?: (e: GestureResponderEvent) => void;
56 /**
57 * Function to execute on long press.
58 */
59 onLongPress?: (e: GestureResponderEvent) => void;
60 /**
61 * The number of milliseconds a user must touch the element before executing `onLongPress`.
62 */
63 delayLongPress?: number;
64 /**
65 * Whether icon should be translated to the end of extended `FAB` or be static and stay in the same place. The default value is `dynamic`.
66 */
67 iconMode?: AnimatedFABIconMode;
68 /**
69 * Indicates from which direction animation should be performed. The default value is `right`.
70 */
71 animateFrom?: AnimatedFABAnimateFrom;
72 /**
73 * Whether `FAB` should start animation to extend.
74 */
75 extended: boolean;
76 /**
77 * Specifies the largest possible scale a label font can reach.
78 */
79 labelMaxFontSizeMultiplier?: number;
80 /**
81 * @supported Available in v5.x with theme version 3
82 *
83 * Color mappings variant for combinations of container and icon colors.
84 */
85 variant?: 'primary' | 'secondary' | 'tertiary' | 'surface';
86 style?: Animated.WithAnimatedValue<StyleProp<ViewStyle>>;
87 /**
88 * @optional
89 */
90 theme?: ThemeProp;
91 /**
92 * TestID used for testing purposes
93 */
94 testID?: string;
95};
96/**
97 * An animated, extending horizontally floating action button represents the primary action in an application.
98 *
99 * ## Usage
100 * ```js
101 * import React from 'react';
102 * import {
103 * StyleProp,
104 * ViewStyle,
105 * Animated,
106 * StyleSheet,
107 * Platform,
108 * ScrollView,
109 * Text,
110 * SafeAreaView,
111 * I18nManager,
112 * } from 'react-native';
113 * import { AnimatedFAB } from 'react-native-paper';
114 *
115 * const MyComponent = ({
116 * animatedValue,
117 * visible,
118 * extended,
119 * label,
120 * animateFrom,
121 * style,
122 * iconMode,
123 * }) => {
124 * const [isExtended, setIsExtended] = React.useState(true);
125 *
126 * const isIOS = Platform.OS === 'ios';
127 *
128 * const onScroll = ({ nativeEvent }) => {
129 * const currentScrollPosition =
130 * Math.floor(nativeEvent?.contentOffset?.y) ?? 0;
131 *
132 * setIsExtended(currentScrollPosition <= 0);
133 * };
134 *
135 * const fabStyle = { [animateFrom]: 16 };
136 *
137 * return (
138 * <SafeAreaView style={styles.container}>
139 * <ScrollView onScroll={onScroll}>
140 * {[...new Array(100).keys()].map((_, i) => (
141 * <Text>{i}</Text>
142 * ))}
143 * </ScrollView>
144 * <AnimatedFAB
145 * icon={'plus'}
146 * label={'Label'}
147 * extended={isExtended}
148 * onPress={() => console.log('Pressed')}
149 * visible={visible}
150 * animateFrom={'right'}
151 * iconMode={'static'}
152 * style={[styles.fabStyle, style, fabStyle]}
153 * />
154 * </SafeAreaView>
155 * );
156 * };
157 *
158 * export default MyComponent;
159 *
160 * const styles = StyleSheet.create({
161 * container: {
162 * flexGrow: 1,
163 * },
164 * fabStyle: {
165 * bottom: 16,
166 * right: 16,
167 * position: 'absolute',
168 * },
169 * });
170 * ```
171 */
172declare const AnimatedFAB: ({ icon, label, background, accessibilityLabel, accessibilityState, color: customColor, rippleColor: customRippleColor, disabled, onPress, onLongPress, delayLongPress, theme: themeOverrides, style, visible, uppercase: uppercaseProp, testID, animateFrom, extended, iconMode, variant, labelMaxFontSizeMultiplier, ...rest }: Props) => React.JSX.Element;
173export default AnimatedFAB;
174//# sourceMappingURL=AnimatedFAB.d.ts.map
\No newline at end of file