@react-native-oh-tpl/react-native-gesture-handler 2.12.6-2 → 2.12.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (192) hide show
  1. package/harmony/gesture_handler/BuildProfile.ets +5 -0
  2. package/harmony/gesture_handler/build-profile.json5 +13 -2
  3. package/harmony/gesture_handler/hvigorfile.ts +1 -1
  4. package/harmony/gesture_handler/index.ets +1 -1
  5. package/harmony/gesture_handler/oh-package-lock.json5 +17 -0
  6. package/harmony/gesture_handler/oh-package.json5 +10 -11
  7. package/harmony/gesture_handler/src/main/cpp/GestureHandlerPackage.cpp +75 -6
  8. package/harmony/gesture_handler/src/main/cpp/GestureHandlerPackage.h +14 -8
  9. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerButtonComponentDescriptor.h +4 -28
  10. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerButtonComponentInstance.h +27 -0
  11. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerButtonJSIBinder.h +32 -0
  12. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerModule.cpp +17 -12
  13. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerModule.h +5 -2
  14. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerPackage.h +72 -0
  15. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerRootViewComponentDescriptor.h +4 -28
  16. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerRootViewComponentInstance.h +78 -0
  17. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerRootViewJSIBinder.h +25 -0
  18. package/harmony/gesture_handler/src/main/ets/EventDispatcher.ts +16 -1
  19. package/harmony/gesture_handler/src/main/ets/GestureHandler.ts +2 -2
  20. package/harmony/gesture_handler/src/main/ets/{GestureHandlerArkUIAdapter.ets → GestureHandlerArkUIAdapter.ts} +2 -1
  21. package/harmony/gesture_handler/src/main/ets/GestureHandlerPackage.ts +2 -2
  22. package/harmony/gesture_handler/src/main/ets/OutgoingEvent.ts +5 -5
  23. package/harmony/gesture_handler/src/main/ets/RNGHLogger.ts +20 -1
  24. package/harmony/gesture_handler/src/main/ets/{RNGHRootTouchHandler.ets → RNGHRootTouchHandlerArkTS.ts} +5 -3
  25. package/harmony/gesture_handler/src/main/ets/RNGHRootTouchHandlerCAPI.ts +87 -0
  26. package/harmony/gesture_handler/src/main/ets/RNGestureHandlerButton.ets +4 -3
  27. package/harmony/gesture_handler/src/main/ets/RNGestureHandlerModule.ts +65 -7
  28. package/harmony/gesture_handler/src/main/ets/RNGestureHandlerRootView.ets +7 -11
  29. package/harmony/gesture_handler/src/main/ets/RNOHScrollLocker.ts +17 -5
  30. package/harmony/gesture_handler/src/main/ets/View.ts +1 -1
  31. package/harmony/gesture_handler/src/main/ets/ViewRegistry.ts +1 -1
  32. package/harmony/gesture_handler/src/main/ets/namespace/RNGestureHandlerButton.ts +140 -0
  33. package/harmony/gesture_handler/src/main/ets/namespace/RNGestureHandlerModule.ts +25 -0
  34. package/harmony/gesture_handler/src/main/ets/namespace/RNGestureHandlerRootView.ts +101 -0
  35. package/harmony/gesture_handler/src/main/ets/namespace/ts.ts +3 -0
  36. package/harmony/gesture_handler/src/main/ets/types.ts +25 -0
  37. package/harmony/gesture_handler/src/main/module.json5 +6 -6
  38. package/harmony/gesture_handler/ts.ts +2 -1
  39. package/harmony/gesture_handler.har +0 -0
  40. package/lib/commonjs/RNGestureHandlerModule.js +6 -3
  41. package/lib/commonjs/RNGestureHandlerModule.js.map +1 -1
  42. package/lib/commonjs/components/GestureHandlerRootView.js +5 -13
  43. package/lib/commonjs/components/GestureHandlerRootView.js.map +1 -1
  44. package/lib/commonjs/handlers/createHandler.js +31 -28
  45. package/lib/commonjs/handlers/createHandler.js.map +1 -1
  46. package/lib/commonjs/index.js +42 -19
  47. package/lib/commonjs/index.js.map +1 -1
  48. package/lib/commonjs/specs/NativeRNGestureHandlerModule.js +10 -0
  49. package/lib/commonjs/specs/NativeRNGestureHandlerModule.js.map +1 -0
  50. package/lib/commonjs/specs/RNGestureHandlerButtonNativeComponent.js +11 -0
  51. package/lib/commonjs/specs/RNGestureHandlerButtonNativeComponent.js.map +1 -0
  52. package/lib/commonjs/specs/RNGestureHandlerRootViewNativeComponent.js +11 -0
  53. package/lib/commonjs/specs/RNGestureHandlerRootViewNativeComponent.js.map +1 -0
  54. package/lib/module/RNGestureHandlerModule.js +3 -2
  55. package/lib/module/RNGestureHandlerModule.js.map +1 -1
  56. package/lib/module/components/GestureHandlerRootView.js +3 -11
  57. package/lib/module/components/GestureHandlerRootView.js.map +1 -1
  58. package/lib/module/handlers/createHandler.js +20 -19
  59. package/lib/module/handlers/createHandler.js.map +1 -1
  60. package/lib/module/index.js +6 -14
  61. package/lib/module/index.js.map +1 -1
  62. package/lib/module/specs/NativeRNGestureHandlerModule.js +3 -0
  63. package/lib/module/specs/NativeRNGestureHandlerModule.js.map +1 -0
  64. package/lib/module/specs/RNGestureHandlerButtonNativeComponent.js +3 -0
  65. package/lib/module/specs/RNGestureHandlerButtonNativeComponent.js.map +1 -0
  66. package/lib/module/specs/RNGestureHandlerRootViewNativeComponent.js +3 -0
  67. package/lib/module/specs/RNGestureHandlerRootViewNativeComponent.js.map +1 -0
  68. package/lib/typescript/RNGestureHandlerModule.d.ts +2 -6
  69. package/lib/typescript/RNGestureHandlerModule.d.ts.map +1 -1
  70. package/lib/typescript/components/GestureHandlerRootView.d.ts +6 -6
  71. package/lib/typescript/components/GestureHandlerRootView.d.ts.map +1 -1
  72. package/lib/typescript/handlers/createHandler.d.ts +11 -11
  73. package/lib/typescript/handlers/createHandler.d.ts.map +1 -1
  74. package/lib/typescript/index.d.ts +9 -8
  75. package/lib/typescript/index.d.ts.map +1 -1
  76. package/lib/typescript/specs/NativeRNGestureHandlerModule.d.ts +15 -0
  77. package/lib/typescript/specs/NativeRNGestureHandlerModule.d.ts.map +1 -0
  78. package/lib/typescript/specs/RNGestureHandlerButtonNativeComponent.d.ts +15 -0
  79. package/lib/typescript/specs/RNGestureHandlerButtonNativeComponent.d.ts.map +1 -0
  80. package/lib/typescript/specs/RNGestureHandlerRootViewNativeComponent.d.ts +7 -0
  81. package/lib/typescript/specs/RNGestureHandlerRootViewNativeComponent.d.ts.map +1 -0
  82. package/package.json +9 -13
  83. package/src/RNGestureHandlerModule.ts +3 -4
  84. package/src/components/GestureHandlerRootView.tsx +4 -15
  85. package/src/handlers/createHandler.tsx +4 -5
  86. package/src/index.ts +13 -13
  87. package/src/specs/NativeRNGestureHandlerModule.ts +26 -0
  88. package/src/specs/RNGestureHandlerButtonNativeComponent.ts +18 -0
  89. package/src/specs/RNGestureHandlerRootViewNativeComponent.ts +6 -0
  90. package/README.md +0 -1
  91. package/harmony/gesture_handler/LICENSE +0 -21
  92. package/harmony/gesture_handler/OAT.xml +0 -44
  93. package/harmony/gesture_handler/README.OpenSource +0 -11
  94. package/harmony/gesture_handler/README.md +0 -1
  95. package/lib/commonjs/components/GestureButtons.js +0 -186
  96. package/lib/commonjs/components/GestureButtons.js.map +0 -1
  97. package/lib/commonjs/components/GestureHandlerButton.js +0 -9
  98. package/lib/commonjs/components/GestureHandlerButton.js.map +0 -1
  99. package/lib/commonjs/components/RNGestureHandlerButton.js +0 -23
  100. package/lib/commonjs/components/RNGestureHandlerButton.js.map +0 -1
  101. package/lib/commonjs/components/touchables/GenericTouchable.js +0 -247
  102. package/lib/commonjs/components/touchables/GenericTouchable.js.map +0 -1
  103. package/lib/commonjs/components/touchables/TouchableOpacity.js +0 -58
  104. package/lib/commonjs/components/touchables/TouchableOpacity.js.map +0 -1
  105. package/lib/commonjs/components/touchables/TouchableWithoutFeedback.js +0 -18
  106. package/lib/commonjs/components/touchables/TouchableWithoutFeedback.js.map +0 -1
  107. package/lib/commonjs/components/touchables/index.js +0 -21
  108. package/lib/commonjs/components/touchables/index.js.map +0 -1
  109. package/lib/commonjs/handlers/NativeViewGestureHandler.js +0 -19
  110. package/lib/commonjs/handlers/NativeViewGestureHandler.js.map +0 -1
  111. package/lib/commonjs/handlers/PanGestureHandler.js +0 -103
  112. package/lib/commonjs/handlers/PanGestureHandler.js.map +0 -1
  113. package/lib/commonjs/handlers/TapGestureHandler.js +0 -22
  114. package/lib/commonjs/handlers/TapGestureHandler.js.map +0 -1
  115. package/lib/commonjs/handlers/createNativeWrapper.js +0 -64
  116. package/lib/commonjs/handlers/createNativeWrapper.js.map +0 -1
  117. package/lib/commonjs/handlers/gestureHandlerCommon.js +0 -22
  118. package/lib/commonjs/handlers/gestureHandlerCommon.js.map +0 -1
  119. package/lib/commonjs/handlers/gestures/GestureDetector.js +0 -554
  120. package/lib/commonjs/handlers/gestures/GestureDetector.js.map +0 -1
  121. package/lib/commonjs/init.js +0 -24
  122. package/lib/commonjs/init.js.map +0 -1
  123. package/lib/module/components/GestureButtons.js +0 -168
  124. package/lib/module/components/GestureButtons.js.map +0 -1
  125. package/lib/module/components/GestureHandlerButton.js +0 -3
  126. package/lib/module/components/GestureHandlerButton.js.map +0 -1
  127. package/lib/module/components/RNGestureHandlerButton.js +0 -17
  128. package/lib/module/components/RNGestureHandlerButton.js.map +0 -1
  129. package/lib/module/components/touchables/GenericTouchable.js +0 -238
  130. package/lib/module/components/touchables/GenericTouchable.js.map +0 -1
  131. package/lib/module/components/touchables/TouchableOpacity.js +0 -49
  132. package/lib/module/components/touchables/TouchableOpacity.js.map +0 -1
  133. package/lib/module/components/touchables/TouchableWithoutFeedback.js +0 -9
  134. package/lib/module/components/touchables/TouchableWithoutFeedback.js.map +0 -1
  135. package/lib/module/components/touchables/index.js +0 -8
  136. package/lib/module/components/touchables/index.js.map +0 -1
  137. package/lib/module/handlers/NativeViewGestureHandler.js +0 -12
  138. package/lib/module/handlers/NativeViewGestureHandler.js.map +0 -1
  139. package/lib/module/handlers/PanGestureHandler.js +0 -92
  140. package/lib/module/handlers/PanGestureHandler.js.map +0 -1
  141. package/lib/module/handlers/TapGestureHandler.js +0 -14
  142. package/lib/module/handlers/TapGestureHandler.js.map +0 -1
  143. package/lib/module/handlers/createNativeWrapper.js +0 -57
  144. package/lib/module/handlers/createNativeWrapper.js.map +0 -1
  145. package/lib/module/handlers/gestureHandlerCommon.js +0 -15
  146. package/lib/module/handlers/gestureHandlerCommon.js.map +0 -1
  147. package/lib/module/handlers/gestures/GestureDetector.js +0 -543
  148. package/lib/module/handlers/gestures/GestureDetector.js.map +0 -1
  149. package/lib/module/init.js +0 -17
  150. package/lib/module/init.js.map +0 -1
  151. package/lib/typescript/components/GestureButtons.d.ts +0 -122
  152. package/lib/typescript/components/GestureButtons.d.ts.map +0 -1
  153. package/lib/typescript/components/GestureHandlerButton.d.ts +0 -5
  154. package/lib/typescript/components/GestureHandlerButton.d.ts.map +0 -1
  155. package/lib/typescript/components/RNGestureHandlerButton.d.ts +0 -2
  156. package/lib/typescript/components/RNGestureHandlerButton.d.ts.map +0 -1
  157. package/lib/typescript/components/touchables/GenericTouchable.d.ts +0 -68
  158. package/lib/typescript/components/touchables/GenericTouchable.d.ts.map +0 -1
  159. package/lib/typescript/components/touchables/TouchableOpacity.d.ts +0 -26
  160. package/lib/typescript/components/touchables/TouchableOpacity.d.ts.map +0 -1
  161. package/lib/typescript/components/touchables/TouchableWithoutFeedback.d.ts +0 -8
  162. package/lib/typescript/components/touchables/TouchableWithoutFeedback.d.ts.map +0 -1
  163. package/lib/typescript/components/touchables/index.d.ts +0 -4
  164. package/lib/typescript/components/touchables/index.d.ts.map +0 -1
  165. package/lib/typescript/handlers/NativeViewGestureHandler.d.ts +0 -29
  166. package/lib/typescript/handlers/NativeViewGestureHandler.d.ts.map +0 -1
  167. package/lib/typescript/handlers/PanGestureHandler.d.ts +0 -140
  168. package/lib/typescript/handlers/PanGestureHandler.d.ts.map +0 -1
  169. package/lib/typescript/handlers/TapGestureHandler.d.ts +0 -58
  170. package/lib/typescript/handlers/TapGestureHandler.d.ts.map +0 -1
  171. package/lib/typescript/handlers/createNativeWrapper.d.ts +0 -4
  172. package/lib/typescript/handlers/createNativeWrapper.d.ts.map +0 -1
  173. package/lib/typescript/handlers/gestureHandlerCommon.d.ts +0 -2
  174. package/lib/typescript/handlers/gestureHandlerCommon.d.ts.map +0 -1
  175. package/lib/typescript/handlers/gestures/GestureDetector.d.ts +0 -24
  176. package/lib/typescript/handlers/gestures/GestureDetector.d.ts.map +0 -1
  177. package/lib/typescript/init.d.ts +0 -3
  178. package/lib/typescript/init.d.ts.map +0 -1
  179. package/src/components/GestureButtons.tsx +0 -334
  180. package/src/components/GestureHandlerButton.tsx +0 -5
  181. package/src/components/RNGestureHandlerButton.tsx +0 -23
  182. package/src/components/touchables/GenericTouchable.tsx +0 -301
  183. package/src/components/touchables/TouchableOpacity.tsx +0 -76
  184. package/src/components/touchables/TouchableWithoutFeedback.tsx +0 -14
  185. package/src/components/touchables/index.ts +0 -7
  186. package/src/handlers/NativeViewGestureHandler.ts +0 -55
  187. package/src/handlers/PanGestureHandler.ts +0 -327
  188. package/src/handlers/TapGestureHandler.ts +0 -95
  189. package/src/handlers/createNativeWrapper.tsx +0 -81
  190. package/src/handlers/gestureHandlerCommon.ts +0 -15
  191. package/src/handlers/gestures/GestureDetector.tsx +0 -823
  192. package/src/init.ts +0 -18
