MCPcopy
hub / github.com/gorhom/react-native-animated-tabbar / RawButton

Function RawButton

src/components/rawButton/RawButton.tsx:30–114  ·  view source on GitHub ↗
({
  index,
  selectedIndex,
  accessibilityLabel,
  children,
  style,
  animatedOnChange,
  onLongPress,
  onLayout,
}: RawButtonProps)

Source from the content-addressed store, hash-verified

28}
29
30const RawButton = ({
31 index,
32 selectedIndex,
33 accessibilityLabel,
34 children,
35 style,
36 animatedOnChange,
37 onLongPress,
38 onLayout,
39}: RawButtonProps) => {
40 // refs
41 const rootViewRef = useRef<Animated.View>(null);
42 const longPressGestureHandlerRef = useRef<LongPressGestureHandler>(null);
43
44 // tap gesture
45 const tapGestureState = useValue(State.UNDETERMINED);
46 const tapGestureHandler = useGestureHandler({ state: tapGestureState });
47
48 // long press gesture
49 const longPressGestureState = useValue(State.UNDETERMINED);
50 const longPressGestureHandler = useGestureHandler({
51 state: longPressGestureState,
52 });
53
54 // effects
55 useCode(
56 () => [
57 onChange(
58 tapGestureState,
59 cond(eq(tapGestureState, State.END), animatedOnChange(index))
60 ),
61 onChange(
62 longPressGestureState,
63 cond(
64 eq(longPressGestureState, State.ACTIVE),
65 call([], () => {
66 onLongPress(index);
67 })
68 )
69 ),
70 onChange(
71 selectedIndex,
72 call([selectedIndex], args => {
73 // @ts-ignore
74 rootViewRef.current.setNativeProps({
75 accessibilityState: {
76 selected: args[0] === index,
77 },
78 });
79 })
80 ),
81 ],
82 [index]
83 );
84
85 // callbacks
86 const handleContainerLayout = useStableCallback(
87 ({ nativeEvent: { layout } }: LayoutChangeEvent) =>

Callers

nothing calls this directly

Calls 1

useStableCallbackFunction · 0.90

Tested by

no test coverage detected