diff --git a/packages/react-native-gesture-handler/src/components/GestureButtons.tsx b/packages/react-native-gesture-handler/src/components/GestureButtons.tsx index 0f1e883c81..3ce1bbaf5d 100644 --- a/packages/react-native-gesture-handler/src/components/GestureButtons.tsx +++ b/packages/react-native-gesture-handler/src/components/GestureButtons.tsx @@ -1,5 +1,5 @@ import * as React from 'react'; -import type { HostComponent } from 'react-native'; +import type { HostComponent, ViewStyle } from 'react-native'; import { Animated, Platform, StyleSheet } from 'react-native'; import createNativeWrapper from '../handlers/createNativeWrapper'; @@ -134,13 +134,12 @@ class InnerBaseButton extends React.Component { }; override render() { - const { rippleColor, style, ...rest } = this.props; + const { rippleColor, ...rest } = this.props; return ( { {children} @@ -294,6 +293,13 @@ export const LegacyBorderlessButton = ({ /** * @deprecated use `PureNativeButton` instead */ -export const LegacyPureNativeButton = ( - props: Omit -) => ; +export const LegacyPureNativeButton = ({ + ref, + ...props +}: Omit) => ( + >} + needsOffscreenAlphaCompositing + /> +); diff --git a/packages/react-native-gesture-handler/src/components/GestureComponents.tsx b/packages/react-native-gesture-handler/src/components/GestureComponents.tsx index f029a3b703..c0dde9f4f5 100644 --- a/packages/react-native-gesture-handler/src/components/GestureComponents.tsx +++ b/packages/react-native-gesture-handler/src/components/GestureComponents.tsx @@ -47,15 +47,16 @@ const GHScrollView = createNativeWrapper>( export const LegacyScrollView = ( props: RNScrollViewProps & NativeViewGestureHandlerProps & { - ref?: React.Ref; + ref?: React.Ref | null>; } ) => { const refreshControlGestureRef = React.useRef(null); - const { refreshControl, waitFor, ...rest } = props; + const { refreshControl, waitFor, ref, ...rest } = props; return ( | null>} waitFor={[...toArray(waitFor ?? []), refreshControlGestureRef]} // @ts-ignore we don't pass `refreshing` prop as we only want to override the ref refreshControl={ @@ -73,7 +74,8 @@ export const LegacyScrollView = ( // Backward type compatibility with https://github.com/software-mansion/react-native-gesture-handler/blob/db78d3ca7d48e8ba57482d3fe9b0a15aa79d9932/react-native-gesture-handler.d.ts#L440-L457 // include methods of wrapped components by creating an intersection type with the RN component instead of duplicating them. // eslint-disable-next-line @typescript-eslint/no-redeclare -export type LegacyScrollView = typeof GHScrollView & RNScrollView; +export type LegacyScrollView = typeof GHScrollView & + React.ComponentRef; /** * @deprecated use `Switch` instead @@ -97,9 +99,12 @@ export type LegacyTextInput = typeof LegacyTextInput & RNTextInput; /** * @deprecated use `DrawerLayoutAndroid` instead */ -export const LegacyDrawerLayoutAndroid = createNativeWrapper< - PropsWithChildren ->(RNDrawerLayoutAndroid, { disallowInterruption: true }); +export const LegacyDrawerLayoutAndroid: React.ComponentType< + PropsWithChildren & NativeViewGestureHandlerProps +> = createNativeWrapper>( + RNDrawerLayoutAndroid, + { disallowInterruption: true } +); // eslint-disable-next-line @typescript-eslint/no-redeclare export type LegacyDrawerLayoutAndroid = typeof LegacyDrawerLayoutAndroid & RNDrawerLayoutAndroid; diff --git a/packages/react-native-gesture-handler/src/components/Pressable/Pressable.tsx b/packages/react-native-gesture-handler/src/components/Pressable/Pressable.tsx index a5aa4a340c..25f0d48d9b 100644 --- a/packages/react-native-gesture-handler/src/components/Pressable/Pressable.tsx +++ b/packages/react-native-gesture-handler/src/components/Pressable/Pressable.tsx @@ -68,6 +68,7 @@ const LegacyPressable = (props: LegacyPressableProps) => { simultaneousWithExternalGesture, requireExternalGestureToFail, blocksExternalGesture, + ref, ...remainingProps } = props; @@ -385,6 +386,7 @@ const LegacyPressable = (props: LegacyPressableProps) => { >} needsOffscreenAlphaCompositing onLayout={setDimensions} accessible={accessible !== false} diff --git a/packages/react-native-gesture-handler/src/components/Pressable/PressableProps.tsx b/packages/react-native-gesture-handler/src/components/Pressable/PressableProps.tsx index ba3085f3a6..4bab919222 100644 --- a/packages/react-native-gesture-handler/src/components/Pressable/PressableProps.tsx +++ b/packages/react-native-gesture-handler/src/components/Pressable/PressableProps.tsx @@ -109,7 +109,7 @@ interface CommonPressableProps /** * A reference to the pressable element. */ - ref?: React.Ref; + ref?: React.Ref>; /** * Either children or a render prop that receives a boolean reflecting whether diff --git a/packages/react-native-gesture-handler/src/components/ReanimatedDrawerLayout.tsx b/packages/react-native-gesture-handler/src/components/ReanimatedDrawerLayout.tsx index 25973058cc..b80ecfe50a 100644 --- a/packages/react-native-gesture-handler/src/components/ReanimatedDrawerLayout.tsx +++ b/packages/react-native-gesture-handler/src/components/ReanimatedDrawerLayout.tsx @@ -596,8 +596,10 @@ const DrawerLayout = function DrawerLayout( const reverseContentDirection = I18nManager.isRTL ? isFromLeft : !isFromLeft; const dynamicDrawerStyles = { - backgroundColor: drawerBackgroundColor, width: drawerWidth, + ...(drawerBackgroundColor !== undefined && { + backgroundColor: drawerBackgroundColor, + }), }; const containerStyles = useAnimatedStyle(() => { diff --git a/packages/react-native-gesture-handler/src/components/Text.tsx b/packages/react-native-gesture-handler/src/components/Text.tsx index 8a400cc319..7c6ff9a58c 100644 --- a/packages/react-native-gesture-handler/src/components/Text.tsx +++ b/packages/react-native-gesture-handler/src/components/Text.tsx @@ -9,7 +9,7 @@ import { GestureObjects as Gesture } from '../handlers/gestures/gestureObjects'; type TextProps = RNTextProps & { ref?: Ref | null>; }; -type RNGHTextRef = Ref & { rngh?: boolean }; +type RNGHTextRef = Ref | null> & { rngh?: boolean }; /** * @deprecated `LegacyText` is deprecated. Since Gesture Handler 3, you should wrap `Text` with `GestureDetector`, `InterceptingGestureDetector`, or `VirtualGestureDetector`. @@ -17,11 +17,11 @@ type RNGHTextRef = Ref & { rngh?: boolean }; export const LegacyText = (props: TextProps) => { const { onPress, onLongPress, ref, ...rest } = props; - const textRef = useRef(null); + const textRef = useRef | null>(null); const native = useMemo(() => Gesture.Native().runOnJS(true), []); const refHandler = useMemo(() => { - const handler: RNGHTextRef = (node: RNText | null) => { + const handler: RNGHTextRef = (node: ComponentRef | null) => { textRef.current = node; if (!ref) { diff --git a/packages/react-native-gesture-handler/src/components/touchables/TouchableHighlight.tsx b/packages/react-native-gesture-handler/src/components/touchables/TouchableHighlight.tsx index 9e4212aeef..f99f9994be 100644 --- a/packages/react-native-gesture-handler/src/components/touchables/TouchableHighlight.tsx +++ b/packages/react-native-gesture-handler/src/components/touchables/TouchableHighlight.tsx @@ -4,8 +4,9 @@ import type { ColorValue, TouchableHighlightProps as RNTouchableHighlightProps, ViewProps, + ViewStyle, } from 'react-native'; -import { StyleSheet, View } from 'react-native'; +import { View } from 'react-native'; import GenericTouchable, { TOUCHABLE_STATE } from './GenericTouchable'; import type { GenericTouchableProps } from './GenericTouchableProps'; @@ -88,7 +89,9 @@ export default class TouchableHighlight extends Component< this.props.children ) as React.ReactElement; // TODO: not sure if OK but fixes error return React.cloneElement(child, { - style: StyleSheet.compose(child.props.style, this.state.extraChildStyle), + style: this.state.extraChildStyle + ? [child.props.style, this.state.extraChildStyle as ViewStyle] + : child.props.style, }); } @@ -109,7 +112,7 @@ export default class TouchableHighlight extends Component< return ( {this.renderChildren()} diff --git a/packages/react-native-gesture-handler/src/components/touchables/TouchableNativeFeedback.android.tsx b/packages/react-native-gesture-handler/src/components/touchables/TouchableNativeFeedback.android.tsx index c7fe803743..18219cc84a 100644 --- a/packages/react-native-gesture-handler/src/components/touchables/TouchableNativeFeedback.android.tsx +++ b/packages/react-native-gesture-handler/src/components/touchables/TouchableNativeFeedback.android.tsx @@ -43,7 +43,12 @@ export default class TouchableNativeFeedback extends Component ({ + ): { + type: 'RippleAndroid'; + color: ColorValue; + borderless: boolean; + rippleRadius: number | undefined; + } => ({ type: 'RippleAndroid', color, borderless, @@ -61,7 +66,8 @@ export default class TouchableNativeFeedback extends Component( - component: ComponentClass

, + component: ComponentType

, options?: unknown ): ComponentClass

; }; diff --git a/packages/react-native-gesture-handler/src/specs/NativeRNGestureHandlerModule.ts b/packages/react-native-gesture-handler/src/specs/NativeRNGestureHandlerModule.ts index d961c5a4fb..ccb9f534a2 100644 --- a/packages/react-native-gesture-handler/src/specs/NativeRNGestureHandlerModule.ts +++ b/packages/react-native-gesture-handler/src/specs/NativeRNGestureHandlerModule.ts @@ -1,27 +1,38 @@ -import type { TurboModule } from 'react-native'; +import type { CodegenTypes, TurboModule } from 'react-native'; import { TurboModuleRegistry } from 'react-native'; -import type { Double } from 'react-native/Libraries/Types/CodegenTypes'; export interface Spec extends TurboModule { createGestureHandler: ( handlerName: string, - handlerTag: Double, + handlerTag: CodegenTypes.Double, // Record<> is not supported by codegen // eslint-disable-next-line @typescript-eslint/ban-types config: Object ) => void; attachGestureHandler: ( - handlerTag: Double, - newView: Double, - actionType: Double + handlerTag: CodegenTypes.Double, + newView: CodegenTypes.Double, + actionType: CodegenTypes.Double ) => void; - // eslint-disable-next-line @typescript-eslint/ban-types - setGestureHandlerConfig: (handlerTag: Double, newConfig: Object) => void; - // eslint-disable-next-line @typescript-eslint/ban-types - updateGestureHandlerConfig: (handlerTag: Double, newConfig: Object) => void; - // eslint-disable-next-line @typescript-eslint/ban-types - configureRelations: (handlerTag: Double, relations: Object) => void; - dropGestureHandler: (handlerTag: Double) => void; + + setGestureHandlerConfig: ( + handlerTag: CodegenTypes.Double, + // eslint-disable-next-line @typescript-eslint/ban-types + newConfig: Object + ) => void; + + updateGestureHandlerConfig: ( + handlerTag: CodegenTypes.Double, + // eslint-disable-next-line @typescript-eslint/ban-types + newConfig: Object + ) => void; + + configureRelations: ( + handlerTag: CodegenTypes.Double, + // eslint-disable-next-line @typescript-eslint/ban-types + relations: Object + ) => void; + dropGestureHandler: (handlerTag: CodegenTypes.Double) => void; flushOperations: () => void; installUIRuntimeBindings: () => boolean; } diff --git a/packages/react-native-gesture-handler/src/specs/RNGestureHandlerButtonNativeComponent.ts b/packages/react-native-gesture-handler/src/specs/RNGestureHandlerButtonNativeComponent.ts index 1842518015..67fff7a00d 100644 --- a/packages/react-native-gesture-handler/src/specs/RNGestureHandlerButtonNativeComponent.ts +++ b/packages/react-native-gesture-handler/src/specs/RNGestureHandlerButtonNativeComponent.ts @@ -1,59 +1,61 @@ -import type { ColorValue, ViewProps } from 'react-native'; import type { - Float, - Int32, - UnsafeMixed, - WithDefault, -} from 'react-native/Libraries/Types/CodegenTypes'; -import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent'; + CodegenTypes, + ColorValue, + HostComponent, + ViewProps, +} from 'react-native'; +import { codegenNativeComponent } from 'react-native'; // @ts-ignore - Redefining pointerEvents with WithDefault for codegen, conflicts with ViewProps type but codegen needs it interface NativeProps extends ViewProps { - exclusive?: WithDefault; + exclusive?: CodegenTypes.WithDefault; foreground?: boolean; borderless?: boolean; - enabled?: WithDefault; + enabled?: CodegenTypes.WithDefault; rippleColor?: ColorValue; - rippleRadius?: Int32; - touchSoundDisabled?: WithDefault; - pointerEvents?: WithDefault< + rippleRadius?: CodegenTypes.Int32; + touchSoundDisabled?: CodegenTypes.WithDefault; + pointerEvents?: CodegenTypes.WithDefault< 'box-none' | 'none' | 'box-only' | 'auto', 'auto' >; - tapAnimationInDuration?: WithDefault; - tapAnimationOutDuration?: WithDefault; - longPressDuration?: WithDefault; - longPressAnimationOutDuration?: WithDefault; - needsOffscreenAlphaCompositing?: WithDefault; - activeOpacity?: WithDefault; - activeScale?: WithDefault; - activeUnderlayOpacity?: WithDefault; + tapAnimationInDuration?: CodegenTypes.WithDefault; + tapAnimationOutDuration?: CodegenTypes.WithDefault; + longPressDuration?: CodegenTypes.WithDefault; + longPressAnimationOutDuration?: CodegenTypes.WithDefault< + CodegenTypes.Int32, + -1 + >; + needsOffscreenAlphaCompositing?: CodegenTypes.WithDefault; + activeOpacity?: CodegenTypes.WithDefault; + activeScale?: CodegenTypes.WithDefault; + activeUnderlayOpacity?: CodegenTypes.WithDefault; // Hover values default to -1 as an "unset" sentinel; the native side // resolves them to the corresponding default* value (matching web, where // an omitted hover value falls back to its default counterpart). - hoverOpacity?: WithDefault; - hoverScale?: WithDefault; - hoverUnderlayOpacity?: WithDefault; - hoverAnimationInDuration?: WithDefault; - hoverAnimationOutDuration?: WithDefault; - defaultOpacity?: WithDefault; - defaultScale?: WithDefault; - defaultUnderlayOpacity?: WithDefault; + hoverOpacity?: CodegenTypes.WithDefault; + hoverScale?: CodegenTypes.WithDefault; + hoverUnderlayOpacity?: CodegenTypes.WithDefault; + hoverAnimationInDuration?: CodegenTypes.WithDefault; + hoverAnimationOutDuration?: CodegenTypes.WithDefault; + defaultOpacity?: CodegenTypes.WithDefault; + defaultScale?: CodegenTypes.WithDefault; + defaultUnderlayOpacity?: CodegenTypes.WithDefault; underlayColor?: ColorValue; // Border style - borderWidth?: Float; + borderWidth?: CodegenTypes.Float; borderColor?: ColorValue; - borderStyle?: WithDefault; - overflow?: WithDefault; + borderStyle?: CodegenTypes.WithDefault; + overflow?: CodegenTypes.WithDefault; // Border width per-edge - borderLeftWidth?: Float; - borderRightWidth?: Float; - borderTopWidth?: Float; - borderBottomWidth?: Float; - borderStartWidth?: Float; - borderEndWidth?: Float; + borderLeftWidth?: CodegenTypes.Float; + borderRightWidth?: CodegenTypes.Float; + borderTopWidth?: CodegenTypes.Float; + borderBottomWidth?: CodegenTypes.Float; + borderStartWidth?: CodegenTypes.Float; + borderEndWidth?: CodegenTypes.Float; // Border color per-edge borderLeftColor?: ColorValue; @@ -75,19 +77,21 @@ interface NativeProps extends ViewProps { // through our delegate instead of falling through to // BaseViewManagerDelegate, which casts to Double and would crash on a // string value. - borderRadius?: UnsafeMixed; - borderTopLeftRadius?: UnsafeMixed; - borderTopRightRadius?: UnsafeMixed; - borderBottomLeftRadius?: UnsafeMixed; - borderBottomRightRadius?: UnsafeMixed; - borderTopStartRadius?: UnsafeMixed; - borderTopEndRadius?: UnsafeMixed; - borderBottomStartRadius?: UnsafeMixed; - borderBottomEndRadius?: UnsafeMixed; - borderEndEndRadius?: UnsafeMixed; - borderEndStartRadius?: UnsafeMixed; - borderStartEndRadius?: UnsafeMixed; - borderStartStartRadius?: UnsafeMixed; + borderRadius?: CodegenTypes.UnsafeMixed; + borderTopLeftRadius?: CodegenTypes.UnsafeMixed; + borderTopRightRadius?: CodegenTypes.UnsafeMixed; + borderBottomLeftRadius?: CodegenTypes.UnsafeMixed; + borderBottomRightRadius?: CodegenTypes.UnsafeMixed; + borderTopStartRadius?: CodegenTypes.UnsafeMixed; + borderTopEndRadius?: CodegenTypes.UnsafeMixed; + borderBottomStartRadius?: CodegenTypes.UnsafeMixed; + borderBottomEndRadius?: CodegenTypes.UnsafeMixed; + borderEndEndRadius?: CodegenTypes.UnsafeMixed; + borderEndStartRadius?: CodegenTypes.UnsafeMixed; + borderStartEndRadius?: CodegenTypes.UnsafeMixed; + borderStartStartRadius?: CodegenTypes.UnsafeMixed; } -export default codegenNativeComponent('RNGestureHandlerButton'); +export default codegenNativeComponent( + 'RNGestureHandlerButton' +) as HostComponent; diff --git a/packages/react-native-gesture-handler/src/specs/RNGestureHandlerDetectorNativeComponent.ts b/packages/react-native-gesture-handler/src/specs/RNGestureHandlerDetectorNativeComponent.ts index 3195335427..08f169c165 100644 --- a/packages/react-native-gesture-handler/src/specs/RNGestureHandlerDetectorNativeComponent.ts +++ b/packages/react-native-gesture-handler/src/specs/RNGestureHandlerDetectorNativeComponent.ts @@ -1,81 +1,76 @@ -import type { ViewProps } from 'react-native'; -import type { - DirectEventHandler, - Double, - Int32, - UnsafeMixed, - WithDefault, -} from 'react-native/Libraries/Types/CodegenTypes'; -import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent'; +import type { CodegenTypes, HostComponent, ViewProps } from 'react-native'; +import { codegenNativeComponent } from 'react-native'; type GestureHandlerEvent = Readonly<{ - handlerTag: Int32; - state: Int32; - handlerData: UnsafeMixed; + handlerTag: CodegenTypes.Int32; + state: CodegenTypes.Int32; + handlerData: CodegenTypes.UnsafeMixed; }>; type GestureHandlerStateChangeEvent = Readonly<{ - handlerTag: Int32; - state: Int32; - oldState: Int32; - handlerData: UnsafeMixed; + handlerTag: CodegenTypes.Int32; + state: CodegenTypes.Int32; + oldState: CodegenTypes.Int32; + handlerData: CodegenTypes.UnsafeMixed; }>; type GestureHandlerTouchEvent = Readonly<{ - handlerTag: Int32; - numberOfTouches: Int32; - state: Int32; - eventType: Int32; + handlerTag: CodegenTypes.Int32; + numberOfTouches: CodegenTypes.Int32; + state: CodegenTypes.Int32; + eventType: CodegenTypes.Int32; allTouches: { - id: Int32; - x: Double; - y: Double; - absoluteX: Double; - absoluteY: Double; + id: CodegenTypes.Int32; + x: CodegenTypes.Double; + y: CodegenTypes.Double; + absoluteX: CodegenTypes.Double; + absoluteY: CodegenTypes.Double; }[]; changedTouches: { - id: Int32; - x: Double; - y: Double; - absoluteX: Double; - absoluteY: Double; + id: CodegenTypes.Int32; + x: CodegenTypes.Double; + y: CodegenTypes.Double; + absoluteX: CodegenTypes.Double; + absoluteY: CodegenTypes.Double; }[]; - pointerType: Int32; + pointerType: CodegenTypes.Int32; }>; export interface VirtualChildrenProps { - handlerTags: Int32[]; - viewTag: Int32; + handlerTags: CodegenTypes.Int32[]; + viewTag: CodegenTypes.Int32; } // @ts-expect-error WithDefault adds `| null` to the type, which doesn't align with ViewProps.pointerEvents // Using Exclude to remove null from the type makes the error go away, but breaks codegen. export interface NativeProps extends ViewProps { - onGestureHandlerEvent?: DirectEventHandler | undefined; + onGestureHandlerEvent?: + | CodegenTypes.DirectEventHandler + | undefined; onGestureHandlerStateChange?: - | DirectEventHandler + | CodegenTypes.DirectEventHandler | undefined; onGestureHandlerTouchEvent?: - | DirectEventHandler + | CodegenTypes.DirectEventHandler | undefined; onGestureHandlerReanimatedEvent?: - | DirectEventHandler + | CodegenTypes.DirectEventHandler | undefined; onGestureHandlerReanimatedStateChange?: - | DirectEventHandler + | CodegenTypes.DirectEventHandler | undefined; onGestureHandlerReanimatedTouchEvent?: - | DirectEventHandler + | CodegenTypes.DirectEventHandler | undefined; onGestureHandlerAnimatedEvent?: - | DirectEventHandler + | CodegenTypes.DirectEventHandler | undefined; - handlerTags: Int32[]; - moduleId: Int32; + handlerTags: CodegenTypes.Int32[]; + moduleId: CodegenTypes.Int32; virtualChildren: VirtualChildrenProps[]; - pointerEvents?: WithDefault< + pointerEvents?: CodegenTypes.WithDefault< 'box-none' | 'none' | 'box-only' | 'auto', 'auto' >; @@ -83,4 +78,4 @@ export interface NativeProps extends ViewProps { export default codegenNativeComponent('RNGestureHandlerDetector', { interfaceOnly: true, -}); +}) as HostComponent; diff --git a/packages/react-native-gesture-handler/src/specs/RNGestureHandlerRootViewNativeComponent.ts b/packages/react-native-gesture-handler/src/specs/RNGestureHandlerRootViewNativeComponent.ts index 59cb663757..60b666ef7f 100644 --- a/packages/react-native-gesture-handler/src/specs/RNGestureHandlerRootViewNativeComponent.ts +++ b/packages/react-native-gesture-handler/src/specs/RNGestureHandlerRootViewNativeComponent.ts @@ -1,6 +1,5 @@ -import type { ViewProps } from 'react-native'; -import type { Int32 } from 'react-native/Libraries/Types/CodegenTypes'; -import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent'; +import type { CodegenTypes, HostComponent, ViewProps } from 'react-native'; +import { codegenNativeComponent } from 'react-native'; // Publicly accessible type, moduleId is set internally export interface RootViewNativeProps extends ViewProps { @@ -8,8 +7,10 @@ export interface RootViewNativeProps extends ViewProps { } interface NativeProps extends ViewProps { - moduleId: Int32; + moduleId: CodegenTypes.Int32; unstable_forceActive?: boolean; } -export default codegenNativeComponent('RNGestureHandlerRootView'); +export default codegenNativeComponent( + 'RNGestureHandlerRootView' +) as HostComponent; diff --git a/packages/react-native-gesture-handler/src/v3/components/GestureButtons.tsx b/packages/react-native-gesture-handler/src/v3/components/GestureButtons.tsx index e07cd9df60..7324f0c619 100644 --- a/packages/react-native-gesture-handler/src/v3/components/GestureButtons.tsx +++ b/packages/react-native-gesture-handler/src/v3/components/GestureButtons.tsx @@ -1,4 +1,5 @@ import React, { useRef } from 'react'; +import type { ViewStyle } from 'react-native'; import { Animated, Platform, StyleSheet } from 'react-native'; import GestureHandlerButton from '../../components/GestureHandlerButton'; @@ -23,7 +24,7 @@ type RawButtonInnerProps = RawButtonProps & { const RawButtonInner = createNativeWrapper< React.ComponentRef, RawButtonInnerProps ->(GestureHandlerButton, { +>(GestureHandlerButton as React.ComponentType, { shouldCancelWhenOutside: false, shouldActivateOnStart: false, }); @@ -46,7 +47,7 @@ export const BaseButton = (props: BaseButtonProps) => { const delayLongPress = props.delayLongPress ?? 600; - const { onLongPress, onPress, onActiveStateChange, style, ...rest } = props; + const { onLongPress, onPress, onActiveStateChange, ...rest } = props; const wrappedLongPress = () => { longPressDetected.current = true; @@ -100,7 +101,6 @@ export const BaseButton = (props: BaseButtonProps) => { return ( { {children} diff --git a/packages/react-native-gesture-handler/src/v3/components/GestureButtonsProps.ts b/packages/react-native-gesture-handler/src/v3/components/GestureButtonsProps.ts index bfbb6325fa..71192d1ad2 100644 --- a/packages/react-native-gesture-handler/src/v3/components/GestureButtonsProps.ts +++ b/packages/react-native-gesture-handler/src/v3/components/GestureButtonsProps.ts @@ -20,7 +20,7 @@ export interface RawButtonProps >, Omit< NativeWrapperProperties>, - 'hitSlop' | 'enabled' + 'hitSlop' | 'enabled' | 'testID' > {} /** diff --git a/packages/react-native-gesture-handler/src/v3/components/GestureComponents.tsx b/packages/react-native-gesture-handler/src/v3/components/GestureComponents.tsx index 3664bc9f7b..ffbdb846b3 100644 --- a/packages/react-native-gesture-handler/src/v3/components/GestureComponents.tsx +++ b/packages/react-native-gesture-handler/src/v3/components/GestureComponents.tsx @@ -23,8 +23,11 @@ import { NativeWrapperProps } from '../hooks/utils'; import type { NativeWrapperProperties } from '../types/NativeWrapperType'; import ScrollViewResponderInterceptor from './ScrollViewResponderInterceptor'; -export const RefreshControl = createNativeWrapper< - RNRefreshControl, +export const RefreshControl: React.ComponentType< + RNRefreshControlProps & + NativeWrapperProperties | null> +> = createNativeWrapper< + React.ComponentRef, RNRefreshControlProps >( RNRefreshControl, @@ -39,7 +42,7 @@ export const RefreshControl = createNativeWrapper< export type RefreshControl = typeof RefreshControl & RNRefreshControl; const GHScrollView = createNativeWrapper< - RNScrollView, + React.ComponentRef, PropsWithChildren >( RNScrollView, @@ -51,7 +54,8 @@ const GHScrollView = createNativeWrapper< ); export const ScrollView = ( - props: RNScrollViewProps & NativeWrapperProperties + props: RNScrollViewProps & + NativeWrapperProperties | null> ) => { const { children, @@ -101,18 +105,28 @@ export const ScrollView = ( // eslint-disable-next-line @typescript-eslint/no-redeclare export type ScrollView = typeof ScrollView & RNScrollView; -export const Switch = createNativeWrapper(RNSwitch, { - shouldCancelWhenOutside: false, - shouldActivateOnStart: true, - disallowInterruption: true, -}); +export const Switch: React.ComponentType< + RNSwitchProps & + NativeWrapperProperties | null> +> = createNativeWrapper, RNSwitchProps>( + RNSwitch, + { + shouldCancelWhenOutside: false, + shouldActivateOnStart: true, + disallowInterruption: true, + } +); // eslint-disable-next-line @typescript-eslint/no-redeclare export type Switch = typeof Switch & RNSwitch; -export const TextInput = createNativeWrapper( - RNTextInput -); +export const TextInput: React.ComponentType< + RNTextInputProps & + NativeWrapperProperties | null> +> = createNativeWrapper< + React.ComponentRef, + RNTextInputProps +>(RNTextInput); // eslint-disable-next-line @typescript-eslint/no-redeclare export type TextInput = typeof TextInput & RNTextInput; diff --git a/packages/react-native-gesture-handler/src/v3/components/Pressable.tsx b/packages/react-native-gesture-handler/src/v3/components/Pressable.tsx index e872809bca..df5fad3747 100644 --- a/packages/react-native-gesture-handler/src/v3/components/Pressable.tsx +++ b/packages/react-native-gesture-handler/src/v3/components/Pressable.tsx @@ -77,6 +77,7 @@ const Pressable = (props: PressableProps) => { simultaneousWith, requireToFail, block, + ref, ...remainingProps } = props; @@ -426,6 +427,7 @@ const Pressable = (props: PressableProps) => { >} {...tvProps} onLayout={setDimensions} accessible={accessible !== false} diff --git a/packages/react-native-gesture-handler/src/v3/detectors/HostGestureDetector.web.tsx b/packages/react-native-gesture-handler/src/v3/detectors/HostGestureDetector.web.tsx index 61fbadbed1..31d8a9b1e6 100644 --- a/packages/react-native-gesture-handler/src/v3/detectors/HostGestureDetector.web.tsx +++ b/packages/react-native-gesture-handler/src/v3/detectors/HostGestureDetector.web.tsx @@ -349,7 +349,9 @@ const HostGestureDetector = (props: GestureHandlerDetectorProps) => { }, [refs]); return ( - }> + >}> {children} ); diff --git a/packages/react-native-gesture-handler/src/v3/detectors/NativeDetector.tsx b/packages/react-native-gesture-handler/src/v3/detectors/NativeDetector.tsx index b992052a71..7672bd9509 100644 --- a/packages/react-native-gesture-handler/src/v3/detectors/NativeDetector.tsx +++ b/packages/react-native-gesture-handler/src/v3/detectors/NativeDetector.tsx @@ -5,7 +5,9 @@ import { useJSResponderHandler } from '../hooks/useJSResponderHandler'; import { isComposedGesture } from '../hooks/utils/relationUtils'; import type { NativeDetectorProps } from './common'; import { AnimatedNativeDetector, nativeDetectorStyles } from './common'; -import HostGestureDetector from './HostGestureDetector'; +import HostGestureDetector, { + type RNGestureHandlerDetectorNativeComponentProps, +} from './HostGestureDetector'; import { ReanimatedNativeDetector } from './ReanimatedNativeDetector'; import { useDetectorAttachmentGuard } from './useDetectorAttachmentGuard'; import { useGestureRelationsUpdater } from './useGestureRelationsUpdater'; @@ -24,11 +26,13 @@ export function NativeDetector< }: NativeDetectorProps) { const { handleStartShouldSetResponder } = useJSResponderHandler(gesture); - const NativeDetectorComponent = gesture.config.dispatchesAnimatedEvents - ? AnimatedNativeDetector - : gesture.config.shouldUseReanimatedDetector - ? ReanimatedNativeDetector - : HostGestureDetector; + const NativeDetectorComponent = ( + gesture.config.dispatchesAnimatedEvents + ? AnimatedNativeDetector + : gesture.config.shouldUseReanimatedDetector + ? ReanimatedNativeDetector + : HostGestureDetector + ) as React.FunctionComponent; ensureNativeDetectorComponent(NativeDetectorComponent); useGestureRelationsUpdater(gesture); diff --git a/packages/react-native-gesture-handler/src/v3/detectors/VirtualDetector/InterceptingGestureDetector.tsx b/packages/react-native-gesture-handler/src/v3/detectors/VirtualDetector/InterceptingGestureDetector.tsx index 5c2377934b..667775b030 100644 --- a/packages/react-native-gesture-handler/src/v3/detectors/VirtualDetector/InterceptingGestureDetector.tsx +++ b/packages/react-native-gesture-handler/src/v3/detectors/VirtualDetector/InterceptingGestureDetector.tsx @@ -15,7 +15,9 @@ import type { } from '../../types'; import type { InterceptingGestureDetectorProps } from '../common'; import { AnimatedNativeDetector, nativeDetectorStyles } from '../common'; -import HostGestureDetector from '../HostGestureDetector'; +import HostGestureDetector, { + type RNGestureHandlerDetectorNativeComponentProps, +} from '../HostGestureDetector'; import { ReanimatedNativeDetector } from '../ReanimatedNativeDetector'; import { useDetectorAttachmentGuard } from '../useDetectorAttachmentGuard'; import { useEnsureGestureHandlerRootView } from '../useEnsureGestureHandlerRootView'; @@ -85,11 +87,13 @@ export function InterceptingGestureDetector< mode === InterceptingDetectorMode.REANIMATED; const dispatchesAnimatedEvents = mode === InterceptingDetectorMode.ANIMATED; - const NativeDetectorComponent = dispatchesAnimatedEvents - ? AnimatedNativeDetector - : shouldUseReanimatedDetector - ? ReanimatedNativeDetector - : HostGestureDetector; + const NativeDetectorComponent = ( + dispatchesAnimatedEvents + ? AnimatedNativeDetector + : shouldUseReanimatedDetector + ? ReanimatedNativeDetector + : HostGestureDetector + ) as React.FunctionComponent; const register = useCallback((child: VirtualChild) => { setVirtualChildren((prev) => { diff --git a/packages/react-native-gesture-handler/src/v3/detectors/common.ts b/packages/react-native-gesture-handler/src/v3/detectors/common.ts index 0b9f7dca72..5bcdda9e84 100644 --- a/packages/react-native-gesture-handler/src/v3/detectors/common.ts +++ b/packages/react-native-gesture-handler/src/v3/detectors/common.ts @@ -7,7 +7,9 @@ import type { } from '../../handlers/gestureHandlerCommon'; import type { GestureDetectorProps as LegacyDetectorProps } from '../../handlers/gestures/GestureDetector'; import type { Gesture } from '../types'; -import HostGestureDetector from './HostGestureDetector'; +import HostGestureDetector, { + type RNGestureHandlerDetectorNativeComponentProps, +} from './HostGestureDetector'; export enum GestureDetectorType { Native, @@ -59,7 +61,7 @@ export type GestureDetectorProps< > | LegacyDetectorProps; -export const AnimatedNativeDetector = +export const AnimatedNativeDetector: React.ComponentType = Animated.createAnimatedComponent(HostGestureDetector); export const nativeDetectorStyles = StyleSheet.create({ diff --git a/packages/react-native-gesture-handler/src/v3/types/EventTypes.ts b/packages/react-native-gesture-handler/src/v3/types/EventTypes.ts index 9fdcfe6029..a325e6001e 100644 --- a/packages/react-native-gesture-handler/src/v3/types/EventTypes.ts +++ b/packages/react-native-gesture-handler/src/v3/types/EventTypes.ts @@ -71,8 +71,10 @@ export type UnpackedGestureHandlerEvent = // This is not how Animated.event is typed in React Native. We add _argMapping in order to // have access to the _argMapping property to check for usage of `change*` callbacks. // It's also not typed as a function, which is breaking Gesture Handler type definitions. +type AnimatedMapping = { [key: string]: AnimatedMapping } | Animated.Value; + export type AnimatedEvent = { - _argMapping: (Animated.Mapping | null)[]; + _argMapping: (AnimatedMapping | null)[]; }; export type ChangeCalculatorType = (