import React, { useMemo } from "react"; import { Platform, TouchableNativeFeedback, TouchableOpacity, View, } from "react-native"; import { useKeyboardState } from "../../hooks"; import type { KeyboardToolbarTheme } from "./types"; import type { PropsWithChildren } from "react"; import type { GestureResponderEvent, ViewStyle } from "react-native"; type ButtonProps = { disabled?: boolean; onPress: (event: GestureResponderEvent) => void; accessibilityLabel: string; accessibilityHint: string; testID: string; rippleRadius?: number; style?: ViewStyle; theme: KeyboardToolbarTheme; }; const ButtonIOS = ({ children, onPress, disabled, accessibilityLabel, accessibilityHint, testID, style, }: PropsWithChildren) => { // immediately switch to plain view to avoid animation flickering // when fade out animation happens and view becomes disabled const Container = disabled ? (View as unknown as typeof TouchableOpacity) : TouchableOpacity; const accessibilityState = useMemo(() => ({ disabled }), [disabled]); return ( {children} ); }; const ButtonAndroid = ({ children, onPress, disabled, accessibilityLabel, accessibilityHint, testID, rippleRadius = 18, style, theme, }: PropsWithChildren) => { const colorScheme = useKeyboardState((state) => state.appearance); const accessibilityState = useMemo(() => ({ disabled }), [disabled]); const ripple = useMemo( () => TouchableNativeFeedback.Ripple( theme[colorScheme].ripple, true, rippleRadius, ), [colorScheme, rippleRadius, theme], ); return ( {children} ); }; export default Platform.select({ android: ButtonAndroid, default: ButtonIOS, });