react-native-gesture-handler 2.18.1 → 2.20.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +1 -0
- package/android/build.gradle +11 -29
- package/android/fabric/src/main/java/com/swmansion/gesturehandler/ReactContextExtensions.kt +1 -1
- package/android/paper/src/main/java/com/swmansion/gesturehandler/ReactContextExtensions.kt +1 -1
- package/android/src/main/AndroidManifest.xml +1 -3
- package/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandler.kt +21 -21
- package/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandlerOrchestrator.kt +2 -2
- package/android/src/main/java/com/swmansion/gesturehandler/core/GestureUtils.kt +1 -0
- package/android/src/main/java/com/swmansion/gesturehandler/core/HoverGestureHandler.kt +16 -0
- package/android/src/main/java/com/swmansion/gesturehandler/core/LongPressGestureHandler.kt +80 -4
- package/android/src/main/java/com/swmansion/gesturehandler/core/PanGestureHandler.kt +8 -0
- package/android/src/main/java/com/swmansion/gesturehandler/core/PinchGestureHandler.kt +2 -1
- package/android/src/main/java/com/swmansion/gesturehandler/core/ScaleGestureDetector.java +10 -0
- package/android/src/main/java/com/swmansion/gesturehandler/core/StylusData.kt +103 -0
- package/android/src/main/java/com/swmansion/gesturehandler/core/Vector.kt +2 -2
- package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerButtonViewManager.kt +24 -15
- package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerModule.kt +3 -0
- package/android/src/main/java/com/swmansion/gesturehandler/react/eventbuilders/HoverGestureHandlerEventDataBuilder.kt +7 -0
- package/android/src/main/java/com/swmansion/gesturehandler/react/eventbuilders/PanGestureHandlerEventDataBuilder.kt +7 -0
- package/android/src/main/jni/CMakeLists.txt +18 -9
- package/apple/Handlers/RNFlingHandler.h +1 -0
- package/apple/Handlers/RNFlingHandler.m +153 -19
- package/apple/Handlers/RNHoverHandler.m +44 -2
- package/apple/Handlers/RNLongPressHandler.m +111 -20
- package/apple/Handlers/RNManualHandler.m +53 -29
- package/apple/Handlers/RNNativeViewHandler.mm +22 -15
- package/apple/Handlers/RNPanHandler.m +57 -7
- package/apple/Handlers/RNRotationHandler.m +1 -1
- package/apple/RNGHStylusData.h +77 -0
- package/apple/RNGHStylusData.m +37 -0
- package/apple/RNGHUIKit.h +2 -0
- package/apple/RNGHVector.h +31 -0
- package/apple/RNGHVector.m +67 -0
- package/apple/RNGestureHandler.h +7 -0
- package/apple/{RNGestureHandler.m → RNGestureHandler.mm} +63 -1
- package/apple/RNGestureHandlerButtonComponentView.mm +41 -0
- package/apple/RNGestureHandlerDirection.h +25 -0
- package/apple/RNGestureHandlerEvents.h +3 -1
- package/apple/RNGestureHandlerEvents.m +11 -3
- package/lib/commonjs/PointerType.js +2 -1
- package/lib/commonjs/PointerType.js.map +1 -1
- package/lib/commonjs/components/GestureButtons.js +5 -1
- package/lib/commonjs/components/GestureButtons.js.map +1 -1
- package/lib/commonjs/components/GestureComponents.js.map +1 -1
- package/lib/commonjs/components/Pressable/Pressable.js +66 -78
- package/lib/commonjs/components/Pressable/Pressable.js.map +1 -1
- package/lib/commonjs/components/Pressable/index.js +0 -8
- package/lib/commonjs/components/Pressable/index.js.map +1 -1
- package/lib/commonjs/components/Pressable/utils.js +1 -23
- package/lib/commonjs/components/Pressable/utils.js.map +1 -1
- package/lib/commonjs/components/ReanimatedSwipeable.js +60 -41
- package/lib/commonjs/components/ReanimatedSwipeable.js.map +1 -1
- package/lib/commonjs/handlers/GestureHandlerEventPayload.js +4 -0
- package/lib/commonjs/handlers/LongPressGestureHandler.js +1 -1
- package/lib/commonjs/handlers/LongPressGestureHandler.js.map +1 -1
- package/lib/commonjs/handlers/createHandler.js +2 -1
- package/lib/commonjs/handlers/createHandler.js.map +1 -1
- package/lib/commonjs/handlers/gestures/GestureDetector/utils.js +1 -1
- package/lib/commonjs/handlers/gestures/GestureDetector/utils.js.map +1 -1
- package/lib/commonjs/handlers/gestures/gesture.js.map +1 -1
- package/lib/commonjs/handlers/gestures/hoverGesture.js.map +1 -1
- package/lib/commonjs/handlers/gestures/longPressGesture.js +10 -0
- package/lib/commonjs/handlers/gestures/longPressGesture.js.map +1 -1
- package/lib/commonjs/jestUtils/jestUtils.js +12 -4
- package/lib/commonjs/jestUtils/jestUtils.js.map +1 -1
- package/lib/commonjs/mocks.js +16 -3
- package/lib/commonjs/mocks.js.map +1 -1
- package/lib/commonjs/utils.js +4 -0
- package/lib/commonjs/utils.js.map +1 -1
- package/lib/commonjs/web/constants.js +3 -3
- package/lib/commonjs/web/constants.js.map +1 -1
- package/lib/commonjs/web/handlers/GestureHandler.js +2 -3
- package/lib/commonjs/web/handlers/GestureHandler.js.map +1 -1
- package/lib/commonjs/web/handlers/HoverGestureHandler.js +18 -1
- package/lib/commonjs/web/handlers/HoverGestureHandler.js.map +1 -1
- package/lib/commonjs/web/handlers/LongPressGestureHandler.js +43 -9
- package/lib/commonjs/web/handlers/LongPressGestureHandler.js.map +1 -1
- package/lib/commonjs/web/handlers/NativeViewGestureHandler.js +14 -3
- package/lib/commonjs/web/handlers/NativeViewGestureHandler.js.map +1 -1
- package/lib/commonjs/web/handlers/PanGestureHandler.js +12 -1
- package/lib/commonjs/web/handlers/PanGestureHandler.js.map +1 -1
- package/lib/commonjs/web/interfaces.js.map +1 -1
- package/lib/commonjs/web/tools/EventManager.js.map +1 -1
- package/lib/commonjs/web/tools/GestureHandlerWebDelegate.js +55 -11
- package/lib/commonjs/web/tools/GestureHandlerWebDelegate.js.map +1 -1
- package/lib/commonjs/web/tools/KeyboardEventManager.js +110 -0
- package/lib/commonjs/web/tools/KeyboardEventManager.js.map +1 -0
- package/lib/commonjs/web/tools/PointerEventManager.js +3 -37
- package/lib/commonjs/web/tools/PointerEventManager.js.map +1 -1
- package/lib/commonjs/web/tools/Vector.js +4 -2
- package/lib/commonjs/web/tools/Vector.js.map +1 -1
- package/lib/commonjs/web/utils.js +187 -13
- package/lib/commonjs/web/utils.js.map +1 -1
- package/lib/module/PointerType.js +2 -1
- package/lib/module/PointerType.js.map +1 -1
- package/lib/module/components/GestureButtons.js +5 -1
- package/lib/module/components/GestureButtons.js.map +1 -1
- package/lib/module/components/GestureComponents.js.map +1 -1
- package/lib/module/components/Pressable/Pressable.js +67 -78
- package/lib/module/components/Pressable/Pressable.js.map +1 -1
- package/lib/module/components/Pressable/index.js +0 -1
- package/lib/module/components/Pressable/index.js.map +1 -1
- package/lib/module/components/Pressable/utils.js +1 -22
- package/lib/module/components/Pressable/utils.js.map +1 -1
- package/lib/module/components/ReanimatedSwipeable.js +58 -37
- package/lib/module/components/ReanimatedSwipeable.js.map +1 -1
- package/lib/module/handlers/GestureHandlerEventPayload.js +1 -1
- package/lib/module/handlers/LongPressGestureHandler.js +1 -1
- package/lib/module/handlers/LongPressGestureHandler.js.map +1 -1
- package/lib/module/handlers/createHandler.js +2 -1
- package/lib/module/handlers/createHandler.js.map +1 -1
- package/lib/module/handlers/gestures/GestureDetector/utils.js +2 -2
- package/lib/module/handlers/gestures/GestureDetector/utils.js.map +1 -1
- package/lib/module/handlers/gestures/gesture.js.map +1 -1
- package/lib/module/handlers/gestures/hoverGesture.js.map +1 -1
- package/lib/module/handlers/gestures/longPressGesture.js +10 -0
- package/lib/module/handlers/gestures/longPressGesture.js.map +1 -1
- package/lib/module/jestUtils/jestUtils.js +12 -4
- package/lib/module/jestUtils/jestUtils.js.map +1 -1
- package/lib/module/mocks.js +13 -3
- package/lib/module/mocks.js.map +1 -1
- package/lib/module/utils.js +1 -0
- package/lib/module/utils.js.map +1 -1
- package/lib/module/web/constants.js +1 -1
- package/lib/module/web/constants.js.map +1 -1
- package/lib/module/web/handlers/GestureHandler.js +2 -3
- package/lib/module/web/handlers/GestureHandler.js.map +1 -1
- package/lib/module/web/handlers/HoverGestureHandler.js +18 -1
- package/lib/module/web/handlers/HoverGestureHandler.js.map +1 -1
- package/lib/module/web/handlers/LongPressGestureHandler.js +43 -9
- package/lib/module/web/handlers/LongPressGestureHandler.js.map +1 -1
- package/lib/module/web/handlers/NativeViewGestureHandler.js +14 -3
- package/lib/module/web/handlers/NativeViewGestureHandler.js.map +1 -1
- package/lib/module/web/handlers/PanGestureHandler.js +12 -1
- package/lib/module/web/handlers/PanGestureHandler.js.map +1 -1
- package/lib/module/web/interfaces.js.map +1 -1
- package/lib/module/web/tools/EventManager.js.map +1 -1
- package/lib/module/web/tools/GestureHandlerWebDelegate.js +54 -10
- package/lib/module/web/tools/GestureHandlerWebDelegate.js.map +1 -1
- package/lib/module/web/tools/KeyboardEventManager.js +96 -0
- package/lib/module/web/tools/KeyboardEventManager.js.map +1 -0
- package/lib/module/web/tools/PointerEventManager.js +4 -38
- package/lib/module/web/tools/PointerEventManager.js.map +1 -1
- package/lib/module/web/tools/Vector.js +5 -3
- package/lib/module/web/tools/Vector.js.map +1 -1
- package/lib/module/web/utils.js +184 -13
- package/lib/module/web/utils.js.map +1 -1
- package/lib/typescript/PointerType.d.ts +2 -1
- package/lib/typescript/components/GestureComponents.d.ts +1 -1
- package/lib/typescript/components/Pressable/index.d.ts +1 -1
- package/lib/typescript/components/Pressable/utils.d.ts +3 -5
- package/lib/typescript/handlers/GestureHandlerEventPayload.d.ts +35 -0
- package/lib/typescript/handlers/LongPressGestureHandler.d.ts +5 -1
- package/lib/typescript/handlers/gestures/gesture.d.ts +2 -2
- package/lib/typescript/handlers/gestures/hoverGesture.d.ts +1 -6
- package/lib/typescript/handlers/gestures/longPressGesture.d.ts +5 -0
- package/lib/typescript/handlers/handlersRegistry.d.ts +1 -1
- package/lib/typescript/jestUtils/jestUtils.d.ts +1 -1
- package/lib/typescript/mocks.d.ts +4 -3
- package/lib/typescript/utils.d.ts +1 -0
- package/lib/typescript/web/constants.d.ts +1 -1
- package/lib/typescript/web/handlers/GestureHandler.d.ts +1 -1
- package/lib/typescript/web/handlers/HoverGestureHandler.d.ts +2 -0
- package/lib/typescript/web/handlers/LongPressGestureHandler.d.ts +3 -0
- package/lib/typescript/web/handlers/NativeViewGestureHandler.d.ts +1 -0
- package/lib/typescript/web/handlers/PanGestureHandler.d.ts +3 -1
- package/lib/typescript/web/interfaces.d.ts +9 -4
- package/lib/typescript/web/tools/EventManager.d.ts +2 -2
- package/lib/typescript/web/tools/GestureHandlerDelegate.d.ts +1 -0
- package/lib/typescript/web/tools/GestureHandlerWebDelegate.d.ts +6 -0
- package/lib/typescript/web/tools/KeyboardEventManager.d.ts +13 -0
- package/lib/typescript/web/utils.d.ts +2 -1
- package/package.json +3 -3
- package/src/PointerType.ts +1 -0
- package/src/components/GestureButtons.tsx +2 -1
- package/src/components/GestureComponents.tsx +1 -1
- package/src/components/Pressable/Pressable.tsx +77 -70
- package/src/components/Pressable/index.ts +1 -1
- package/src/components/Pressable/utils.ts +5 -49
- package/src/components/ReanimatedSwipeable.tsx +70 -47
- package/src/handlers/GestureHandlerEventPayload.ts +42 -0
- package/src/handlers/LongPressGestureHandler.ts +6 -0
- package/src/handlers/createHandler.tsx +1 -0
- package/src/handlers/gestures/GestureDetector/utils.ts +2 -2
- package/src/handlers/gestures/gesture.ts +3 -1
- package/src/handlers/gestures/hoverGesture.ts +1 -7
- package/src/handlers/gestures/longPressGesture.ts +9 -0
- package/src/jestUtils/jestUtils.ts +9 -1
- package/src/{mocks.ts → mocks.tsx} +8 -3
- package/src/utils.ts +2 -0
- package/src/web/constants.ts +1 -1
- package/src/web/handlers/GestureHandler.ts +4 -2
- package/src/web/handlers/HoverGestureHandler.ts +16 -2
- package/src/web/handlers/LongPressGestureHandler.ts +49 -10
- package/src/web/handlers/NativeViewGestureHandler.ts +14 -4
- package/src/web/handlers/PanGestureHandler.ts +14 -1
- package/src/web/interfaces.ts +10 -4
- package/src/web/tools/EventManager.ts +2 -4
- package/src/web/tools/GestureHandlerDelegate.ts +1 -0
- package/src/web/tools/GestureHandlerWebDelegate.ts +67 -10
- package/src/web/tools/KeyboardEventManager.ts +91 -0
- package/src/web/tools/PointerEventManager.ts +2 -38
- package/src/web/tools/Vector.ts +4 -3
- package/src/web/utils.ts +188 -13
- package/lib/commonjs/web/tools/TouchEventManager.js +0 -164
- package/lib/commonjs/web/tools/TouchEventManager.js.map +0 -1
- package/lib/module/web/tools/TouchEventManager.js +0 -149
- package/lib/module/web/tools/TouchEventManager.js.map +0 -1
- package/lib/typescript/web/tools/TouchEventManager.d.ts +0 -11
- package/src/web/tools/TouchEventManager.ts +0 -175
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["GestureComponents.tsx"],"names":["React","ScrollView","RNScrollView","Switch","RNSwitch","TextInput","RNTextInput","DrawerLayoutAndroid","RNDrawerLayoutAndroid","FlatList","RNFlatList","RefreshControl","RNRefreshControl","createNativeWrapper","nativeViewProps","toArray","disallowInterruption","shouldCancelWhenOutside","GHScrollView","forwardRef","props","ref","refreshControlGestureRef","useRef","refreshControl","waitFor","rest","cloneElement","undefined","shouldActivateOnStart","flatListProps","scrollViewProps","propName","value","Object","entries","includes","scrollProps"],"mappings":";;AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AAOA,SACEC,UAAU,IAAIC,YADhB,EAGEC,MAAM,IAAIC,QAHZ,EAKEC,SAAS,IAAIC,WALf,EAOEC,mBAAmB,IAAIC,qBAPzB,EASEC,QAAQ,IAAIC,UATd,EAWEC,cAAc,IAAIC,gBAXpB,QAYO,cAZP;AAcA,OAAOC,mBAAP,MAAgC,iCAAhC;AAEA,SAEEC,eAFF,QAGO,sCAHP;AAKA,SAASC,OAAT,QAAwB,UAAxB;AAEA,OAAO,MAAMJ,cAAc,GAAGE,mBAAmB,CAACD,gBAAD,EAAmB;AAClEI,EAAAA,oBAAoB,EAAE,IAD4C;AAElEC,EAAAA,uBAAuB,EAAE;AAFyC,CAAnB,CAA1C,C,CAIP;;AAGA,MAAMC,YAAY,GAAGL,mBAAmB,CACtCX,YADsC,EAEtC;AACEc,EAAAA,oBAAoB,EAAE,IADxB;AAEEC,EAAAA,uBAAuB,EAAE;AAF3B,CAFsC,CAAxC;AAOA,OAAO,MAAMhB,UAAU,gBAAGD,KAAK,CAACmB,UAAN,CAGxB,CAACC,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,KAA7C;AAEA,QAAMU,aAAa,GAAG,EAAtB;AACA,QAAMC,eAAe,GAAG,EAAxB;;AACA,OAAK,MAAM,CAACC,QAAD,EAAWC,KAAX,CAAX,IAAgCC,MAAM,CAACC,OAAP,CAAeT,IAAf,CAAhC,EAAsD;AACpD;AACA,QAAKZ,eAAD,CAAuCsB,QAAvC,CAAgDJ,QAAhD,CAAJ,EAA+D;AAC7D;AACA;AACAD,MAAAA,eAAe,CAACC,QAAD,CAAf,GAA4BC,KAA5B;AACD,KAJD,MAIO;AACL;AACA;AACAH,MAAAA,aAAa,CAACE,QAAD,CAAb,GAA0BC,KAA1B;AACD;AACF;;AAED;AAAA;AACE;AACA,wBAAC,UAAD;AACE,MAAA,GAAG,EAAEZ;AADP,OAEMS,aAFN;AAGE,MAAA,qBAAqB,EAAGO,WAAD,iBACrB,oBAAC,UAAD,eAEOA,WAFP,EAGON,eAHP;AAIIN,QAAAA,OAAO,EAAE,CAAC,GAAGV,OAAO,CAACU,OAAD,aAACA,OAAD,cAACA,OAAD,GAAY,EAAZ,CAAX,EAA4BH,wBAA5B;AAJb,SAJJ,CAYE;AAZF;AAaE,MAAA,cAAc,EACZE,cAAc,gBACVxB,KAAK,CAAC2B,YAAN,CAAmBH,cAAnB,EAAmC;AACjC;AACAH,QAAAA,GAAG,EAAEC;AAF4B,OAAnC,CADU,GAKVM;AAnBR;AAFF;AAyBD,CA7CuB,CAAjB,C,CAqDP","sourcesContent":["import * as React from 'react';\nimport {\n PropsWithChildren,\n ForwardedRef,\n RefAttributes,\n ReactElement,\n} from 'react';\nimport {\n ScrollView as RNScrollView,\n ScrollViewProps as RNScrollViewProps,\n Switch as RNSwitch,\n SwitchProps as RNSwitchProps,\n TextInput as RNTextInput,\n TextInputProps as RNTextInputProps,\n DrawerLayoutAndroid as RNDrawerLayoutAndroid,\n DrawerLayoutAndroidProps as RNDrawerLayoutAndroidProps,\n FlatList as RNFlatList,\n FlatListProps as RNFlatListProps,\n RefreshControl as RNRefreshControl,\n} from 'react-native';\n\nimport createNativeWrapper from '../handlers/createNativeWrapper';\n\nimport {\n NativeViewGestureHandlerProps,\n nativeViewProps,\n} from '../handlers/NativeViewGestureHandler';\n\nimport { toArray } from '../utils';\n\nexport const RefreshControl = createNativeWrapper(RNRefreshControl, {\n disallowInterruption: true,\n shouldCancelWhenOutside: false,\n});\n// eslint-disable-next-line @typescript-eslint/no-redeclare\nexport type RefreshControl = typeof RefreshControl & RNRefreshControl;\n\nconst GHScrollView = createNativeWrapper<PropsWithChildren<RNScrollViewProps>>(\n RNScrollView,\n {\n disallowInterruption: true,\n shouldCancelWhenOutside: false,\n }\n);\nexport const ScrollView = React.forwardRef<\n RNScrollView,\n RNScrollViewProps & NativeViewGestureHandlerProps\n>((props, ref) => {\n const refreshControlGestureRef = React.useRef<RefreshControl>(null);\n const { refreshControl, waitFor, ...rest } = props;\n\n return (\n <GHScrollView\n {...rest}\n // @ts-ignore `ref` exists on `GHScrollView`\n ref={ref}\n waitFor={[...toArray(waitFor ?? []), refreshControlGestureRef]}\n // @ts-ignore we don't pass `refreshing` prop as we only want to override the ref\n refreshControl={\n refreshControl\n ? React.cloneElement(refreshControl, {\n // @ts-ignore for reasons unknown to me, `ref` doesn't exist on the type inferred by TS\n ref: refreshControlGestureRef,\n })\n : undefined\n }\n />\n );\n});\n// Backward type compatibility with https://github.com/software-mansion/react-native-gesture-handler/blob/db78d3ca7d48e8ba57482d3fe9b0a15aa79d9932/react-native-gesture-handler.d.ts#L440-L457\n// include methods of wrapped components by creating an intersection type with the RN component instead of duplicating them.\n// eslint-disable-next-line @typescript-eslint/no-redeclare\nexport type ScrollView = typeof GHScrollView & RNScrollView;\n\nexport const Switch = createNativeWrapper<RNSwitchProps>(RNSwitch, {\n shouldCancelWhenOutside: false,\n shouldActivateOnStart: true,\n disallowInterruption: true,\n});\n// eslint-disable-next-line @typescript-eslint/no-redeclare\nexport type Switch = typeof Switch & RNSwitch;\n\nexport const TextInput = createNativeWrapper<RNTextInputProps>(RNTextInput);\n// eslint-disable-next-line @typescript-eslint/no-redeclare\nexport type TextInput = typeof TextInput & RNTextInput;\n\nexport const DrawerLayoutAndroid = createNativeWrapper<\n PropsWithChildren<RNDrawerLayoutAndroidProps>\n>(RNDrawerLayoutAndroid, { disallowInterruption: true });\n// eslint-disable-next-line @typescript-eslint/no-redeclare\nexport type DrawerLayoutAndroid = typeof DrawerLayoutAndroid &\n RNDrawerLayoutAndroid;\n\nexport const FlatList = React.forwardRef((props, ref) => {\n const refreshControlGestureRef = React.useRef<RefreshControl>(null);\n\n const { waitFor, refreshControl, ...rest } = props;\n\n const flatListProps = {};\n const scrollViewProps = {};\n for (const [propName, value] of Object.entries(rest)) {\n // https://github.com/microsoft/TypeScript/issues/26255\n if ((nativeViewProps as readonly string[]).includes(propName)) {\n // @ts-ignore - this function cannot have generic type so we have to ignore this error\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n scrollViewProps[propName] = value;\n } else {\n // @ts-ignore - this function cannot have generic type so we have to ignore this error\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n flatListProps[propName] = value;\n }\n }\n\n return (\n // @ts-ignore - this function cannot have generic type so we have to ignore this error\n <RNFlatList\n ref={ref}\n {...flatListProps}\n renderScrollComponent={(scrollProps) => (\n <ScrollView\n {...{\n ...scrollProps,\n ...scrollViewProps,\n waitFor: [...toArray(waitFor ?? []), refreshControlGestureRef],\n }}\n />\n )}\n // @ts-ignore we don't pass `refreshing` prop as we only want to override the ref\n refreshControl={\n refreshControl\n ? React.cloneElement(refreshControl, {\n // @ts-ignore for reasons unknown to me, `ref` doesn't exist on the type inferred by TS\n ref: refreshControlGestureRef,\n })\n : undefined\n }\n />\n );\n}) as <ItemT = any>(\n props: PropsWithChildren<\n RNFlatListProps<ItemT> &\n RefAttributes<FlatList<ItemT>> &\n NativeViewGestureHandlerProps\n >,\n ref: ForwardedRef<FlatList<ItemT>>\n) => ReactElement | null;\n// eslint-disable-next-line @typescript-eslint/no-redeclare\nexport type FlatList<ItemT = any> = typeof FlatList & RNFlatList<ItemT>;\n"]}
|
1
|
+
{"version":3,"sources":["GestureComponents.tsx"],"names":["React","ScrollView","RNScrollView","Switch","RNSwitch","TextInput","RNTextInput","DrawerLayoutAndroid","RNDrawerLayoutAndroid","FlatList","RNFlatList","RefreshControl","RNRefreshControl","createNativeWrapper","nativeViewProps","toArray","disallowInterruption","shouldCancelWhenOutside","GHScrollView","forwardRef","props","ref","refreshControlGestureRef","useRef","refreshControl","waitFor","rest","cloneElement","undefined","shouldActivateOnStart","flatListProps","scrollViewProps","propName","value","Object","entries","includes","scrollProps"],"mappings":";;AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AAOA,SACEC,UAAU,IAAIC,YADhB,EAGEC,MAAM,IAAIC,QAHZ,EAKEC,SAAS,IAAIC,WALf,EAOEC,mBAAmB,IAAIC,qBAPzB,EASEC,QAAQ,IAAIC,UATd,EAWEC,cAAc,IAAIC,gBAXpB,QAYO,cAZP;AAcA,OAAOC,mBAAP,MAAgC,iCAAhC;AAEA,SAEEC,eAFF,QAGO,sCAHP;AAKA,SAASC,OAAT,QAAwB,UAAxB;AAEA,OAAO,MAAMJ,cAAc,GAAGE,mBAAmB,CAACD,gBAAD,EAAmB;AAClEI,EAAAA,oBAAoB,EAAE,IAD4C;AAElEC,EAAAA,uBAAuB,EAAE;AAFyC,CAAnB,CAA1C,C,CAIP;;AAGA,MAAMC,YAAY,GAAGL,mBAAmB,CACtCX,YADsC,EAEtC;AACEc,EAAAA,oBAAoB,EAAE,IADxB;AAEEC,EAAAA,uBAAuB,EAAE;AAF3B,CAFsC,CAAxC;AAOA,OAAO,MAAMhB,UAAU,gBAAGD,KAAK,CAACmB,UAAN,CAGxB,CAACC,KAAD,EAAQC,GAAR,KAAgB;AAChB,QAAMC,wBAAwB,GAAGtB,KAAK,CAACuB,MAAN,CAA6B,IAA7B,CAAjC;AACA,QAAM;AAAEC,IAAAA,cAAF;AAAkBC,IAAAA,OAAlB;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eT,IAAf,CAAhC,EAAsD;AACpD;AACA,QAAKZ,eAAD,CAAuCsB,QAAvC,CAAgDJ,QAAhD,CAAJ,EAA+D;AAC7D;AACA;AACAD,MAAAA,eAAe,CAACC,QAAD,CAAf,GAA4BC,KAA5B;AACD,KAJD,MAIO;AACL;AACA;AACAH,MAAAA,aAAa,CAACE,QAAD,CAAb,GAA0BC,KAA1B;AACD;AACF;;AAED;AAAA;AACE;AACA,wBAAC,UAAD;AACE,MAAA,GAAG,EAAEZ;AADP,OAEMS,aAFN;AAGE,MAAA,qBAAqB,EAAGO,WAAD,iBACrB,oBAAC,UAAD,eAEOA,WAFP,EAGON,eAHP;AAIIN,QAAAA,OAAO,EAAE,CAAC,GAAGV,OAAO,CAACU,OAAD,aAACA,OAAD,cAACA,OAAD,GAAY,EAAZ,CAAX,EAA4BH,wBAA5B;AAJb,SAJJ,CAYE;AAZF;AAaE,MAAA,cAAc,EACZE,cAAc,gBACVxB,KAAK,CAAC2B,YAAN,CAAmBH,cAAnB,EAAmC;AACjC;AACAH,QAAAA,GAAG,EAAEC;AAF4B,OAAnC,CADU,GAKVM;AAnBR;AAFF;AAyBD,CA7CuB,CAAjB,C,CAqDP","sourcesContent":["import * as React from 'react';\nimport {\n PropsWithChildren,\n ForwardedRef,\n RefAttributes,\n ReactElement,\n} from 'react';\nimport {\n ScrollView as RNScrollView,\n ScrollViewProps as RNScrollViewProps,\n Switch as RNSwitch,\n SwitchProps as RNSwitchProps,\n TextInput as RNTextInput,\n TextInputProps as RNTextInputProps,\n DrawerLayoutAndroid as RNDrawerLayoutAndroid,\n DrawerLayoutAndroidProps as RNDrawerLayoutAndroidProps,\n FlatList as RNFlatList,\n FlatListProps as RNFlatListProps,\n RefreshControl as RNRefreshControl,\n} from 'react-native';\n\nimport createNativeWrapper from '../handlers/createNativeWrapper';\n\nimport {\n NativeViewGestureHandlerProps,\n nativeViewProps,\n} from '../handlers/NativeViewGestureHandler';\n\nimport { toArray } from '../utils';\n\nexport const RefreshControl = createNativeWrapper(RNRefreshControl, {\n disallowInterruption: true,\n shouldCancelWhenOutside: false,\n});\n// eslint-disable-next-line @typescript-eslint/no-redeclare\nexport type RefreshControl = typeof RefreshControl & RNRefreshControl;\n\nconst GHScrollView = createNativeWrapper<PropsWithChildren<RNScrollViewProps>>(\n RNScrollView,\n {\n disallowInterruption: true,\n shouldCancelWhenOutside: false,\n }\n);\nexport const ScrollView = React.forwardRef<\n RNScrollView,\n RNScrollViewProps & NativeViewGestureHandlerProps\n>((props, ref) => {\n const refreshControlGestureRef = React.useRef<RefreshControl>(null);\n const { refreshControl, waitFor, ...rest } = props;\n\n return (\n <GHScrollView\n {...rest}\n // @ts-ignore `ref` exists on `GHScrollView`\n ref={ref}\n waitFor={[...toArray(waitFor ?? []), refreshControlGestureRef]}\n // @ts-ignore we don't pass `refreshing` prop as we only want to override the ref\n refreshControl={\n refreshControl\n ? React.cloneElement(refreshControl, {\n // @ts-ignore for reasons unknown to me, `ref` doesn't exist on the type inferred by TS\n ref: refreshControlGestureRef,\n })\n : undefined\n }\n />\n );\n});\n// Backward type compatibility with https://github.com/software-mansion/react-native-gesture-handler/blob/db78d3ca7d48e8ba57482d3fe9b0a15aa79d9932/react-native-gesture-handler.d.ts#L440-L457\n// include methods of wrapped components by creating an intersection type with the RN component instead of duplicating them.\n// eslint-disable-next-line @typescript-eslint/no-redeclare\nexport type ScrollView = typeof GHScrollView & RNScrollView;\n\nexport const Switch = createNativeWrapper<RNSwitchProps>(RNSwitch, {\n shouldCancelWhenOutside: false,\n shouldActivateOnStart: true,\n disallowInterruption: true,\n});\n// eslint-disable-next-line @typescript-eslint/no-redeclare\nexport type Switch = typeof Switch & RNSwitch;\n\nexport const TextInput = createNativeWrapper<RNTextInputProps>(RNTextInput);\n// eslint-disable-next-line @typescript-eslint/no-redeclare\nexport type TextInput = typeof TextInput & RNTextInput;\n\nexport const DrawerLayoutAndroid = createNativeWrapper<\n PropsWithChildren<RNDrawerLayoutAndroidProps>\n>(RNDrawerLayoutAndroid, { disallowInterruption: true });\n// eslint-disable-next-line @typescript-eslint/no-redeclare\nexport type DrawerLayoutAndroid = typeof DrawerLayoutAndroid &\n RNDrawerLayoutAndroid;\n\nexport const FlatList = React.forwardRef((props, ref) => {\n const refreshControlGestureRef = React.useRef<RefreshControl>(null);\n\n const { waitFor, refreshControl, ...rest } = props;\n\n const flatListProps = {};\n const scrollViewProps = {};\n for (const [propName, value] of Object.entries(rest)) {\n // https://github.com/microsoft/TypeScript/issues/26255\n if ((nativeViewProps as readonly string[]).includes(propName)) {\n // @ts-ignore - this function cannot have generic type so we have to ignore this error\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n scrollViewProps[propName] = value;\n } else {\n // @ts-ignore - this function cannot have generic type so we have to ignore this error\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n flatListProps[propName] = value;\n }\n }\n\n return (\n // @ts-ignore - this function cannot have generic type so we have to ignore this error\n <RNFlatList\n ref={ref}\n {...flatListProps}\n renderScrollComponent={(scrollProps) => (\n <ScrollView\n {...{\n ...scrollProps,\n ...scrollViewProps,\n waitFor: [...toArray(waitFor ?? []), refreshControlGestureRef],\n }}\n />\n )}\n // @ts-ignore we don't pass `refreshing` prop as we only want to override the ref\n refreshControl={\n refreshControl\n ? React.cloneElement(refreshControl, {\n // @ts-ignore for reasons unknown to me, `ref` doesn't exist on the type inferred by TS\n ref: refreshControlGestureRef,\n })\n : undefined\n }\n />\n );\n}) as <ItemT = any>(\n props: PropsWithChildren<\n Omit<RNFlatListProps<ItemT>, 'renderScrollComponent'> &\n RefAttributes<FlatList<ItemT>> &\n NativeViewGestureHandlerProps\n >,\n ref: ForwardedRef<FlatList<ItemT>>\n) => ReactElement | null;\n// eslint-disable-next-line @typescript-eslint/no-redeclare\nexport type FlatList<ItemT = any> = typeof FlatList & RNFlatList<ItemT>;\n"]}
|
@@ -1,75 +1,77 @@
|
|
1
|
+
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
2
|
+
|
1
3
|
import React, { useCallback, useMemo, useRef, useState } from 'react';
|
2
4
|
import { GestureObjects as Gesture } from '../../handlers/gestures/gestureObjects';
|
3
5
|
import { GestureDetector } from '../../handlers/gestures/GestureDetector';
|
4
|
-
import { Platform,
|
6
|
+
import { Platform, processColor } from 'react-native';
|
5
7
|
import NativeButton from '../GestureHandlerButton';
|
6
|
-
import { numberAsInset, gestureToPressableEvent, isTouchWithinInset, gestureTouchToPressableEvent, addInsets
|
8
|
+
import { numberAsInset, gestureToPressableEvent, isTouchWithinInset, gestureTouchToPressableEvent, addInsets } from './utils';
|
7
9
|
import { PressabilityDebugView } from '../../handlers/PressabilityDebugView';
|
10
|
+
import { INT32_MAX } from '../../utils';
|
8
11
|
const DEFAULT_LONG_PRESS_DURATION = 500;
|
9
12
|
export default function Pressable(props) {
|
10
|
-
var
|
11
|
-
|
12
|
-
const
|
13
|
+
var _android_ripple$color, _android_ripple$radiu;
|
14
|
+
|
15
|
+
const {
|
16
|
+
testOnly_pressed,
|
17
|
+
hitSlop,
|
18
|
+
pressRetentionOffset,
|
19
|
+
delayHoverIn,
|
20
|
+
onHoverIn,
|
21
|
+
delayHoverOut,
|
22
|
+
onHoverOut,
|
23
|
+
delayLongPress,
|
24
|
+
unstable_pressDelay,
|
25
|
+
onPress,
|
26
|
+
onPressIn,
|
27
|
+
onPressOut,
|
28
|
+
onLongPress,
|
29
|
+
style,
|
30
|
+
children,
|
31
|
+
android_disableSound,
|
32
|
+
android_ripple,
|
33
|
+
disabled,
|
34
|
+
...remainingProps
|
35
|
+
} = props;
|
36
|
+
const [pressedState, setPressedState] = useState(testOnly_pressed !== null && testOnly_pressed !== void 0 ? testOnly_pressed : false);
|
13
37
|
const pressableRef = useRef(null); // Disabled when onLongPress has been called
|
14
38
|
|
15
39
|
const isPressCallbackEnabled = useRef(true);
|
16
40
|
const hasPassedBoundsChecks = useRef(false);
|
17
41
|
const shouldPreventNativeEffects = useRef(false);
|
18
|
-
const normalizedHitSlop = useMemo(() => {
|
19
|
-
|
20
|
-
|
21
|
-
return typeof props.hitSlop === 'number' ? numberAsInset(props.hitSlop) : (_props$hitSlop = props.hitSlop) !== null && _props$hitSlop !== void 0 ? _props$hitSlop : {};
|
22
|
-
}, [props.hitSlop]);
|
23
|
-
const normalizedPressRetentionOffset = useMemo(() => {
|
24
|
-
var _props$pressRetention;
|
25
|
-
|
26
|
-
return typeof props.pressRetentionOffset === 'number' ? numberAsInset(props.pressRetentionOffset) : (_props$pressRetention = props.pressRetentionOffset) !== null && _props$pressRetention !== void 0 ? _props$pressRetention : {};
|
27
|
-
}, [props.pressRetentionOffset]);
|
42
|
+
const normalizedHitSlop = useMemo(() => typeof hitSlop === 'number' ? numberAsInset(hitSlop) : hitSlop !== null && hitSlop !== void 0 ? hitSlop : {}, [hitSlop]);
|
43
|
+
const normalizedPressRetentionOffset = useMemo(() => typeof pressRetentionOffset === 'number' ? numberAsInset(pressRetentionOffset) : pressRetentionOffset !== null && pressRetentionOffset !== void 0 ? pressRetentionOffset : {}, [pressRetentionOffset]);
|
28
44
|
const hoverInTimeout = useRef(null);
|
29
45
|
const hoverOutTimeout = useRef(null);
|
30
46
|
const hoverGesture = useMemo(() => Gesture.Hover().manualActivation(true) // Stops Hover from blocking Native gesture activation on web
|
31
47
|
.cancelsTouchesInView(false).onBegin(event => {
|
32
|
-
var _props$onHoverIn2;
|
33
|
-
|
34
48
|
if (hoverOutTimeout.current) {
|
35
49
|
clearTimeout(hoverOutTimeout.current);
|
36
50
|
}
|
37
51
|
|
38
|
-
if (
|
39
|
-
hoverInTimeout.current = setTimeout(() =>
|
40
|
-
var _props$onHoverIn;
|
41
|
-
|
42
|
-
return (_props$onHoverIn = props.onHoverIn) === null || _props$onHoverIn === void 0 ? void 0 : _props$onHoverIn.call(props, gestureToPressableEvent(event));
|
43
|
-
}, props.delayHoverIn);
|
52
|
+
if (delayHoverIn) {
|
53
|
+
hoverInTimeout.current = setTimeout(() => onHoverIn === null || onHoverIn === void 0 ? void 0 : onHoverIn(gestureToPressableEvent(event)), delayHoverIn);
|
44
54
|
return;
|
45
55
|
}
|
46
56
|
|
47
|
-
|
57
|
+
onHoverIn === null || onHoverIn === void 0 ? void 0 : onHoverIn(gestureToPressableEvent(event));
|
48
58
|
}).onFinalize(event => {
|
49
|
-
var _props$onHoverOut2;
|
50
|
-
|
51
59
|
if (hoverInTimeout.current) {
|
52
60
|
clearTimeout(hoverInTimeout.current);
|
53
61
|
}
|
54
62
|
|
55
|
-
if (
|
56
|
-
hoverOutTimeout.current = setTimeout(() =>
|
57
|
-
var _props$onHoverOut;
|
58
|
-
|
59
|
-
return (_props$onHoverOut = props.onHoverOut) === null || _props$onHoverOut === void 0 ? void 0 : _props$onHoverOut.call(props, gestureToPressableEvent(event));
|
60
|
-
}, props.delayHoverOut);
|
63
|
+
if (delayHoverOut) {
|
64
|
+
hoverOutTimeout.current = setTimeout(() => onHoverOut === null || onHoverOut === void 0 ? void 0 : onHoverOut(gestureToPressableEvent(event)), delayHoverOut);
|
61
65
|
return;
|
62
66
|
}
|
63
67
|
|
64
|
-
|
65
|
-
}), [
|
68
|
+
onHoverOut === null || onHoverOut === void 0 ? void 0 : onHoverOut(gestureToPressableEvent(event));
|
69
|
+
}), [delayHoverIn, delayHoverOut, onHoverIn, onHoverOut]);
|
66
70
|
const pressDelayTimeoutRef = useRef(null);
|
67
71
|
const isTouchPropagationAllowed = useRef(false); // iOS only: due to varying flow of gestures, events sometimes have to be saved for later use
|
68
72
|
|
69
73
|
const deferredEventPayload = useRef(null);
|
70
74
|
const pressInHandler = useCallback(event => {
|
71
|
-
var _props$onPressIn;
|
72
|
-
|
73
75
|
if (handlingOnTouchesDown.current) {
|
74
76
|
deferredEventPayload.current = event;
|
75
77
|
}
|
@@ -79,19 +81,17 @@ export default function Pressable(props) {
|
|
79
81
|
}
|
80
82
|
|
81
83
|
deferredEventPayload.current = null;
|
82
|
-
|
84
|
+
onPressIn === null || onPressIn === void 0 ? void 0 : onPressIn(event);
|
83
85
|
isPressCallbackEnabled.current = true;
|
84
86
|
pressDelayTimeoutRef.current = null;
|
85
87
|
setPressedState(true);
|
86
|
-
}, [
|
88
|
+
}, [onPressIn]);
|
87
89
|
const pressOutHandler = useCallback(event => {
|
88
|
-
var _props$onPressOut;
|
89
|
-
|
90
90
|
if (!hasPassedBoundsChecks.current || event.nativeEvent.touches.length > event.nativeEvent.changedTouches.length) {
|
91
91
|
return;
|
92
92
|
}
|
93
93
|
|
94
|
-
if (
|
94
|
+
if (unstable_pressDelay && pressDelayTimeoutRef.current !== null) {
|
95
95
|
// When delay is preemptively finished by lifting touches,
|
96
96
|
// we want to immediately activate it's effects - pressInHandler,
|
97
97
|
// even though we are located at the pressOutHandler
|
@@ -100,18 +100,14 @@ export default function Pressable(props) {
|
|
100
100
|
}
|
101
101
|
|
102
102
|
if (deferredEventPayload.current) {
|
103
|
-
|
104
|
-
|
105
|
-
(_props$onPressIn2 = props.onPressIn) === null || _props$onPressIn2 === void 0 ? void 0 : _props$onPressIn2.call(props, deferredEventPayload.current);
|
103
|
+
onPressIn === null || onPressIn === void 0 ? void 0 : onPressIn(deferredEventPayload.current);
|
106
104
|
deferredEventPayload.current = null;
|
107
105
|
}
|
108
106
|
|
109
|
-
|
107
|
+
onPressOut === null || onPressOut === void 0 ? void 0 : onPressOut(event);
|
110
108
|
|
111
109
|
if (isPressCallbackEnabled.current) {
|
112
|
-
|
113
|
-
|
114
|
-
(_props$onPress = props.onPress) === null || _props$onPress === void 0 ? void 0 : _props$onPress.call(props, event);
|
110
|
+
onPress === null || onPress === void 0 ? void 0 : onPress(event);
|
115
111
|
}
|
116
112
|
|
117
113
|
if (longPressTimeoutRef.current) {
|
@@ -123,7 +119,7 @@ export default function Pressable(props) {
|
|
123
119
|
hasPassedBoundsChecks.current = false;
|
124
120
|
isPressCallbackEnabled.current = true;
|
125
121
|
setPressedState(false);
|
126
|
-
}, [pressInHandler,
|
122
|
+
}, [onPress, onPressIn, onPressOut, pressInHandler, unstable_pressDelay]);
|
127
123
|
const handlingOnTouchesDown = useRef(false);
|
128
124
|
const onEndHandlingTouchesDown = useRef(null);
|
129
125
|
const cancelledMidPress = useRef(false);
|
@@ -133,9 +129,7 @@ export default function Pressable(props) {
|
|
133
129
|
}
|
134
130
|
|
135
131
|
if (hasPassedBoundsChecks.current) {
|
136
|
-
|
137
|
-
|
138
|
-
(_props$onLongPress = props.onLongPress) === null || _props$onLongPress === void 0 ? void 0 : _props$onLongPress.call(props, gestureTouchToPressableEvent(event));
|
132
|
+
onLongPress === null || onLongPress === void 0 ? void 0 : onLongPress(gestureTouchToPressableEvent(event));
|
139
133
|
isPressCallbackEnabled.current = false;
|
140
134
|
}
|
141
135
|
|
@@ -143,11 +137,11 @@ export default function Pressable(props) {
|
|
143
137
|
clearTimeout(longPressTimeoutRef.current);
|
144
138
|
longPressTimeoutRef.current = null;
|
145
139
|
}
|
146
|
-
}, [
|
140
|
+
}, [onLongPress]);
|
147
141
|
const longPressTimeoutRef = useRef(null);
|
148
|
-
const longPressMinDuration = (
|
149
|
-
const pressAndTouchGesture = useMemo(() => Gesture.LongPress().minDuration(
|
150
|
-
.maxDistance(
|
142
|
+
const longPressMinDuration = (delayLongPress !== null && delayLongPress !== void 0 ? delayLongPress : DEFAULT_LONG_PRESS_DURATION) + (unstable_pressDelay !== null && unstable_pressDelay !== void 0 ? unstable_pressDelay : 0);
|
143
|
+
const pressAndTouchGesture = useMemo(() => Gesture.LongPress().minDuration(INT32_MAX) // Stops long press from blocking native gesture
|
144
|
+
.maxDistance(INT32_MAX) // Stops long press from cancelling after set distance
|
151
145
|
.cancelsTouchesInView(false).onTouchesDown(event => {
|
152
146
|
var _pressableRef$current;
|
153
147
|
|
@@ -172,10 +166,10 @@ export default function Pressable(props) {
|
|
172
166
|
longPressTimeoutRef.current = setTimeout(() => activateLongPress(event), longPressMinDuration);
|
173
167
|
}
|
174
168
|
|
175
|
-
if (
|
169
|
+
if (unstable_pressDelay) {
|
176
170
|
pressDelayTimeoutRef.current = setTimeout(() => {
|
177
171
|
pressInHandler(gestureTouchToPressableEvent(event));
|
178
|
-
},
|
172
|
+
}, unstable_pressDelay);
|
179
173
|
} else {
|
180
174
|
pressInHandler(gestureTouchToPressableEvent(event));
|
181
175
|
}
|
@@ -214,7 +208,7 @@ export default function Pressable(props) {
|
|
214
208
|
}
|
215
209
|
|
216
210
|
pressOutHandler(gestureTouchToPressableEvent(event));
|
217
|
-
}), [activateLongPress, longPressMinDuration, normalizedHitSlop, pressInHandler, pressOutHandler,
|
211
|
+
}), [activateLongPress, longPressMinDuration, normalizedHitSlop, pressInHandler, pressOutHandler, unstable_pressDelay]); // RNButton is placed inside ButtonGesture to enable Android's ripple and to capture non-propagating events
|
218
212
|
|
219
213
|
const buttonGesture = useMemo(() => Gesture.Native().onBegin(() => {
|
220
214
|
// Android sets BEGAN state on press down
|
@@ -258,7 +252,7 @@ export default function Pressable(props) {
|
|
258
252
|
isTouchPropagationAllowed.current = true;
|
259
253
|
}), [pressInHandler, pressOutHandler]);
|
260
254
|
const appliedHitSlop = addInsets(normalizedHitSlop, normalizedPressRetentionOffset);
|
261
|
-
const isPressableEnabled =
|
255
|
+
const isPressableEnabled = disabled !== true;
|
262
256
|
const gestures = [pressAndTouchGesture, hoverGesture, buttonGesture];
|
263
257
|
|
264
258
|
for (const gesture of gestures) {
|
@@ -275,35 +269,30 @@ export default function Pressable(props) {
|
|
275
269
|
|
276
270
|
buttonGesture.hitSlop(normalizedHitSlop);
|
277
271
|
const gesture = Gesture.Simultaneous(...gestures);
|
278
|
-
const defaultRippleColor =
|
272
|
+
const defaultRippleColor = android_ripple ? undefined : 'transparent'; // `cursor: 'pointer'` on `RNButton` crashes iOS
|
279
273
|
|
280
274
|
const pointerStyle = Platform.OS === 'web' ? {
|
281
275
|
cursor: 'pointer'
|
282
276
|
} : {};
|
283
|
-
const styleProp = typeof
|
277
|
+
const styleProp = typeof style === 'function' ? style({
|
284
278
|
pressed: pressedState
|
285
|
-
}) :
|
286
|
-
const childrenProp = typeof
|
279
|
+
}) : style;
|
280
|
+
const childrenProp = typeof children === 'function' ? children({
|
287
281
|
pressed: pressedState
|
288
|
-
}) :
|
289
|
-
|
290
|
-
const [innerStyles, outerStyles] = splitStyles(flattenedStyles);
|
291
|
-
return /*#__PURE__*/React.createElement(View, {
|
292
|
-
style: outerStyles
|
293
|
-
}, /*#__PURE__*/React.createElement(GestureDetector, {
|
282
|
+
}) : children;
|
283
|
+
return /*#__PURE__*/React.createElement(GestureDetector, {
|
294
284
|
gesture: gesture
|
295
|
-
}, /*#__PURE__*/React.createElement(NativeButton, {
|
285
|
+
}, /*#__PURE__*/React.createElement(NativeButton, _extends({}, remainingProps, {
|
296
286
|
ref: pressableRef,
|
297
|
-
testID: props.testID,
|
298
287
|
hitSlop: appliedHitSlop,
|
299
288
|
enabled: isPressableEnabled,
|
300
|
-
touchSoundDisabled:
|
301
|
-
rippleColor: processColor((
|
302
|
-
rippleRadius: (
|
303
|
-
style: [
|
304
|
-
}, childrenProp, __DEV__ ? /*#__PURE__*/React.createElement(PressabilityDebugView, {
|
289
|
+
touchSoundDisabled: android_disableSound !== null && android_disableSound !== void 0 ? android_disableSound : undefined,
|
290
|
+
rippleColor: processColor((_android_ripple$color = android_ripple === null || android_ripple === void 0 ? void 0 : android_ripple.color) !== null && _android_ripple$color !== void 0 ? _android_ripple$color : defaultRippleColor),
|
291
|
+
rippleRadius: (_android_ripple$radiu = android_ripple === null || android_ripple === void 0 ? void 0 : android_ripple.radius) !== null && _android_ripple$radiu !== void 0 ? _android_ripple$radiu : undefined,
|
292
|
+
style: [pointerStyle, styleProp]
|
293
|
+
}), childrenProp, __DEV__ ? /*#__PURE__*/React.createElement(PressabilityDebugView, {
|
305
294
|
color: "red",
|
306
295
|
hitSlop: normalizedHitSlop
|
307
|
-
}) : null))
|
296
|
+
}) : null));
|
308
297
|
}
|
309
298
|
//# sourceMappingURL=Pressable.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["Pressable.tsx"],"names":["React","useCallback","useMemo","useRef","useState","GestureObjects","Gesture","GestureDetector","Platform","View","processColor","StyleSheet","NativeButton","numberAsInset","gestureToPressableEvent","isTouchWithinInset","gestureTouchToPressableEvent","addInsets","splitStyles","PressabilityDebugView","DEFAULT_LONG_PRESS_DURATION","Pressable","props","pressedState","setPressedState","testOnly_pressed","pressableRef","isPressCallbackEnabled","hasPassedBoundsChecks","shouldPreventNativeEffects","normalizedHitSlop","hitSlop","normalizedPressRetentionOffset","pressRetentionOffset","hoverInTimeout","hoverOutTimeout","hoverGesture","Hover","manualActivation","cancelsTouchesInView","onBegin","event","current","clearTimeout","delayHoverIn","setTimeout","onHoverIn","onFinalize","delayHoverOut","onHoverOut","pressDelayTimeoutRef","isTouchPropagationAllowed","deferredEventPayload","pressInHandler","handlingOnTouchesDown","onPressIn","pressOutHandler","nativeEvent","touches","length","changedTouches","unstable_pressDelay","onPressOut","onPress","longPressTimeoutRef","onEndHandlingTouchesDown","cancelledMidPress","activateLongPress","onLongPress","longPressMinDuration","delayLongPress","pressAndTouchGesture","LongPress","minDuration","Number","MAX_SAFE_INTEGER","maxDistance","onTouchesDown","measure","_x","_y","width","height","at","onTouchesUp","onTouchesCancelled","allTouches","buttonGesture","Native","OS","onStart","appliedHitSlop","isPressableEnabled","disabled","gestures","gesture","enabled","runOnJS","shouldCancelWhenOutside","Simultaneous","defaultRippleColor","android_ripple","undefined","pointerStyle","cursor","styleProp","style","pressed","childrenProp","children","flattenedStyles","flatten","innerStyles","outerStyles","testID","android_disableSound","color","radius","absoluteFill","__DEV__"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,WAAhB,EAA6BC,OAA7B,EAAsCC,MAAtC,EAA8CC,QAA9C,QAA8D,OAA9D;AACA,SAASC,cAAc,IAAIC,OAA3B,QAA0C,wCAA1C;AACA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K,EAAE,CAAC3F,UAAU,CAAC2G,YAAZ,EAA0Bf,YAA1B,EAAwCS,WAAxC;AAVT,KAWGJ,YAXH,EAYGW,OAAO,gBACN,oBAAC,qBAAD;AAAuB,IAAA,KAAK,EAAC,KAA7B;AAAmC,IAAA,OAAO,EAAEzF;AAA5C,IADM,GAEJ,IAdN,CADF,CADF,CADF;AAsBD","sourcesContent":["import React, { useCallback, useMemo, useRef, useState } from 'react';\nimport { GestureObjects as Gesture } from '../../handlers/gestures/gestureObjects';\nimport { GestureDetector } from '../../handlers/gestures/GestureDetector';\nimport { PressableEvent, PressableProps } from './PressableProps';\nimport {\n Insets,\n Platform,\n StyleProp,\n View,\n ViewStyle,\n processColor,\n StyleSheet,\n} from 'react-native';\nimport NativeButton from '../GestureHandlerButton';\nimport {\n numberAsInset,\n gestureToPressableEvent,\n isTouchWithinInset,\n gestureTouchToPressableEvent,\n addInsets,\n splitStyles,\n} from './utils';\nimport { PressabilityDebugView } from '../../handlers/PressabilityDebugView';\nimport { GestureTouchEvent } from '../../handlers/gestureHandlerCommon';\n\nconst DEFAULT_LONG_PRESS_DURATION = 500;\n\nexport default function Pressable(props: PressableProps) {\n const [pressedState, setPressedState] = useState(\n props.testOnly_pressed ?? false\n );\n\n const pressableRef = useRef<View>(null);\n\n // Disabled when onLongPress has been called\n const isPressCallbackEnabled = useRef<boolean>(true);\n const hasPassedBoundsChecks = useRef<boolean>(false);\n const shouldPreventNativeEffects = useRef<boolean>(false);\n\n const normalizedHitSlop: Insets = useMemo(\n () =>\n typeof props.hitSlop === 'number'\n ? numberAsInset(props.hitSlop)\n : props.hitSlop ?? {},\n [props.hitSlop]\n );\n\n const normalizedPressRetentionOffset: Insets = useMemo(\n () =>\n typeof props.pressRetentionOffset === 'number'\n ? numberAsInset(props.pressRetentionOffset)\n : props.pressRetentionOffset ?? {},\n [props.pressRetentionOffset]\n );\n\n const hoverInTimeout = useRef<number | null>(null);\n const hoverOutTimeout = useRef<number | null>(null);\n\n const hoverGesture = useMemo(\n () =>\n Gesture.Hover()\n .manualActivation(true) // Stops Hover from blocking Native gesture activation on web\n .cancelsTouchesInView(false)\n .onBegin((event) => {\n if (hoverOutTimeout.current) {\n clearTimeout(hoverOutTimeout.current);\n }\n if (props.delayHoverIn) {\n hoverInTimeout.current = setTimeout(\n () => props.onHoverIn?.(gestureToPressableEvent(event)),\n props.delayHoverIn\n );\n return;\n }\n props.onHoverIn?.(gestureToPressableEvent(event));\n })\n .onFinalize((event) => {\n if (hoverInTimeout.current) {\n clearTimeout(hoverInTimeout.current);\n }\n if (props.delayHoverOut) {\n hoverOutTimeout.current = setTimeout(\n () => props.onHoverOut?.(gestureToPressableEvent(event)),\n props.delayHoverOut\n );\n return;\n }\n props.onHoverOut?.(gestureToPressableEvent(event));\n }),\n [props]\n );\n\n const pressDelayTimeoutRef = useRef<number | null>(null);\n const isTouchPropagationAllowed = useRef<boolean>(false);\n\n // iOS only: due to varying flow of gestures, events sometimes have to be saved for later use\n const deferredEventPayload = useRef<PressableEvent | null>(null);\n\n const pressInHandler = useCallback(\n (event: PressableEvent) => {\n if (handlingOnTouchesDown.current) {\n deferredEventPayload.current = event;\n }\n\n if (!isTouchPropagationAllowed.current) {\n return;\n }\n\n deferredEventPayload.current = null;\n\n props.onPressIn?.(event);\n isPressCallbackEnabled.current = true;\n pressDelayTimeoutRef.current = null;\n setPressedState(true);\n },\n [props]\n );\n\n const pressOutHandler = useCallback(\n (event: PressableEvent) => {\n if (\n !hasPassedBoundsChecks.current ||\n event.nativeEvent.touches.length >\n event.nativeEvent.changedTouches.length\n ) {\n return;\n }\n\n if (props.unstable_pressDelay && pressDelayTimeoutRef.current !== null) {\n // When delay is preemptively finished by lifting touches,\n // we want to immediately activate it's effects - pressInHandler,\n // even though we are located at the pressOutHandler\n clearTimeout(pressDelayTimeoutRef.current);\n pressInHandler(event);\n }\n\n if (deferredEventPayload.current) {\n props.onPressIn?.(deferredEventPayload.current);\n deferredEventPayload.current = null;\n }\n\n props.onPressOut?.(event);\n\n if (isPressCallbackEnabled.current) {\n props.onPress?.(event);\n }\n\n if (longPressTimeoutRef.current) {\n clearTimeout(longPressTimeoutRef.current);\n longPressTimeoutRef.current = null;\n }\n\n isTouchPropagationAllowed.current = false;\n hasPassedBoundsChecks.current = false;\n isPressCallbackEnabled.current = true;\n setPressedState(false);\n },\n [pressInHandler, props]\n );\n\n const handlingOnTouchesDown = useRef<boolean>(false);\n const onEndHandlingTouchesDown = useRef<(() => void) | null>(null);\n const cancelledMidPress = useRef<boolean>(false);\n\n const activateLongPress = useCallback(\n (event: GestureTouchEvent) => {\n if (!isTouchPropagationAllowed.current) {\n return;\n }\n\n if (hasPassedBoundsChecks.current) {\n props.onLongPress?.(gestureTouchToPressableEvent(event));\n isPressCallbackEnabled.current = false;\n }\n\n if (longPressTimeoutRef.current) {\n clearTimeout(longPressTimeoutRef.current);\n longPressTimeoutRef.current = null;\n }\n },\n [props]\n );\n\n const longPressTimeoutRef = useRef<number | null>(null);\n const longPressMinDuration =\n (props.delayLongPress ?? DEFAULT_LONG_PRESS_DURATION) +\n (props.unstable_pressDelay ?? 0);\n\n const pressAndTouchGesture = useMemo(\n () =>\n Gesture.LongPress()\n .minDuration(Number.MAX_SAFE_INTEGER) // Stops long press from blocking native gesture\n .maxDistance(Number.MAX_SAFE_INTEGER) // Stops long press from cancelling after set distance\n .cancelsTouchesInView(false)\n .onTouchesDown((event) => {\n handlingOnTouchesDown.current = true;\n pressableRef.current?.measure((_x, _y, width, height) => {\n if (\n !isTouchWithinInset(\n {\n width,\n height,\n },\n normalizedHitSlop,\n event.changedTouches.at(-1)\n ) ||\n hasPassedBoundsChecks.current ||\n cancelledMidPress.current\n ) {\n cancelledMidPress.current = false;\n onEndHandlingTouchesDown.current = null;\n handlingOnTouchesDown.current = false;\n return;\n }\n\n hasPassedBoundsChecks.current = true;\n\n // In case of multiple touches, the first one starts long press gesture\n if (longPressTimeoutRef.current === null) {\n // Start long press gesture timer\n longPressTimeoutRef.current = setTimeout(\n () => activateLongPress(event),\n longPressMinDuration\n );\n }\n\n if (props.unstable_pressDelay) {\n pressDelayTimeoutRef.current = setTimeout(() => {\n pressInHandler(gestureTouchToPressableEvent(event));\n }, props.unstable_pressDelay);\n } else {\n pressInHandler(gestureTouchToPressableEvent(event));\n }\n\n onEndHandlingTouchesDown.current?.();\n onEndHandlingTouchesDown.current = null;\n handlingOnTouchesDown.current = false;\n });\n })\n .onTouchesUp((event) => {\n if (handlingOnTouchesDown.current) {\n onEndHandlingTouchesDown.current = () =>\n pressOutHandler(gestureTouchToPressableEvent(event));\n return;\n }\n // On iOS, short taps will make LongPress gesture call onTouchesUp before Native gesture calls onStart\n // This variable ensures that onStart isn't detected as the first gesture since Pressable is pressed.\n if (deferredEventPayload.current !== null) {\n shouldPreventNativeEffects.current = true;\n }\n pressOutHandler(gestureTouchToPressableEvent(event));\n })\n .onTouchesCancelled((event) => {\n isPressCallbackEnabled.current = false;\n\n if (handlingOnTouchesDown.current) {\n cancelledMidPress.current = true;\n onEndHandlingTouchesDown.current = () =>\n pressOutHandler(gestureTouchToPressableEvent(event));\n return;\n }\n\n if (\n !hasPassedBoundsChecks.current ||\n event.allTouches.length > event.changedTouches.length\n ) {\n return;\n }\n\n pressOutHandler(gestureTouchToPressableEvent(event));\n }),\n [\n activateLongPress,\n longPressMinDuration,\n normalizedHitSlop,\n pressInHandler,\n pressOutHandler,\n props.unstable_pressDelay,\n ]\n );\n\n // RNButton is placed inside ButtonGesture to enable Android's ripple and to capture non-propagating events\n const buttonGesture = useMemo(\n () =>\n Gesture.Native()\n .onBegin(() => {\n // Android sets BEGAN state on press down\n if (Platform.OS === 'android') {\n isTouchPropagationAllowed.current = true;\n }\n })\n .onStart(() => {\n if (Platform.OS === 'web') {\n isTouchPropagationAllowed.current = true;\n }\n\n // iOS sets ACTIVE state on press down\n if (Platform.OS !== 'ios') {\n return;\n }\n\n if (deferredEventPayload.current) {\n isTouchPropagationAllowed.current = true;\n\n if (hasPassedBoundsChecks.current) {\n pressInHandler(deferredEventPayload.current);\n deferredEventPayload.current = null;\n } else {\n pressOutHandler(deferredEventPayload.current);\n isTouchPropagationAllowed.current = false;\n }\n\n return;\n }\n\n if (hasPassedBoundsChecks.current) {\n isTouchPropagationAllowed.current = true;\n return;\n }\n\n if (shouldPreventNativeEffects.current) {\n shouldPreventNativeEffects.current = false;\n return;\n }\n\n isTouchPropagationAllowed.current = true;\n }),\n [pressInHandler, pressOutHandler]\n );\n\n const appliedHitSlop = addInsets(\n normalizedHitSlop,\n normalizedPressRetentionOffset\n );\n\n const isPressableEnabled = props.disabled !== true;\n\n const gestures = [pressAndTouchGesture, hoverGesture, buttonGesture];\n\n for (const gesture of gestures) {\n gesture.enabled(isPressableEnabled);\n gesture.runOnJS(true);\n gesture.hitSlop(appliedHitSlop);\n gesture.shouldCancelWhenOutside(false);\n\n if (Platform.OS !== 'web') {\n gesture.shouldCancelWhenOutside(true);\n }\n }\n\n // Uses different hitSlop, to activate on hitSlop area instead of pressRetentionOffset area\n buttonGesture.hitSlop(normalizedHitSlop);\n\n const gesture = Gesture.Simultaneous(...gestures);\n\n const defaultRippleColor = props.android_ripple ? undefined : 'transparent';\n\n // `cursor: 'pointer'` on `RNButton` crashes iOS\n const pointerStyle: StyleProp<ViewStyle> =\n Platform.OS === 'web' ? { cursor: 'pointer' } : {};\n\n const styleProp =\n typeof props.style === 'function'\n ? props.style({ pressed: pressedState })\n : props.style;\n\n const childrenProp =\n typeof props.children === 'function'\n ? props.children({ pressed: pressedState })\n : props.children;\n\n const flattenedStyles = StyleSheet.flatten(styleProp ?? {});\n\n const [innerStyles, outerStyles] = splitStyles(flattenedStyles);\n\n return (\n <View style={outerStyles}>\n <GestureDetector gesture={gesture}>\n <NativeButton\n ref={pressableRef}\n testID={props.testID}\n hitSlop={appliedHitSlop}\n enabled={isPressableEnabled}\n touchSoundDisabled={props.android_disableSound ?? undefined}\n rippleColor={processColor(\n props.android_ripple?.color ?? defaultRippleColor\n )}\n rippleRadius={props.android_ripple?.radius ?? undefined}\n style={[StyleSheet.absoluteFill, pointerStyle, innerStyles]}>\n {childrenProp}\n {__DEV__ ? (\n <PressabilityDebugView color=\"red\" hitSlop={normalizedHitSlop} />\n ) : null}\n </NativeButton>\n </GestureDetector>\n </View>\n );\n}\n"]}
|
1
|
+
{"version":3,"sources":["Pressable.tsx"],"names":["React","useCallback","useMemo","useRef","useState","GestureObjects","Gesture","GestureDetector","Platform","processColor","NativeButton","numberAsInset","gestureToPressableEvent","isTouchWithinInset","gestureTouchToPressableEvent","addInsets","PressabilityDebugView","INT32_MAX","DEFAULT_LONG_PRESS_DURATION","Pressable","props","testOnly_pressed","hitSlop","pressRetentionOffset","delayHoverIn","onHoverIn","delayHoverOut","onHoverOut","delayLongPress","unstable_pressDelay","onPress","onPressIn","onPressOut","onLongPress","style","children","android_disableSound","android_ripple","disabled","remainingProps","pressedState","setPressedState","pressableRef","isPressCallbackEnabled","hasPassedBoundsChecks","shouldPreventNativeEffects","normalizedHitSlop","normalizedPressRetentionOffset","hoverInTimeout","hoverOutTimeout","hoverGesture","Hover","manualActivation","cancelsTouchesInView","onBegin","event","current","clearTimeout","setTimeout","onFinalize","pressDelayTimeoutRef","isTouchPropagationAllowed","deferredEventPayload","pressInHandler","handlingOnTouchesDown","pressOutHandler","nativeEvent","touches","length","changedTouches","longPressTimeoutRef","onEndHandlingTouchesDown","cancelledMidPress","activateLongPress","longPressMinDuration","pressAndTouchGesture","LongPress","minDuration","maxDistance","onTouchesDown","measure","_x","_y","width","height","at","onTouchesUp","onTouchesCancelled","allTouches","buttonGesture","Native","OS","onStart","appliedHitSlop","isPressableEnabled","gestures","gesture","enabled","runOnJS","shouldCancelWhenOutside","Simultaneous","defaultRippleColor","undefined","pointerStyle","cursor","styleProp","pressed","childrenProp","color","radius","__DEV__"],"mappings":";;AAAA,OAAOA,KAAP,IAAgBC,WAAhB,EAA6BC,OAA7B,EAAsCC,MAAtC,EAA8CC,QAA9C,QAA8D,OAA9D;AACA,SAAS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H,EAUGG,OAAO,gBACN,oBAAC,qBAAD;AAAuB,IAAA,KAAK,EAAC,KAA7B;AAAmC,IAAA,OAAO,EAAEhE;AAA5C,IADM,GAEJ,IAZN,CADF,CADF;AAkBD","sourcesContent":["import React, { useCallback, useMemo, useRef, useState } from 'react';\nimport { GestureObjects as Gesture } from '../../handlers/gestures/gestureObjects';\nimport { GestureDetector } from '../../handlers/gestures/GestureDetector';\nimport { PressableEvent, PressableProps } from './PressableProps';\nimport {\n Insets,\n Platform,\n StyleProp,\n View,\n ViewStyle,\n processColor,\n} from 'react-native';\nimport NativeButton from '../GestureHandlerButton';\nimport {\n numberAsInset,\n gestureToPressableEvent,\n isTouchWithinInset,\n gestureTouchToPressableEvent,\n addInsets,\n} from './utils';\nimport { PressabilityDebugView } from '../../handlers/PressabilityDebugView';\nimport { GestureTouchEvent } from '../../handlers/gestureHandlerCommon';\nimport { INT32_MAX } from '../../utils';\n\nconst DEFAULT_LONG_PRESS_DURATION = 500;\n\nexport default function Pressable(props: PressableProps) {\n const {\n testOnly_pressed,\n hitSlop,\n pressRetentionOffset,\n delayHoverIn,\n onHoverIn,\n delayHoverOut,\n onHoverOut,\n delayLongPress,\n unstable_pressDelay,\n onPress,\n onPressIn,\n onPressOut,\n onLongPress,\n style,\n children,\n android_disableSound,\n android_ripple,\n disabled,\n ...remainingProps\n } = props;\n\n const [pressedState, setPressedState] = useState(testOnly_pressed ?? false);\n\n const pressableRef = useRef<View>(null);\n\n // Disabled when onLongPress has been called\n const isPressCallbackEnabled = useRef<boolean>(true);\n const hasPassedBoundsChecks = useRef<boolean>(false);\n const shouldPreventNativeEffects = useRef<boolean>(false);\n\n const normalizedHitSlop: Insets = useMemo(\n () =>\n typeof hitSlop === 'number' ? numberAsInset(hitSlop) : hitSlop ?? {},\n [hitSlop]\n );\n\n const normalizedPressRetentionOffset: Insets = useMemo(\n () =>\n typeof pressRetentionOffset === 'number'\n ? numberAsInset(pressRetentionOffset)\n : pressRetentionOffset ?? {},\n [pressRetentionOffset]\n );\n\n const hoverInTimeout = useRef<number | null>(null);\n const hoverOutTimeout = useRef<number | null>(null);\n\n const hoverGesture = useMemo(\n () =>\n Gesture.Hover()\n .manualActivation(true) // Stops Hover from blocking Native gesture activation on web\n .cancelsTouchesInView(false)\n .onBegin((event) => {\n if (hoverOutTimeout.current) {\n clearTimeout(hoverOutTimeout.current);\n }\n if (delayHoverIn) {\n hoverInTimeout.current = setTimeout(\n () => onHoverIn?.(gestureToPressableEvent(event)),\n delayHoverIn\n );\n return;\n }\n onHoverIn?.(gestureToPressableEvent(event));\n })\n .onFinalize((event) => {\n if (hoverInTimeout.current) {\n clearTimeout(hoverInTimeout.current);\n }\n if (delayHoverOut) {\n hoverOutTimeout.current = setTimeout(\n () => onHoverOut?.(gestureToPressableEvent(event)),\n delayHoverOut\n );\n return;\n }\n onHoverOut?.(gestureToPressableEvent(event));\n }),\n [delayHoverIn, delayHoverOut, onHoverIn, onHoverOut]\n );\n\n const pressDelayTimeoutRef = useRef<number | null>(null);\n const isTouchPropagationAllowed = useRef<boolean>(false);\n\n // iOS only: due to varying flow of gestures, events sometimes have to be saved for later use\n const deferredEventPayload = useRef<PressableEvent | null>(null);\n\n const pressInHandler = useCallback(\n (event: PressableEvent) => {\n if (handlingOnTouchesDown.current) {\n deferredEventPayload.current = event;\n }\n\n if (!isTouchPropagationAllowed.current) {\n return;\n }\n\n deferredEventPayload.current = null;\n\n onPressIn?.(event);\n isPressCallbackEnabled.current = true;\n pressDelayTimeoutRef.current = null;\n setPressedState(true);\n },\n [onPressIn]\n );\n\n const pressOutHandler = useCallback(\n (event: PressableEvent) => {\n if (\n !hasPassedBoundsChecks.current ||\n event.nativeEvent.touches.length >\n event.nativeEvent.changedTouches.length\n ) {\n return;\n }\n\n if (unstable_pressDelay && pressDelayTimeoutRef.current !== null) {\n // When delay is preemptively finished by lifting touches,\n // we want to immediately activate it's effects - pressInHandler,\n // even though we are located at the pressOutHandler\n clearTimeout(pressDelayTimeoutRef.current);\n pressInHandler(event);\n }\n\n if (deferredEventPayload.current) {\n onPressIn?.(deferredEventPayload.current);\n deferredEventPayload.current = null;\n }\n\n onPressOut?.(event);\n\n if (isPressCallbackEnabled.current) {\n onPress?.(event);\n }\n\n if (longPressTimeoutRef.current) {\n clearTimeout(longPressTimeoutRef.current);\n longPressTimeoutRef.current = null;\n }\n\n isTouchPropagationAllowed.current = false;\n hasPassedBoundsChecks.current = false;\n isPressCallbackEnabled.current = true;\n setPressedState(false);\n },\n [onPress, onPressIn, onPressOut, pressInHandler, unstable_pressDelay]\n );\n\n const handlingOnTouchesDown = useRef<boolean>(false);\n const onEndHandlingTouchesDown = useRef<(() => void) | null>(null);\n const cancelledMidPress = useRef<boolean>(false);\n\n const activateLongPress = useCallback(\n (event: GestureTouchEvent) => {\n if (!isTouchPropagationAllowed.current) {\n return;\n }\n\n if (hasPassedBoundsChecks.current) {\n onLongPress?.(gestureTouchToPressableEvent(event));\n isPressCallbackEnabled.current = false;\n }\n\n if (longPressTimeoutRef.current) {\n clearTimeout(longPressTimeoutRef.current);\n longPressTimeoutRef.current = null;\n }\n },\n [onLongPress]\n );\n\n const longPressTimeoutRef = useRef<number | null>(null);\n const longPressMinDuration =\n (delayLongPress ?? DEFAULT_LONG_PRESS_DURATION) +\n (unstable_pressDelay ?? 0);\n\n const pressAndTouchGesture = useMemo(\n () =>\n Gesture.LongPress()\n .minDuration(INT32_MAX) // Stops long press from blocking native gesture\n .maxDistance(INT32_MAX) // Stops long press from cancelling after set distance\n .cancelsTouchesInView(false)\n .onTouchesDown((event) => {\n handlingOnTouchesDown.current = true;\n pressableRef.current?.measure((_x, _y, width, height) => {\n if (\n !isTouchWithinInset(\n {\n width,\n height,\n },\n normalizedHitSlop,\n event.changedTouches.at(-1)\n ) ||\n hasPassedBoundsChecks.current ||\n cancelledMidPress.current\n ) {\n cancelledMidPress.current = false;\n onEndHandlingTouchesDown.current = null;\n handlingOnTouchesDown.current = false;\n return;\n }\n\n hasPassedBoundsChecks.current = true;\n\n // In case of multiple touches, the first one starts long press gesture\n if (longPressTimeoutRef.current === null) {\n // Start long press gesture timer\n longPressTimeoutRef.current = setTimeout(\n () => activateLongPress(event),\n longPressMinDuration\n );\n }\n\n if (unstable_pressDelay) {\n pressDelayTimeoutRef.current = setTimeout(() => {\n pressInHandler(gestureTouchToPressableEvent(event));\n }, unstable_pressDelay);\n } else {\n pressInHandler(gestureTouchToPressableEvent(event));\n }\n\n onEndHandlingTouchesDown.current?.();\n onEndHandlingTouchesDown.current = null;\n handlingOnTouchesDown.current = false;\n });\n })\n .onTouchesUp((event) => {\n if (handlingOnTouchesDown.current) {\n onEndHandlingTouchesDown.current = () =>\n pressOutHandler(gestureTouchToPressableEvent(event));\n return;\n }\n // On iOS, short taps will make LongPress gesture call onTouchesUp before Native gesture calls onStart\n // This variable ensures that onStart isn't detected as the first gesture since Pressable is pressed.\n if (deferredEventPayload.current !== null) {\n shouldPreventNativeEffects.current = true;\n }\n pressOutHandler(gestureTouchToPressableEvent(event));\n })\n .onTouchesCancelled((event) => {\n isPressCallbackEnabled.current = false;\n\n if (handlingOnTouchesDown.current) {\n cancelledMidPress.current = true;\n onEndHandlingTouchesDown.current = () =>\n pressOutHandler(gestureTouchToPressableEvent(event));\n return;\n }\n\n if (\n !hasPassedBoundsChecks.current ||\n event.allTouches.length > event.changedTouches.length\n ) {\n return;\n }\n\n pressOutHandler(gestureTouchToPressableEvent(event));\n }),\n [\n activateLongPress,\n longPressMinDuration,\n normalizedHitSlop,\n pressInHandler,\n pressOutHandler,\n unstable_pressDelay,\n ]\n );\n\n // RNButton is placed inside ButtonGesture to enable Android's ripple and to capture non-propagating events\n const buttonGesture = useMemo(\n () =>\n Gesture.Native()\n .onBegin(() => {\n // Android sets BEGAN state on press down\n if (Platform.OS === 'android') {\n isTouchPropagationAllowed.current = true;\n }\n })\n .onStart(() => {\n if (Platform.OS === 'web') {\n isTouchPropagationAllowed.current = true;\n }\n\n // iOS sets ACTIVE state on press down\n if (Platform.OS !== 'ios') {\n return;\n }\n\n if (deferredEventPayload.current) {\n isTouchPropagationAllowed.current = true;\n\n if (hasPassedBoundsChecks.current) {\n pressInHandler(deferredEventPayload.current);\n deferredEventPayload.current = null;\n } else {\n pressOutHandler(deferredEventPayload.current);\n isTouchPropagationAllowed.current = false;\n }\n\n return;\n }\n\n if (hasPassedBoundsChecks.current) {\n isTouchPropagationAllowed.current = true;\n return;\n }\n\n if (shouldPreventNativeEffects.current) {\n shouldPreventNativeEffects.current = false;\n return;\n }\n\n isTouchPropagationAllowed.current = true;\n }),\n [pressInHandler, pressOutHandler]\n );\n\n const appliedHitSlop = addInsets(\n normalizedHitSlop,\n normalizedPressRetentionOffset\n );\n\n const isPressableEnabled = disabled !== true;\n\n const gestures = [pressAndTouchGesture, hoverGesture, buttonGesture];\n\n for (const gesture of gestures) {\n gesture.enabled(isPressableEnabled);\n gesture.runOnJS(true);\n gesture.hitSlop(appliedHitSlop);\n gesture.shouldCancelWhenOutside(false);\n\n if (Platform.OS !== 'web') {\n gesture.shouldCancelWhenOutside(true);\n }\n }\n\n // Uses different hitSlop, to activate on hitSlop area instead of pressRetentionOffset area\n buttonGesture.hitSlop(normalizedHitSlop);\n\n const gesture = Gesture.Simultaneous(...gestures);\n\n const defaultRippleColor = android_ripple ? undefined : 'transparent';\n\n // `cursor: 'pointer'` on `RNButton` crashes iOS\n const pointerStyle: StyleProp<ViewStyle> =\n Platform.OS === 'web' ? { cursor: 'pointer' } : {};\n\n const styleProp =\n typeof style === 'function' ? style({ pressed: pressedState }) : style;\n\n const childrenProp =\n typeof children === 'function'\n ? children({ pressed: pressedState })\n : children;\n\n return (\n <GestureDetector gesture={gesture}>\n <NativeButton\n {...remainingProps}\n ref={pressableRef}\n hitSlop={appliedHitSlop}\n enabled={isPressableEnabled}\n touchSoundDisabled={android_disableSound ?? undefined}\n rippleColor={processColor(android_ripple?.color ?? defaultRippleColor)}\n rippleRadius={android_ripple?.radius ?? undefined}\n style={[pointerStyle, styleProp]}>\n {childrenProp}\n {__DEV__ ? (\n <PressabilityDebugView color=\"red\" hitSlop={normalizedHitSlop} />\n ) : null}\n </NativeButton>\n </GestureDetector>\n );\n}\n"]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["index.ts"],"names":["
|
1
|
+
{"version":3,"sources":["index.ts"],"names":["default"],"mappings":"AACA,SAASA,OAAT,QAAwB,aAAxB","sourcesContent":["export type { PressableProps } from './PressableProps';\nexport { default } from './Pressable';\n"]}
|
@@ -95,26 +95,5 @@ const gestureTouchToPressableEvent = event => {
|
|
95
95
|
};
|
96
96
|
};
|
97
97
|
|
98
|
-
|
99
|
-
// - From ViewStyle extracted FlexStyle sub-interface which contains all of the box-model manipulating props.
|
100
|
-
// - From FlexStyle handpicked those styles, which act on the inner part of the box-model.
|
101
|
-
const innerStyleKeys = new Set(['alignContent', 'alignItems', 'flexBasis', 'flexDirection', 'flexWrap', 'rowGap', 'gap', 'columnGap', 'justifyContent', 'overflow', 'padding', 'paddingBottom', 'paddingEnd', 'paddingHorizontal', 'paddingLeft', 'paddingRight', 'paddingStart', 'paddingTop', 'paddingVertical', 'start', 'end', 'direction' // iOS only
|
102
|
-
]);
|
103
|
-
|
104
|
-
const splitStyles = from => {
|
105
|
-
const outerStyles = {};
|
106
|
-
const innerStyles = {};
|
107
|
-
|
108
|
-
for (const key in from) {
|
109
|
-
if (innerStyleKeys.has(key)) {
|
110
|
-
innerStyles[key] = from[key];
|
111
|
-
} else {
|
112
|
-
outerStyles[key] = from[key];
|
113
|
-
}
|
114
|
-
}
|
115
|
-
|
116
|
-
return [innerStyles, outerStyles];
|
117
|
-
};
|
118
|
-
|
119
|
-
export { numberAsInset, addInsets, isTouchWithinInset, gestureToPressableEvent, gestureTouchToPressableEvent, splitStyles };
|
98
|
+
export { numberAsInset, addInsets, isTouchWithinInset, gestureToPressableEvent, gestureTouchToPressableEvent };
|
120
99
|
//# sourceMappingURL=utils.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["utils.ts"],"names":["numberAsInset","value","left","right","top","bottom","addInsets","a","b","touchDataToPressEvent","data","timestamp","targetId","identifier","id","locationX","x","locationY","y","pageX","absoluteX","pageY","absoluteY","target","touches","changedTouches","gestureToPressEvent","event","handlerTag","isTouchWithinInset","dimensions","inset","touch","width","height","gestureToPressableEvent","Date","now","pressEvent","nativeEvent","force","undefined","gestureTouchToPressableEvent","touchesList","allTouches","map","changedTouchesList","at","innerStyleKeys","Set","splitStyles","from","outerStyles","innerStyles","key","has"],"mappings":"AAUA,MAAMA,aAAa,GAAIC,KAAD,KAA4B;AAChDC,EAAAA,IAAI,EAAED,KAD0C;AAEhDE,EAAAA,KAAK,EAAEF,KAFyC;AAGhDG,EAAAA,GAAG,EAAEH,KAH2C;AAIhDI,EAAAA,MAAM,EAAEJ;AAJwC,CAA5B,CAAtB;;AAOA,MAAMK,SAAS,GAAG,CAACC,CAAD,EAAYC,CAAZ;AAAA;;AAAA,SAAmC;AACnDN,IAAAA,IAAI,EAAE,YAACK,CAAC,CAACL,IAAH,6CAAW,CAAX,gBAAiBM,CAAC,CAACN,IAAnB,6CAA2B,CAA3B,CAD6C;AAEnDC,IAAAA,KAAK,EAAE,aAACI,CAAC,CAACJ,KAAH,+CAAY,CAAZ,iBAAkBK,CAAC,CAACL,KAApB,+CAA6B,CAA7B,CAF4C;AAGnDC,IAAAA,GAAG,EAAE,WAACG,CAAC,CAACH,GAAH,2CAAU,CAAV,eAAgBI,CAAC,CAACJ,GAAlB,2CAAyB,CAAzB,CAH8C;AAInDC,IAAAA,MAAM,EAAE,cAACE,CAAC,CAACF,MAAH,iDAAa,CAAb,kBAAmBG,CAAC,CAACH,MAArB,iDAA+B,CAA/B;AAJ2C,GAAnC;AAAA,CAAlB;;AAOA,MAAMI,qBAAqB,GAAG,CAC5BC,IAD4B,EAE5BC,SAF4B,EAG5BC,QAH4B,MAIH;AACzBC,EAAAA,UAAU,EAAEH,IAAI,CAACI,EADQ;AAEzBC,EAAAA,SA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,EAc7B,mBAd6B,EAe7B,aAf6B,EAgB7B,cAhB6B,EAiB7B,cAjB6B,EAkB7B,YAlB6B,EAmB7B,iBAnB6B,EAoB7B,OApB6B,EAqB7B,KArB6B,EAsB7B,WAtB6B,CAsBhB;AAtBgB,CAAR,CAAvB;;AAyBA,MAAMC,WAAW,GAAIC,IAAD,IAA6C;AAC/D,QAAMC,WAAoC,GAAG,EAA7C;AACA,QAAMC,WAAoC,GAAG,EAA7C;;AAEA,OAAK,MAAMC,GAAX,IAAkBH,IAAlB,EAAwB;AACtB,QAAIH,cAAc,CAACO,GAAf,CAAmBD,GAAnB,CAAJ,EAAgD;AAC9CD,MAAAA,WAAW,CAACC,GAAD,CAAX,GAAmBH,IAAI,CAACG,GAAD,CAAvB;AACD,KAFD,MAEO;AACLF,MAAAA,WAAW,CAACE,GAAD,CAAX,GAAmBH,IAAI,CAACG,GAAD,CAAvB;AACD;AACF;;AAED,SAAO,CAACD,WAAD,EAAcD,WAAd,CAAP;AACD,CAbD;;AAeA,SACEpD,aADF,EAEEM,SAFF,EAGEuB,kBAHF,EAIEM,uBAJF,EAKEO,4BALF,EAMEQ,WANF","sourcesContent":["import { Insets, ViewStyle } from 'react-native';\nimport { LongPressGestureHandlerEventPayload } from '../../handlers/GestureHandlerEventPayload';\nimport {\n TouchData,\n GestureStateChangeEvent,\n GestureTouchEvent,\n} from '../../handlers/gestureHandlerCommon';\nimport { HoverGestureHandlerEventPayload } from '../../handlers/gestures/hoverGesture';\nimport { InnerPressableEvent, PressableEvent } from './PressableProps';\n\nconst numberAsInset = (value: number): Insets => ({\n left: value,\n right: value,\n top: value,\n bottom: value,\n});\n\nconst addInsets = (a: Insets, b: Insets): Insets => ({\n left: (a.left ?? 0) + (b.left ?? 0),\n right: (a.right ?? 0) + (b.right ?? 0),\n top: (a.top ?? 0) + (b.top ?? 0),\n bottom: (a.bottom ?? 0) + (b.bottom ?? 0),\n});\n\nconst touchDataToPressEvent = (\n data: TouchData,\n timestamp: number,\n targetId: number\n): InnerPressableEvent => ({\n identifier: data.id,\n locationX: data.x,\n locationY: data.y,\n pageX: data.absoluteX,\n pageY: data.absoluteY,\n target: targetId,\n timestamp: timestamp,\n touches: [], // Always empty - legacy compatibility\n changedTouches: [], // Always empty - legacy compatibility\n});\n\nconst gestureToPressEvent = (\n event: GestureStateChangeEvent<\n HoverGestureHandlerEventPayload | LongPressGestureHandlerEventPayload\n >,\n timestamp: number,\n targetId: number\n): InnerPressableEvent => ({\n identifier: event.handlerTag,\n locationX: event.x,\n locationY: event.y,\n pageX: event.absoluteX,\n pageY: event.absoluteY,\n target: targetId,\n timestamp: timestamp,\n touches: [], // Always empty - legacy compatibility\n changedTouches: [], // Always empty - legacy compatibility\n});\n\nconst isTouchWithinInset = (\n dimensions: { width: number; height: number },\n inset: Insets,\n touch?: TouchData\n) =>\n (touch?.x ?? 0) < (inset.right ?? 0) + dimensions.width &&\n (touch?.y ?? 0) < (inset.bottom ?? 0) + dimensions.height &&\n (touch?.x ?? 0) > -(inset.left ?? 0) &&\n (touch?.y ?? 0) > -(inset.top ?? 0);\n\nconst gestureToPressableEvent = (\n event: GestureStateChangeEvent<\n HoverGestureHandlerEventPayload | LongPressGestureHandlerEventPayload\n >\n): PressableEvent => {\n const timestamp = Date.now();\n\n // As far as I can see, there isn't a conventional way of getting targetId with the data we get\n const targetId = 0;\n\n const pressEvent = gestureToPressEvent(event, timestamp, targetId);\n\n return {\n nativeEvent: {\n touches: [pressEvent],\n changedTouches: [pressEvent],\n identifier: pressEvent.identifier,\n locationX: event.x,\n locationY: event.y,\n pageX: event.absoluteX,\n pageY: event.absoluteY,\n target: targetId,\n timestamp: timestamp,\n force: undefined,\n },\n };\n};\n\nconst gestureTouchToPressableEvent = (\n event: GestureTouchEvent\n): PressableEvent => {\n const timestamp = Date.now();\n\n // As far as I can see, there isn't a conventional way of getting targetId with the data we get\n const targetId = 0;\n\n const touchesList = event.allTouches.map((touch: TouchData) =>\n touchDataToPressEvent(touch, timestamp, targetId)\n );\n const changedTouchesList = event.changedTouches.map((touch: TouchData) =>\n touchDataToPressEvent(touch, timestamp, targetId)\n );\n\n return {\n nativeEvent: {\n touches: touchesList,\n changedTouches: changedTouchesList,\n identifier: event.handlerTag,\n locationX: event.allTouches.at(0)?.x ?? -1,\n locationY: event.allTouches.at(0)?.y ?? -1,\n pageX: event.allTouches.at(0)?.absoluteX ?? -1,\n pageY: event.allTouches.at(0)?.absoluteY ?? -1,\n target: targetId,\n timestamp: timestamp,\n force: undefined,\n },\n };\n};\n\ntype StylePropKeys = (keyof ViewStyle)[];\n\n// Source:\n// - From ViewStyle extracted FlexStyle sub-interface which contains all of the box-model manipulating props.\n// - From FlexStyle handpicked those styles, which act on the inner part of the box-model.\nconst innerStyleKeys = new Set([\n 'alignContent',\n 'alignItems',\n 'flexBasis',\n 'flexDirection',\n 'flexWrap',\n 'rowGap',\n 'gap',\n 'columnGap',\n 'justifyContent',\n 'overflow',\n 'padding',\n 'paddingBottom',\n 'paddingEnd',\n 'paddingHorizontal',\n 'paddingLeft',\n 'paddingRight',\n 'paddingStart',\n 'paddingTop',\n 'paddingVertical',\n 'start',\n 'end',\n 'direction', // iOS only\n] as StylePropKeys);\n\nconst splitStyles = (from: ViewStyle): [ViewStyle, ViewStyle] => {\n const outerStyles: Record<string, unknown> = {};\n const innerStyles: Record<string, unknown> = {};\n\n for (const key in from) {\n if (innerStyleKeys.has(key as keyof ViewStyle)) {\n innerStyles[key] = from[key as keyof ViewStyle];\n } else {\n outerStyles[key] = from[key as keyof ViewStyle];\n }\n }\n\n return [innerStyles, outerStyles];\n};\n\nexport {\n numberAsInset,\n addInsets,\n isTouchWithinInset,\n gestureToPressableEvent,\n gestureTouchToPressableEvent,\n splitStyles,\n};\n"]}
|
1
|
+
{"version":3,"sources":["utils.ts"],"names":["numberAsInset","value","left","right","top","bottom","addInsets","a","b","touchDataToPressEvent","data","timestamp","targetId","identifier","id","locationX","x","locationY","y","pageX","absoluteX","pageY","absoluteY","target","touches","changedTouches","gestureToPressEvent","event","handlerTag","isTouchWithinInset","dimensions","inset","touch","width","height","gestureToPressableEvent","Date","now","pressEvent","nativeEvent","force","undefined","gestureTouchToPressableEvent","touchesList","allTouches","map","changedTouchesList","at"],"mappings":"AAYA,MAAMA,aAAa,GAAIC,KAAD,KAA4B;AAChDC,EAAAA,IAAI,EAAED,KAD0C;AAEhDE,EAAAA,KAAK,EAAEF,KAFyC;AAGhDG,EAAAA,GAAG,EAAEH,KAH2C;AAIhDI,EAAAA,MAAM,EAAEJ;AAJwC,CAA5B,CAAtB;;AAOA,MAAMK,SAAS,GAAG,CAACC,CAAD,EAAYC,CAAZ;AAAA;;AAAA,SAAmC;AACnDN,IAAAA,IAAI,EAAE,YAACK,CAAC,CAACL,IAAH,6CAAW,CAAX,gBAAiBM,CAAC,CAACN,IAAnB,6CAA2B,CAA3B,CAD6C;AAEnDC,IAAAA,KAAK,EAAE,aAACI,CAAC,CAACJ,KAAH,+CAAY,CAAZ,iBAAkBK,CAAC,CAACL,KAApB,+CAA6B,CAA7B,CAF4C;AAGnDC,IAAAA,GAAG,EAAE,WAACG,CAAC,CAACH,GAAH,2CAAU,CAAV,eAAgBI,CAAC,CAACJ,GAAlB,2CAAyB,CAAzB,CAH8C;AAInDC,IAAAA,MAAM,EAAE,cAACE,CAAC,CAACF,MAAH,iDAAa,CAAb,kBAAmBG,CAAC,CAACH,MAArB,iDAA+B,CAA/B;AAJ2C,GAAnC;AAAA,CAAlB;;AAOA,MAAMI,qBAAqB,GAAG,CAC5BC,IAD4B,EAE5BC,SAF4B,EAG5BC,QAH4B,MAIH;AACzBC,EAAAA,UAAU,EAAEH,IAAI,CAACI,EADQ;AAEzBC,EAAAA,SAAS,EAAEL,IAAI,CAACM,CAFS;AAGzBC,EAAAA,SAAS,EAAEP,IAAI,CAACQ,CAHS;AAIzBC,EAAAA,KAAK,EAAET,IAAI,CAACU,SAJa;AAKzBC,EAAAA,KAAK,EAAEX,IAAI,CAACY,SALa;AAMzBC,EAA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IA,SAAO;AACL2B,IAAAA,WAAW,EAAE;AACXf,MAAAA,OAAO,EAAEmB,WADE;AAEXlB,MAAAA,cAAc,EAAEqB,kBAFL;AAGXjC,MAAAA,UAAU,EAAEc,KAAK,CAACC,UAHP;AAIXb,MAAAA,SAAS,mDAAEY,KAAK,CAACiB,UAAN,CAAiBG,EAAjB,CAAoB,CAApB,CAAF,yDAAE,qBAAwB/B,CAA1B,yEAA+B,CAAC,CAJ9B;AAKXC,MAAAA,SAAS,qDAAEU,KAAK,CAACiB,UAAN,CAAiBG,EAAjB,CAAoB,CAApB,CAAF,0DAAE,sBAAwB7B,CAA1B,2EAA+B,CAAC,CAL9B;AAMXC,MAAAA,KAAK,qDAAEQ,KAAK,CAACiB,UAAN,CAAiBG,EAAjB,CAAoB,CAApB,CAAF,0DAAE,sBAAwB3B,SAA1B,2EAAuC,CAAC,CANlC;AAOXC,MAAAA,KAAK,qDAAEM,KAAK,CAACiB,UAAN,CAAiBG,EAAjB,CAAoB,CAApB,CAAF,0DAAE,sBAAwBzB,SAA1B,2EAAuC,CAAC,CAPlC;AAQXC,MAAAA,MAAM,EAAEX,QARG;AASXD,MAAAA,SAAS,EAAEA,SATA;AAUX6B,MAAAA,KAAK,EAAEC;AAVI;AADR,GAAP;AAcD,CA7BD;;AA+BA,SACEzC,aADF,EAEEM,SAFF,EAGEuB,kBAHF,EAIEM,uBAJF,EAKEO,4BALF","sourcesContent":["import { Insets } from 'react-native';\nimport {\n HoverGestureHandlerEventPayload,\n LongPressGestureHandlerEventPayload,\n} from '../../handlers/GestureHandlerEventPayload';\nimport {\n TouchData,\n GestureStateChangeEvent,\n GestureTouchEvent,\n} from '../../handlers/gestureHandlerCommon';\nimport { InnerPressableEvent, PressableEvent } from './PressableProps';\n\nconst numberAsInset = (value: number): Insets => ({\n left: value,\n right: value,\n top: value,\n bottom: value,\n});\n\nconst addInsets = (a: Insets, b: Insets): Insets => ({\n left: (a.left ?? 0) + (b.left ?? 0),\n right: (a.right ?? 0) + (b.right ?? 0),\n top: (a.top ?? 0) + (b.top ?? 0),\n bottom: (a.bottom ?? 0) + (b.bottom ?? 0),\n});\n\nconst touchDataToPressEvent = (\n data: TouchData,\n timestamp: number,\n targetId: number\n): InnerPressableEvent => ({\n identifier: data.id,\n locationX: data.x,\n locationY: data.y,\n pageX: data.absoluteX,\n pageY: data.absoluteY,\n target: targetId,\n timestamp: timestamp,\n touches: [], // Always empty - legacy compatibility\n changedTouches: [], // Always empty - legacy compatibility\n});\n\nconst gestureToPressEvent = (\n event: GestureStateChangeEvent<\n HoverGestureHandlerEventPayload | LongPressGestureHandlerEventPayload\n >,\n timestamp: number,\n targetId: number\n): InnerPressableEvent => ({\n identifier: event.handlerTag,\n locationX: event.x,\n locationY: event.y,\n pageX: event.absoluteX,\n pageY: event.absoluteY,\n target: targetId,\n timestamp: timestamp,\n touches: [], // Always empty - legacy compatibility\n changedTouches: [], // Always empty - legacy compatibility\n});\n\nconst isTouchWithinInset = (\n dimensions: { width: number; height: number },\n inset: Insets,\n touch?: TouchData\n) =>\n (touch?.x ?? 0) < (inset.right ?? 0) + dimensions.width &&\n (touch?.y ?? 0) < (inset.bottom ?? 0) + dimensions.height &&\n (touch?.x ?? 0) > -(inset.left ?? 0) &&\n (touch?.y ?? 0) > -(inset.top ?? 0);\n\nconst gestureToPressableEvent = (\n event: GestureStateChangeEvent<\n HoverGestureHandlerEventPayload | LongPressGestureHandlerEventPayload\n >\n): PressableEvent => {\n const timestamp = Date.now();\n\n // As far as I can see, there isn't a conventional way of getting targetId with the data we get\n const targetId = 0;\n\n const pressEvent = gestureToPressEvent(event, timestamp, targetId);\n\n return {\n nativeEvent: {\n touches: [pressEvent],\n changedTouches: [pressEvent],\n identifier: pressEvent.identifier,\n locationX: event.x,\n locationY: event.y,\n pageX: event.absoluteX,\n pageY: event.absoluteY,\n target: targetId,\n timestamp: timestamp,\n force: undefined,\n },\n };\n};\n\nconst gestureTouchToPressableEvent = (\n event: GestureTouchEvent\n): PressableEvent => {\n const timestamp = Date.now();\n\n // As far as I can see, there isn't a conventional way of getting targetId with the data we get\n const targetId = 0;\n\n const touchesList = event.allTouches.map((touch: TouchData) =>\n touchDataToPressEvent(touch, timestamp, targetId)\n );\n const changedTouchesList = event.changedTouches.map((touch: TouchData) =>\n touchDataToPressEvent(touch, timestamp, targetId)\n );\n\n return {\n nativeEvent: {\n touches: touchesList,\n changedTouches: changedTouchesList,\n identifier: event.handlerTag,\n locationX: event.allTouches.at(0)?.x ?? -1,\n locationY: event.allTouches.at(0)?.y ?? -1,\n pageX: event.allTouches.at(0)?.absoluteX ?? -1,\n pageY: event.allTouches.at(0)?.absoluteY ?? -1,\n target: targetId,\n timestamp: timestamp,\n force: undefined,\n },\n };\n};\n\nexport {\n numberAsInset,\n addInsets,\n isTouchWithinInset,\n gestureToPressableEvent,\n gestureTouchToPressableEvent,\n};\n"]}
|