({
visible,
action,
icon,
onIconPress,
iconAccessibilityLabel = 'Close icon',
duration = DURATION_MEDIUM,
onDismiss,
children,
elevation = 2,
style,
wrapperStyle,
contentStyle,
theme: themeOverrides,
maxFontSizeMultiplier,
rippleColor,
testID,
...rest
}: Props)
| 147 | * ``` |
| 148 | */ |
| 149 | const Snackbar = ({ |
| 150 | visible, |
| 151 | action, |
| 152 | icon, |
| 153 | onIconPress, |
| 154 | iconAccessibilityLabel = 'Close icon', |
| 155 | duration = DURATION_MEDIUM, |
| 156 | onDismiss, |
| 157 | children, |
| 158 | elevation = 2, |
| 159 | style, |
| 160 | wrapperStyle, |
| 161 | contentStyle, |
| 162 | theme: themeOverrides, |
| 163 | maxFontSizeMultiplier, |
| 164 | rippleColor, |
| 165 | testID, |
| 166 | ...rest |
| 167 | }: Props) => { |
| 168 | const theme = useInternalTheme(themeOverrides); |
| 169 | const { bottom, right, left } = useSafeAreaInsets(); |
| 170 | |
| 171 | const { current: opacity } = React.useRef<Animated.Value>( |
| 172 | new Animated.Value(0.0) |
| 173 | ); |
| 174 | const hideTimeout = React.useRef<NodeJS.Timeout | undefined>(undefined); |
| 175 | |
| 176 | const [hidden, setHidden] = React.useState(!visible); |
| 177 | |
| 178 | const { scale } = theme.animation; |
| 179 | |
| 180 | const animateShow = useLatestCallback(() => { |
| 181 | if (hideTimeout.current) clearTimeout(hideTimeout.current); |
| 182 | |
| 183 | Animated.timing(opacity, { |
| 184 | toValue: 1, |
| 185 | duration: 200 * scale, |
| 186 | easing: Easing.out(Easing.ease), |
| 187 | useNativeDriver: true, |
| 188 | }).start(({ finished }) => { |
| 189 | if (finished) { |
| 190 | const isInfinity = |
| 191 | duration === Number.POSITIVE_INFINITY || |
| 192 | duration === Number.NEGATIVE_INFINITY; |
| 193 | |
| 194 | if (!isInfinity) { |
| 195 | hideTimeout.current = setTimeout( |
| 196 | onDismiss, |
| 197 | duration |
| 198 | ) as unknown as NodeJS.Timeout; |
| 199 | } |
| 200 | } |
| 201 | }); |
| 202 | }); |
| 203 | |
| 204 | const handleOnVisible = useLatestCallback(() => { |
| 205 | // show |
| 206 | setHidden(false); |
nothing calls this directly
no test coverage detected
searching dependent graphs…