MCPcopy
hub / github.com/callstack/react-native-paper / Snackbar

Function Snackbar

src/components/Snackbar.tsx:149–381  ·  view source on GitHub ↗
({
  visible,
  action,
  icon,
  onIconPress,
  iconAccessibilityLabel = 'Close icon',
  duration = DURATION_MEDIUM,
  onDismiss,
  children,
  elevation = 2,
  style,
  wrapperStyle,
  contentStyle,
  theme: themeOverrides,
  maxFontSizeMultiplier,
  rippleColor,
  testID,
  ...rest
}: Props)

Source from the content-addressed store, hash-verified

147 * ```
148 */
149const 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);

Callers

nothing calls this directly

Calls 2

useInternalThemeFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…