@@ -1,334 +0,0 @@
1
- import * as React from 'react';
2
- import {
3
- Animated,
4
- Platform,
5
- processColor,
6
- StyleSheet,
7
- StyleProp,
8
- ViewStyle,
9
- } from 'react-native';
10
-
11
- import createNativeWrapper from '../handlers/createNativeWrapper';
12
- import GestureHandlerButton from './GestureHandlerButton';
13
- import { State } from 'react-native-gesture-handler/src/State';
14
-
15
- import {
16
- GestureEvent,
17
- HandlerStateChangeEvent,
18
- } from 'react-native-gesture-handler/src/handlers/gestureHandlerCommon';
19
- import {
20
- NativeViewGestureHandlerPayload,
21
- NativeViewGestureHandlerProps,
22
- } from 'react-native-gesture-handler/src/handlers/NativeViewGestureHandler';
23
-
24
- export interface RawButtonProps extends NativeViewGestureHandlerProps {
25
- /**
26
- * Defines if more than one button could be pressed simultaneously. By default
27
- * set true.
28
- */
29
- exclusive?: boolean;
30
- // TODO: we should transform props in `createNativeWrapper`
31
-
32
- /**
33
- * Android only.
34
- *
35
- * Defines color of native ripple animation used since API level 21.
36
- */
37
- rippleColor?: any; // it was present in BaseButtonProps before but is used here in code
38
-
39
- /**
40
- * Android only.
41
- *
42
- * Defines radius of native ripple animation used since API level 21.
43
- */
44
- rippleRadius?: number | null;
45
-
46
- /**
47
- * Android only.
48
- *
49
- * Set this to true if you want the ripple animation to render outside the view bounds.
50
- */
51
- borderless?: boolean;
52
-
53
- /**
54
- * Android only.
55
- *
56
- * Defines whether the ripple animation should be drawn on the foreground of the view.
57
- */
58
- foreground?: boolean;
59
-
60
- /**
61
- * Android only.
62
- *
63
- * Set this to true if you don't want the system to play sound when the button is pressed.
64
- */
65
- touchSoundDisabled?: boolean;
66
- }
67
-
68
- export interface BaseButtonProps extends RawButtonProps {
69
- /**
70
- * Called when the button gets pressed (analogous to `onPress` in
71
- * `TouchableHighlight` from RN core).
72
- */
73
- onPress?: (pointerInside: boolean) => void;
74
-
75
- /**
76
- * Called when the button gets pressed and is held for `delayLongPress`
77
- * milliseconds.
78
- */
79
- onLongPress?: () => void;
80
-
81
- /**
82
- * Called when button changes from inactive to active and vice versa. It
83
- * passes active state as a boolean variable as a first parameter for that
84
- * method.
85
- */
86
- onActiveStateChange?: (active: boolean) => void;
87
- style?: StyleProp<ViewStyle>;
88
- testID?: string;
89
-
90
- /**
91
- * Delay, in milliseconds, after which the `onLongPress` callback gets called.
92
- * Defaults to 600.
93
- */
94
- delayLongPress?: number;
95
- }
96
-
97
- export interface RectButtonProps extends BaseButtonProps {
98
- /**
99
- * Background color that will be dimmed when button is in active state.
100
- */
101
- underlayColor?: string;
102
-
103
- /**
104
- * iOS only.
105
- *
106
- * Opacity applied to the underlay when button is in active state.
107
- */
108
- activeOpacity?: number;
109
- }
110
-
111
- export interface BorderlessButtonProps extends BaseButtonProps {
112
- /**
113
- * iOS only.
114
- *
115
- * Opacity applied to the button when it is in an active state.
116
- */
117
- activeOpacity?: number;
118
- }
119
-
120
- export const RawButton = createNativeWrapper(GestureHandlerButton, {
121
- shouldCancelWhenOutside: false,
122
- shouldActivateOnStart: false,
123
- });
124
-
125
- export class BaseButton extends React.Component<BaseButtonProps> {
126
- static defaultProps = {
127
- delayLongPress: 600,
128
- };
129
-
130
- private lastActive: boolean;
131
- private longPressTimeout: ReturnType<typeof setTimeout> | undefined;
132
- private longPressDetected: boolean;
133
-
134
- constructor(props: BaseButtonProps) {
135
- super(props);
136
- this.lastActive = false;
137
- this.longPressDetected = false;
138
- }
139
-
140
- private handleEvent = ({
141
- nativeEvent,
142
- }: HandlerStateChangeEvent<NativeViewGestureHandlerPayload>) => {
143
- const { state, oldState, pointerInside } = nativeEvent;
144
- const active = pointerInside && state === State.ACTIVE;
145
-
146
- if (active !== this.lastActive && this.props.onActiveStateChange) {
147
- this.props.onActiveStateChange(active);
148
- }
149
-
150
- if (
151
- !this.longPressDetected &&
152
- oldState === State.ACTIVE &&
153
- state !== State.CANCELLED &&
154
- this.lastActive &&
155
- this.props.onPress
156
- ) {
157
- this.props.onPress(active);
158
- }
159
-
160
- if (
161
- !this.lastActive &&
162
- // NativeViewGestureHandler sends different events based on platform
163
- state === (Platform.OS !== 'android' ? State.ACTIVE : State.BEGAN) &&
164
- pointerInside
165
- ) {
166
- this.longPressDetected = false;
167
- if (this.props.onLongPress) {
168
- this.longPressTimeout = setTimeout(
169
- this.onLongPress,
170
- this.props.delayLongPress
171
- );
172
- }
173
- } else if (
174
- // cancel longpress timeout if it's set and the finger moved out of the view
175
- state === State.ACTIVE &&
176
- !pointerInside &&
177
- this.longPressTimeout !== undefined
178
- ) {
179
- clearTimeout(this.longPressTimeout);
180
- this.longPressTimeout = undefined;
181
- } else if (
182
- // cancel longpress timeout if it's set and the gesture has finished
183
- this.longPressTimeout !== undefined &&
184
- (state === State.END ||
185
- state === State.CANCELLED ||
186
- state === State.FAILED)
187
- ) {
188
- clearTimeout(this.longPressTimeout);
189
- this.longPressTimeout = undefined;
190
- }
191
-
192
- this.lastActive = active;
193
- };
194
-
195
- private onLongPress = () => {
196
- this.longPressDetected = true;
197
- this.props.onLongPress?.();
198
- };
199
-
200
- // Normally, the parent would execute it's handler first, then forward the
201
- // event to listeners. However, here our handler is virtually only forwarding
202
- // events to listeners, so we reverse the order to keep the proper order of
203
- // the callbacks (from "raw" ones to "processed").
204
- private onHandlerStateChange = (
205
- e: HandlerStateChangeEvent<NativeViewGestureHandlerPayload>
206
- ) => {
207
- this.props.onHandlerStateChange?.(e);
208
- this.handleEvent(e);
209
- };
210
-
211
- private onGestureEvent = (
212
- e: GestureEvent<NativeViewGestureHandlerPayload>
213
- ) => {
214
- this.props.onGestureEvent?.(e);
215
- this.handleEvent(
216
- e as HandlerStateChangeEvent<NativeViewGestureHandlerPayload>
217
- ); // TODO: maybe it is not correct
218
- };
219
-
220
- render() {
221
- const { rippleColor, ...rest } = this.props;
222
-
223
- return (
224
- <RawButton
225
- rippleColor={processColor(rippleColor)}
226
- {...rest}
227
- onGestureEvent={this.onGestureEvent}
228
- onHandlerStateChange={this.onHandlerStateChange}
229
- />
230
- );
231
- }
232
- }
233
-
234
- const AnimatedBaseButton = Animated.createAnimatedComponent(BaseButton);
235
-
236
- const btnStyles = StyleSheet.create({
237
- underlay: {
238
- position: 'absolute',
239
- left: 0,
240
- right: 0,
241
- bottom: 0,
242
- top: 0,
243
- },
244
- });
245
-
246
- export class RectButton extends React.Component<RectButtonProps> {
247
- static defaultProps = {
248
- activeOpacity: 0.105,
249
- underlayColor: 'black',
250
- };
251
-
252
- private opacity: Animated.Value;
253
-
254
- constructor(props: RectButtonProps) {
255
- super(props);
256
- this.opacity = new Animated.Value(0);
257
- }
258
-
259
- private onActiveStateChange = (active: boolean) => {
260
- if (Platform.OS !== 'android') {
261
- this.opacity.setValue(active ? this.props.activeOpacity! : 0);
262
- }
263
-
264
- this.props.onActiveStateChange?.(active);
265
- };
266
-
267
- render() {
268
- const { children, style, ...rest } = this.props;
269
-
270
- const resolvedStyle = StyleSheet.flatten(style ?? {});
271
-
272
- return (
273
- <BaseButton
274
- {...rest}
275
- style={resolvedStyle}
276
- onActiveStateChange={this.onActiveStateChange}
277
- >
278
- <Animated.View
279
- style={[
280
- btnStyles.underlay,
281
- {
282
- opacity: this.opacity,
283
- backgroundColor: this.props.underlayColor,
284
- borderRadius: resolvedStyle.borderRadius,
285
- borderTopLeftRadius: resolvedStyle.borderTopLeftRadius,
286
- borderTopRightRadius: resolvedStyle.borderTopRightRadius,
287
- borderBottomLeftRadius: resolvedStyle.borderBottomLeftRadius,
288
- borderBottomRightRadius: resolvedStyle.borderBottomRightRadius,
289
- },
290
- ]}
291
- />
292
- {children}
293
- </BaseButton>
294
- );
295
- }
296
- }
297
-
298
- export class BorderlessButton extends React.Component<BorderlessButtonProps> {
299
- static defaultProps = {
300
- activeOpacity: 0.3,
301
- borderless: true,
302
- };
303
-
304
- private opacity: Animated.Value;
305
-
306
- constructor(props: BorderlessButtonProps) {
307
- super(props);
308
- this.opacity = new Animated.Value(1);
309
- }
310
-
311
- private onActiveStateChange = (active: boolean) => {
312
- if (Platform.OS !== 'android') {
313
- this.opacity.setValue(active ? this.props.activeOpacity! : 1);
314
- }
315
-
316
- this.props.onActiveStateChange?.(active);
317
- };
318
-
319
- render() {
320
- const { children, style, ...rest } = this.props;
321
-
322
- return (
323
- <AnimatedBaseButton
324
- {...rest}
325
- onActiveStateChange={this.onActiveStateChange}
326
- style={[style, Platform.OS === 'ios' && { opacity: this.opacity }]}
327
- >
328
- {children}
329
- </AnimatedBaseButton>
330
- );
331
- }
332
- }
333
-
334
- export { default as PureNativeButton } from './GestureHandlerButton';
@@ -1,5 +0,0 @@
1
- import { HostComponent } from 'react-native';
2
- import { RawButtonProps } from 'react-native-gesture-handler/src/components/GestureButtons';
3
- import { RNGestureHandlerButton } from './RNGestureHandlerButton';
4
-
5
- export default RNGestureHandlerButton as HostComponent<RawButtonProps>;
@@ -1,23 +0,0 @@
1
- import {
2
- registerViewConfig,
3
- ReactNativeViewAttributes,
4
- } from 'react-native-harmony';
5
-
6
- export const RNGestureHandlerButton = registerViewConfig(
7
- 'RNGestureHandlerButton',
8
- () => ({
9
- uiViewClassName: 'RNGestureHandlerButton',
10
- bubblingEventTypes: {},
11
- directEventTypes: {},
12
- validAttributes: {
13
- ...ReactNativeViewAttributes.UIView,
14
- exclusive: true,
15
- foreground: true,
16
- borderless: true,
17
- enabled: true,
18
- rippleColor: true,
19
- rippleRadius: true,
20
- touchSoundDisabled: true,
21
- },
22
- })
23
- );
@@ -1,301 +0,0 @@
1
- import * as React from 'react';
2
- import { Component } from 'react';
3
- import {
4
- Animated,
5
- Platform,
6
- StyleProp,
7
- ViewStyle,
8
- TouchableWithoutFeedbackProps,
9
- Insets,
10
- } from 'react-native';
11
-
12
- import { State } from 'react-native-gesture-handler/src/State';
13
- import { BaseButton } from '../GestureButtons';
14
-
15
- import {
16
- GestureEvent,
17
- HandlerStateChangeEvent,
18
- } from 'react-native-gesture-handler/src/handlers/gestureHandlerCommon';
19
- import { NativeViewGestureHandlerPayload } from 'react-native-gesture-handler/src/handlers/NativeViewGestureHandler';
20
-
21
- /**
22
- * Each touchable is a states' machine which preforms transitions.
23
- * On very beginning (and on the very end or recognition) touchable is
24
- * UNDETERMINED. Then it moves to BEGAN. If touchable recognizes that finger
25
- * travel outside it transits to special MOVED_OUTSIDE state. Gesture recognition
26
- * finishes in UNDETERMINED state.
27
- */
28
- export const TOUCHABLE_STATE = {
29
- UNDETERMINED: 0,
30
- BEGAN: 1,
31
- MOVED_OUTSIDE: 2,
32
- } as const;
33
-
34
- type TouchableState = (typeof TOUCHABLE_STATE)[keyof typeof TOUCHABLE_STATE];
35
-
36
- export interface GenericTouchableProps
37
- extends Omit<TouchableWithoutFeedbackProps, 'hitSlop'> {
38
- // Decided to drop not used fields from RN's implementation.
39
- // e.g. onBlur and onFocus as well as deprecated props. - TODO: this comment may be unuseful in this moment
40
-
41
- // TODO: in RN these events get native event parameter, which prolly could be used in our implementation too
42
- onPress?: () => void;
43
- onPressIn?: () => void;
44
- onPressOut?: () => void;
45
- onLongPress?: () => void;
46
-
47
- nativeID?: string;
48
- shouldActivateOnStart?: boolean;
49
- disallowInterruption?: boolean;
50
-
51
- containerStyle?: StyleProp<ViewStyle>;
52
- hitSlop?: Insets | number;
53
- }
54
-
55
- interface InternalProps {
56
- extraButtonProps: any;
57
- onStateChange?: (oldState: TouchableState, newState: TouchableState) => void;
58
- }
59
-
60
- // TODO: maybe can be better
61
- // TODO: all clearTimeout have ! added, maybe they shouldn't ?
62
- type Timeout = ReturnType<typeof setTimeout> | null | undefined;
63
-
64
- /**
65
- * GenericTouchable is not intented to be used as it is.
66
- * Should be treated as a source for the rest of touchables
67
- */
68
-
69
- export default class GenericTouchable extends Component<
70
- GenericTouchableProps & InternalProps
71
- > {
72
- static defaultProps = {
73
- delayLongPress: 600,
74
- extraButtonProps: {
75
- rippleColor: 'transparent',
76
- exclusive: true,
77
- },
78
- };
79
-
80
- // timeout handlers
81
- pressInTimeout: Timeout;
82
- pressOutTimeout: Timeout;
83
- longPressTimeout: Timeout;
84
-
85
- // This flag is required since recognition of longPress implies not-invoking onPress
86
- longPressDetected = false;
87
-
88
- pointerInside = true;
89
-
90
- // State of touchable
91
- STATE: TouchableState = TOUCHABLE_STATE.UNDETERMINED;
92
-
93
- // handlePressIn in called on first touch on traveling inside component.
94
- // Handles state transition with delay.
95
- handlePressIn() {
96
- if (this.props.delayPressIn) {
97
- this.pressInTimeout = setTimeout(() => {
98
- this.moveToState(TOUCHABLE_STATE.BEGAN);
99
- this.pressInTimeout = null;
100
- }, this.props.delayPressIn);
101
- } else {
102
- this.moveToState(TOUCHABLE_STATE.BEGAN);
103
- }
104
- if (this.props.onLongPress) {
105
- const time =
106
- (this.props.delayPressIn || 0) + (this.props.delayLongPress || 0);
107
- this.longPressTimeout = setTimeout(this.onLongPressDetected, time);
108
- }
109
- }
110
- // handleMoveOutside in called on traveling outside component.
111
- // Handles state transition with delay.
112
- handleMoveOutside() {
113
- if (this.props.delayPressOut) {
114
- this.pressOutTimeout =
115
- this.pressOutTimeout ||
116
- setTimeout(() => {
117
- this.moveToState(TOUCHABLE_STATE.MOVED_OUTSIDE);
118
- this.pressOutTimeout = null;
119
- }, this.props.delayPressOut);
120
- } else {
121
- this.moveToState(TOUCHABLE_STATE.MOVED_OUTSIDE);
122
- }
123
- }
124
-
125
- // handleGoToUndetermined transits to UNDETERMINED state with proper delay
126
- handleGoToUndetermined() {
127
- clearTimeout(this.pressOutTimeout!); // TODO: maybe it can be undefined
128
- if (this.props.delayPressOut) {
129
- this.pressOutTimeout = setTimeout(() => {
130
- if (this.STATE === TOUCHABLE_STATE.UNDETERMINED) {
131
- this.moveToState(TOUCHABLE_STATE.BEGAN);
132
- }
133
- this.moveToState(TOUCHABLE_STATE.UNDETERMINED);
134
- this.pressOutTimeout = null;
135
- }, this.props.delayPressOut);
136
- } else {
137
- if (this.STATE === TOUCHABLE_STATE.UNDETERMINED) {
138
- this.moveToState(TOUCHABLE_STATE.BEGAN);
139
- }
140
- this.moveToState(TOUCHABLE_STATE.UNDETERMINED);
141
- }
142
- }
143
-
144
- componentDidMount() {
145
- this.reset();
146
- }
147
- // reset timeout to prevent memory leaks.
148
- reset() {
149
- this.longPressDetected = false;
150
- this.pointerInside = true;
151
- clearTimeout(this.pressInTimeout!);
152
- clearTimeout(this.pressOutTimeout!);
153
- clearTimeout(this.longPressTimeout!);
154
- this.pressOutTimeout = null;
155
- this.longPressTimeout = null;
156
- this.pressInTimeout = null;
157
- }
158
-
159
- // All states' transitions are defined here.
160
- moveToState(newState: TouchableState) {
161
- if (newState === this.STATE) {
162
- // Ignore dummy transitions
163
- return;
164
- }
165
- if (newState === TOUCHABLE_STATE.BEGAN) {
166
- // First touch and moving inside
167
- this.props.onPressIn?.();
168
- } else if (newState === TOUCHABLE_STATE.MOVED_OUTSIDE) {
169
- // Moving outside
170
- this.props.onPressOut?.();
171
- } else if (newState === TOUCHABLE_STATE.UNDETERMINED) {
172
- // Need to reset each time on transition to UNDETERMINED
173
- this.reset();
174
- if (this.STATE === TOUCHABLE_STATE.BEGAN) {
175
- // ... and if it happens inside button.
176
- this.props.onPressOut?.();
177
- }
178
- }
179
- // Finally call lister (used by subclasses)
180
- this.props.onStateChange?.(this.STATE, newState);
181
- // ... and make transition.
182
- this.STATE = newState;
183
- }
184
-
185
- onGestureEvent = ({
186
- nativeEvent: { pointerInside },
187
- }: GestureEvent<NativeViewGestureHandlerPayload>) => {
188
- if (this.pointerInside !== pointerInside) {
189
- if (pointerInside) {
190
- this.onMoveIn();
191
- } else {
192
- this.onMoveOut();
193
- }
194
- }
195
- this.pointerInside = pointerInside;
196
- };
197
-
198
- onHandlerStateChange = ({
199
- nativeEvent,
200
- }: HandlerStateChangeEvent<NativeViewGestureHandlerPayload>) => {
201
- const { state } = nativeEvent;
202
- if (state === State.CANCELLED || state === State.FAILED) {
203
- // Need to handle case with external cancellation (e.g. by ScrollView)
204
- this.moveToState(TOUCHABLE_STATE.UNDETERMINED);
205
- } else if (
206
- // This platform check is an implication of slightly different behavior of handlers on different platform.
207
- // And Android "Active" state is achieving on first move of a finger, not on press in.
208
- // On iOS event on "Began" is not delivered.
209
- state === (Platform.OS !== 'android' ? State.ACTIVE : State.BEGAN) &&
210
- this.STATE === TOUCHABLE_STATE.UNDETERMINED
211
- ) {
212
- // Moving inside requires
213
- this.handlePressIn();
214
- } else if (state === State.END) {
215
- const shouldCallOnPress =
216
- !this.longPressDetected &&
217
- this.STATE !== TOUCHABLE_STATE.MOVED_OUTSIDE &&
218
- this.pressOutTimeout === null;
219
- this.handleGoToUndetermined();
220
- if (shouldCallOnPress) {
221
- // Calls only inside component whether no long press was called previously
222
- this.props.onPress?.();
223
- }
224
- }
225
- };
226
-
227
- onLongPressDetected = () => {
228
- this.longPressDetected = true;
229
- // checked for in the caller of `onLongPressDetected`, but better to check twice
230
- this.props.onLongPress?.();
231
- };
232
-
233
- componentWillUnmount() {
234
- // to prevent memory leaks
235
- this.reset();
236
- }
237
-
238
- onMoveIn() {
239
- if (this.STATE === TOUCHABLE_STATE.MOVED_OUTSIDE) {
240
- // This call is not throttled with delays (like in RN's implementation).
241
- this.moveToState(TOUCHABLE_STATE.BEGAN);
242
- }
243
- }
244
-
245
- onMoveOut() {
246
- // long press should no longer be detected
247
- clearTimeout(this.longPressTimeout!);
248
- this.longPressTimeout = null;
249
- if (this.STATE === TOUCHABLE_STATE.BEGAN) {
250
- this.handleMoveOutside();
251
- }
252
- }
253
-
254
- render() {
255
- const hitSlop =
256
- (typeof this.props.hitSlop === 'number'
257
- ? {
258
- top: this.props.hitSlop,
259
- left: this.props.hitSlop,
260
- bottom: this.props.hitSlop,
261
- right: this.props.hitSlop,
262
- }
263
- : this.props.hitSlop) ?? undefined;
264
-
265
- const coreProps = {
266
- accessible: this.props.accessible !== false,
267
- accessibilityLabel: this.props.accessibilityLabel,
268
- accessibilityHint: this.props.accessibilityHint,
269
- accessibilityRole: this.props.accessibilityRole,
270
- // TODO: check if changed to no 's' correctly, also removed 2 props that are no longer available: `accessibilityComponentType` and `accessibilityTraits`,
271
- // would be good to check if it is ok for sure, see: https://github.com/facebook/react-native/issues/24016
272
- accessibilityState: this.props.accessibilityState,
273
- accessibilityActions: this.props.accessibilityActions,
274
- onAccessibilityAction: this.props.onAccessibilityAction,
275
- nativeID: this.props.nativeID,
276
- onLayout: this.props.onLayout,
277
- };
278
-
279
- return (
280
- <BaseButton
281
- style={this.props.containerStyle}
282
- onHandlerStateChange={
283
- // TODO: not sure if it can be undefined instead of null
284
- this.props.disabled ? undefined : this.onHandlerStateChange
285
- }
286
- onGestureEvent={this.onGestureEvent}
287
- hitSlop={hitSlop}
288
- shouldActivateOnStart={this.props.shouldActivateOnStart}
289
- disallowInterruption={this.props.disallowInterruption}
290
- testID={this.props.testID}
291
- touchSoundDisabled={this.props.touchSoundDisabled ?? false}
292
- enabled={!this.props.disabled}
293
- {...this.props.extraButtonProps}
294
- >
295
- <Animated.View {...coreProps} style={this.props.style}>
296
- {this.props.children}
297
- </Animated.View>
298
- </BaseButton>
299
- );
300
- }
301
- }