@office-iss/react-native-win32 0.66.2 → 0.66.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.flowconfig CHANGED
@@ -10,6 +10,7 @@
10
10
  ; initRNLibraries build step
11
11
  <PROJECT_ROOT>/index.js
12
12
  <PROJECT_ROOT>/Libraries/Alert/Alert.js
13
+ <PROJECT_ROOT>/Libraries/Components/Pressable/Pressable.js
13
14
  <PROJECT_ROOT>/Libraries/Components/SafeAreaView/SafeAreaView.js
14
15
  <PROJECT_ROOT>/Libraries/Components/TextInput/TextInput.js
15
16
  <PROJECT_ROOT>/Libraries/Components/TextInput/TextInputState.js
@@ -17,11 +18,15 @@
17
18
  <PROJECT_ROOT>/Libraries/Components/View/ReactNativeViewAttributes.js
18
19
  <PROJECT_ROOT>/Libraries/Components/View/ReactNativeViewViewConfig.js
19
20
  <PROJECT_ROOT>/Libraries/Components/View/View.js
21
+ <PROJECT_ROOT>/Libraries/Components/View/ViewPropTypes.js
20
22
  <PROJECT_ROOT>/Libraries/Image/Image.js
21
23
  <PROJECT_ROOT>/Libraries/Inspector/Inspector.js
22
24
  <PROJECT_ROOT>/Libraries/Inspector/InspectorOverlay.js
23
25
  <PROJECT_ROOT>/Libraries/Network/RCTNetworking.js
26
+ <PROJECT_ROOT>/Libraries/Pressability/Pressability.js
27
+ <PROJECT_ROOT>/Libraries/Pressability/HoverState.js
24
28
  <PROJECT_ROOT>/Libraries/StyleSheet/StyleSheet.js
29
+ <PROJECT_ROOT>/Libraries/Types/CoreEventTypes.js
25
30
  <PROJECT_ROOT>/Libraries/Utilities/DeviceInfo.js
26
31
  <PROJECT_ROOT>/Libraries/Utilities/Dimensions.js
27
32
 
package/CHANGELOG.json CHANGED
@@ -2,7 +2,22 @@
2
2
  "name": "@office-iss/react-native-win32",
3
3
  "entries": [
4
4
  {
5
- "date": "Mon, 15 Nov 2021 16:09:26 GMT",
5
+ "date": "Mon, 17 Jan 2022 16:12:09 GMT",
6
+ "tag": "@office-iss/react-native-win32_v0.66.3",
7
+ "version": "0.66.3",
8
+ "comments": {
9
+ "patch": [
10
+ {
11
+ "comment": "Port windows pressable with extra desktop support to win32",
12
+ "author": "saadnajmi2@gmail.com",
13
+ "commit": "1a70a3b499a0e695597e8669439b856d41096170",
14
+ "package": "@office-iss/react-native-win32"
15
+ }
16
+ ]
17
+ }
18
+ },
19
+ {
20
+ "date": "Mon, 15 Nov 2021 16:09:53 GMT",
6
21
  "tag": "@office-iss/react-native-win32_v0.66.2",
7
22
  "version": "0.66.2",
8
23
  "comments": {
package/CHANGELOG.md CHANGED
@@ -1,17 +1,25 @@
1
1
  # Change Log - @office-iss/react-native-win32
2
2
 
3
- This log was last generated on Mon, 15 Nov 2021 16:09:26 GMT and should not be manually modified.
3
+ This log was last generated on Mon, 17 Jan 2022 16:12:09 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
- ## 0.66.2
7
+ ## 0.66.3
8
8
 
9
- Mon, 15 Nov 2021 16:09:26 GMT
9
+ Mon, 17 Jan 2022 16:12:09 GMT
10
10
 
11
11
  ### Patches
12
12
 
13
- - Add enableFocusRing prop for View and test (ruaraki@microsoft.com)
13
+ - Port windows pressable with extra desktop support to win32 (saadnajmi2@gmail.com)
14
14
 
15
+ ## 0.66.2
16
+
17
+ Mon, 15 Nov 2021 16:09:53 GMT
18
+
19
+ ### Patches
20
+
21
+ - Add enableFocusRing prop for View and test (ruaraki@microsoft.com)
22
+
15
23
  ## 0.66.1
16
24
 
17
25
  Mon, 18 Oct 2021 15:08:36 GMT
@@ -0,0 +1,384 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow strict-local
8
+ * @format
9
+ */
10
+
11
+ import * as React from 'react';
12
+ import {useMemo, useState, useRef, useImperativeHandle} from 'react';
13
+ import useAndroidRippleForView, {
14
+ type RippleConfig,
15
+ } from './useAndroidRippleForView';
16
+ import type {
17
+ AccessibilityActionEvent,
18
+ AccessibilityActionInfo,
19
+ AccessibilityRole,
20
+ AccessibilityState,
21
+ AccessibilityValue,
22
+ } from '../View/ViewAccessibility';
23
+ import {PressabilityDebugView} from '../../Pressability/PressabilityDebug';
24
+ import usePressability from '../../Pressability/usePressability';
25
+ import {normalizeRect, type RectOrSize} from '../../StyleSheet/Rect';
26
+ import type {
27
+ LayoutEvent,
28
+ MouseEvent,
29
+ PressEvent,
30
+ // [Windows
31
+ BlurEvent,
32
+ FocusEvent,
33
+ KeyEvent, // Windows]
34
+ } from '../../Types/CoreEventTypes';
35
+ import type {HandledKeyboardEvent} from '../../Components/View/ViewPropTypes';
36
+ import View from '../View/View';
37
+ import TextInputState from '../TextInput/TextInputState';
38
+
39
+ type ViewStyleProp = $ElementType<React.ElementConfig<typeof View>, 'style'>;
40
+
41
+ export type StateCallbackType = $ReadOnly<{|
42
+ pressed: boolean,
43
+ |}>;
44
+
45
+ type Props = $ReadOnly<{|
46
+ /**
47
+ * Accessibility.
48
+ */
49
+ accessibilityActions?: ?$ReadOnlyArray<AccessibilityActionInfo>,
50
+ accessibilityElementsHidden?: ?boolean,
51
+ accessibilityHint?: ?Stringish,
52
+ accessibilityIgnoresInvertColors?: ?boolean,
53
+ accessibilityLabel?: ?Stringish,
54
+ accessibilityLiveRegion?: ?('none' | 'polite' | 'assertive'),
55
+ accessibilityRole?: ?AccessibilityRole,
56
+ accessibilityState?: ?AccessibilityState,
57
+ accessibilityValue?: ?AccessibilityValue,
58
+ accessibilityViewIsModal?: ?boolean,
59
+ accessible?: ?boolean,
60
+ focusable?: ?boolean,
61
+ importantForAccessibility?: ?('auto' | 'yes' | 'no' | 'no-hide-descendants'),
62
+ onAccessibilityAction?: ?(event: AccessibilityActionEvent) => mixed,
63
+
64
+ /**
65
+ * Whether a press gesture can be interrupted by a parent gesture such as a
66
+ * scroll event. Defaults to true.
67
+ */
68
+ cancelable?: ?boolean,
69
+
70
+ /**
71
+ * Either children or a render prop that receives a boolean reflecting whether
72
+ * the component is currently pressed.
73
+ */
74
+ children: React.Node | ((state: StateCallbackType) => React.Node),
75
+
76
+ /**
77
+ * Duration to wait after hover in before calling `onHoverIn`.
78
+ */
79
+ delayHoverIn?: ?number,
80
+
81
+ /**
82
+ * Duration to wait after hover out before calling `onHoverOut`.
83
+ */
84
+ delayHoverOut?: ?number,
85
+
86
+ /**
87
+ * Duration (in milliseconds) from `onPressIn` before `onLongPress` is called.
88
+ */
89
+ delayLongPress?: ?number,
90
+
91
+ /**
92
+ * Whether the press behavior is disabled.
93
+ */
94
+ disabled?: ?boolean,
95
+
96
+ /**
97
+ * Additional distance outside of this view in which a press is detected.
98
+ */
99
+ hitSlop?: ?RectOrSize,
100
+
101
+ /**
102
+ * Additional distance outside of this view in which a touch is considered a
103
+ * press before `onPressOut` is triggered.
104
+ */
105
+ pressRetentionOffset?: ?RectOrSize,
106
+
107
+ /**
108
+ * Called when this view's layout changes.
109
+ */
110
+ onLayout?: ?(event: LayoutEvent) => mixed,
111
+
112
+ /**
113
+ * Called when the hover is activated to provide visual feedback.
114
+ */
115
+ onHoverIn?: ?(event: MouseEvent) => mixed,
116
+
117
+ /**
118
+ * Called when the hover is deactivated to undo visual feedback.
119
+ */
120
+ onHoverOut?: ?(event: MouseEvent) => mixed,
121
+
122
+ /**
123
+ * Called when a long-tap gesture is detected.
124
+ */
125
+ onLongPress?: ?(event: PressEvent) => mixed,
126
+
127
+ /**
128
+ * Called when a single tap gesture is detected.
129
+ */
130
+ onPress?: ?(event: PressEvent) => mixed,
131
+
132
+ /**
133
+ * Called when a touch is engaged before `onPress`.
134
+ */
135
+ onPressIn?: ?(event: PressEvent) => mixed,
136
+
137
+ /**
138
+ * Called when a touch is released before `onPress`.
139
+ */
140
+ onPressOut?: ?(event: PressEvent) => mixed,
141
+
142
+ /**
143
+ * Called after the element loses focus.
144
+ */
145
+ onBlur?: ?(event: BlurEvent) => mixed,
146
+
147
+ /**
148
+ * Called after the element is focused.
149
+ */
150
+ onFocus?: ?(event: FocusEvent) => mixed,
151
+
152
+ /*
153
+ * Called after a key down event is detected.
154
+ */
155
+ onKeyDown?: ?(event: KeyEvent) => mixed,
156
+
157
+ /*
158
+ * Called after a key up event is detected.
159
+ */
160
+ onKeyUp?: ?(event: KeyEvent) => mixed,
161
+
162
+ /*
163
+ * List of keys handled only by JS.
164
+ */
165
+ keyDownEvents?: ?$ReadOnlyArray<HandledKeyboardEvent>,
166
+
167
+ /*
168
+ * List of keys to be handled only by JS.
169
+ */
170
+ keyUpEvents?: ?$ReadOnlyArray<HandledKeyboardEvent>,
171
+
172
+ /*
173
+ * Called in the tunneling phase after a key up event is detected.
174
+ */
175
+ onKeyDownCapture?: ?(event: KeyEvent) => void,
176
+
177
+ /*
178
+ * Called in the tunneling phase after a key up event is detected.
179
+ */
180
+ onKeyUpCapture?: ?(event: KeyEvent) => void,
181
+
182
+ /**
183
+ * Either view styles or a function that receives a boolean reflecting whether
184
+ * the component is currently pressed and returns view styles.
185
+ */
186
+ style?: ViewStyleProp | ((state: StateCallbackType) => ViewStyleProp),
187
+
188
+ /**
189
+ * Identifier used to find this view in tests.
190
+ */
191
+ testID?: ?string,
192
+
193
+ /**
194
+ * If true, doesn't play system sound on touch.
195
+ */
196
+ android_disableSound?: ?boolean,
197
+
198
+ /**
199
+ * Enables the Android ripple effect and configures its color.
200
+ */
201
+ android_ripple?: ?RippleConfig,
202
+
203
+ /**
204
+ * Used only for documentation or testing (e.g. snapshot testing).
205
+ */
206
+ testOnly_pressed?: ?boolean,
207
+
208
+ /**
209
+ * Duration to wait after press down before calling `onPressIn`.
210
+ */
211
+ unstable_pressDelay?: ?number,
212
+ |}>;
213
+
214
+ /**
215
+ * Component used to build display components that should respond to whether the
216
+ * component is currently pressed or not.
217
+ */
218
+ function Pressable(props: Props, forwardedRef): React.Node {
219
+ const {
220
+ accessible,
221
+ android_disableSound,
222
+ android_ripple,
223
+ cancelable,
224
+ children,
225
+ delayHoverIn,
226
+ delayHoverOut,
227
+ delayLongPress,
228
+ disabled,
229
+ focusable,
230
+ onHoverIn,
231
+ onHoverOut,
232
+ onLongPress,
233
+ onPress,
234
+ onPressIn,
235
+ onPressOut,
236
+ // [Windows
237
+ onBlur,
238
+ onFocus,
239
+ onKeyDown,
240
+ onKeyUp,
241
+ // Windows]
242
+ pressRetentionOffset,
243
+ style,
244
+ testOnly_pressed,
245
+ unstable_pressDelay,
246
+ ...restProps
247
+ } = props;
248
+
249
+ const viewRef = useRef<React.ElementRef<typeof View> | null>(null);
250
+ useImperativeHandle(forwardedRef, () => viewRef.current);
251
+
252
+ // [Windows
253
+ const _onBlur = (event: BlurEvent) => {
254
+ TextInputState.blurInput(viewRef.current);
255
+ if (props.onBlur) {
256
+ props.onBlur(event);
257
+ }
258
+ };
259
+
260
+ const _onFocus = (event: FocusEvent) => {
261
+ TextInputState.focusInput(viewRef.current);
262
+ if (props.onFocus) {
263
+ props.onFocus(event);
264
+ }
265
+ };
266
+ // Windows]
267
+
268
+ const android_rippleConfig = useAndroidRippleForView(android_ripple, viewRef);
269
+
270
+ const [pressed, setPressed] = usePressState(testOnly_pressed === true);
271
+
272
+ const hitSlop = normalizeRect(props.hitSlop);
273
+
274
+ const accessibilityState =
275
+ disabled != null
276
+ ? {...props.accessibilityState, disabled}
277
+ : props.accessibilityState;
278
+
279
+ const restPropsWithDefaults: React.ElementConfig<typeof View> = {
280
+ ...restProps,
281
+ ...android_rippleConfig?.viewProps,
282
+ accessible: accessible !== false,
283
+ accessibilityState,
284
+ focusable: focusable !== false,
285
+ hitSlop,
286
+ };
287
+
288
+ const config = useMemo(
289
+ () => ({
290
+ cancelable,
291
+ disabled,
292
+ hitSlop,
293
+ pressRectOffset: pressRetentionOffset,
294
+ android_disableSound,
295
+ delayHoverIn,
296
+ delayHoverOut,
297
+ delayLongPress,
298
+ delayPressIn: unstable_pressDelay,
299
+ onHoverIn,
300
+ onHoverOut,
301
+ onLongPress,
302
+ onPress,
303
+ onPressIn(event: PressEvent): void {
304
+ if (android_rippleConfig != null) {
305
+ android_rippleConfig.onPressIn(event);
306
+ }
307
+ setPressed(true);
308
+ if (onPressIn != null) {
309
+ onPressIn(event);
310
+ }
311
+ },
312
+ onPressMove: android_rippleConfig?.onPressMove,
313
+ onPressOut(event: PressEvent): void {
314
+ if (android_rippleConfig != null) {
315
+ android_rippleConfig.onPressOut(event);
316
+ }
317
+ setPressed(false);
318
+ if (onPressOut != null) {
319
+ onPressOut(event);
320
+ }
321
+ },
322
+ // [Windows
323
+ onBlur,
324
+ onFocus,
325
+ onKeyDown,
326
+ onKeyUp,
327
+ // Windows]
328
+ }),
329
+ [
330
+ android_disableSound,
331
+ android_rippleConfig,
332
+ cancelable,
333
+ delayHoverIn,
334
+ delayHoverOut,
335
+ delayLongPress,
336
+ disabled,
337
+ hitSlop,
338
+ onHoverIn,
339
+ onHoverOut,
340
+ onLongPress,
341
+ onPress,
342
+ onPressIn,
343
+ onPressOut,
344
+ // [Windows
345
+ onBlur,
346
+ onFocus,
347
+ onKeyDown,
348
+ onKeyUp,
349
+ // Windows]
350
+ pressRetentionOffset,
351
+ setPressed,
352
+ unstable_pressDelay,
353
+ ],
354
+ );
355
+ const eventHandlers = usePressability(config);
356
+
357
+ return (
358
+ <View
359
+ {...restPropsWithDefaults}
360
+ {...eventHandlers}
361
+ // [Windows
362
+ onBlur={_onBlur}
363
+ onFocus={_onFocus}
364
+ // Windows]
365
+ ref={viewRef}
366
+ style={typeof style === 'function' ? style({pressed}) : style}>
367
+ {typeof children === 'function' ? children({pressed}) : children}
368
+ {__DEV__ ? <PressabilityDebugView color="red" hitSlop={hitSlop} /> : null}
369
+ </View>
370
+ );
371
+ }
372
+
373
+ function usePressState(forcePressed: boolean): [boolean, (boolean) => void] {
374
+ const [pressed, setPressed] = useState(false);
375
+ return [pressed || forcePressed, setPressed];
376
+ }
377
+
378
+ const MemoedPressable = React.memo(React.forwardRef(Pressable));
379
+ MemoedPressable.displayName = 'Pressable';
380
+
381
+ export default (MemoedPressable: React.AbstractComponent<
382
+ Props,
383
+ React.ElementRef<typeof View>,
384
+ >);
@@ -14,6 +14,9 @@ import ViewNativeComponent from './ViewNativeComponent';
14
14
  import TextAncestor from '../../Text/TextAncestor';
15
15
  import * as React from 'react';
16
16
  import invariant from 'invariant'; // [Windows]
17
+ // [Windows
18
+ import type {KeyEvent} from '../../Types/CoreEventTypes';
19
+ // Windows]
17
20
 
18
21
  export type Props = ViewProps;
19
22
 
@@ -28,6 +31,50 @@ const View: React.AbstractComponent<
28
31
  ViewProps,
29
32
  React.ElementRef<typeof ViewNativeComponent>,
30
33
  > = React.forwardRef((props: ViewProps, forwardedRef) => {
34
+ const _keyDown = (event: KeyEvent) => {
35
+ if (props.keyDownEvents && event.isPropagationStopped() !== true) {
36
+ for (const el of props.keyDownEvents) {
37
+ if (event.nativeEvent.code == el.code && el.handledEventPhase == 3) {
38
+ event.stopPropagation();
39
+ }
40
+ }
41
+ }
42
+ props.onKeyDown && props.onKeyDown(event);
43
+ };
44
+
45
+ const _keyUp = (event: KeyEvent) => {
46
+ if (props.keyUpEvents && event.isPropagationStopped() !== true) {
47
+ for (const el of props.keyUpEvents) {
48
+ if (event.nativeEvent.code == el.code && el.handledEventPhase == 3) {
49
+ event.stopPropagation();
50
+ }
51
+ }
52
+ }
53
+ props.onKeyUp && props.onKeyUp(event);
54
+ };
55
+
56
+ const _keyDownCapture = (event: KeyEvent) => {
57
+ if (props.keyDownEvents && event.isPropagationStopped() !== true) {
58
+ for (const el of props.keyDownEvents) {
59
+ if (event.nativeEvent.code == el.code && el.handledEventPhase == 1) {
60
+ event.stopPropagation();
61
+ }
62
+ }
63
+ }
64
+ props.onKeyDownCapture && props.onKeyDownCapture(event);
65
+ };
66
+
67
+ const _keyUpCapture = (event: KeyEvent) => {
68
+ if (props.keyUpEvents && event.isPropagationStopped() !== true) {
69
+ for (const el of props.keyUpEvents) {
70
+ if (event.nativeEvent.code == el.code && el.handledEventPhase == 1) {
71
+ event.stopPropagation();
72
+ }
73
+ }
74
+ }
75
+ props.onKeyUpCapture && props.onKeyUpCapture(event);
76
+ };
77
+
31
78
  return (
32
79
  // [Windows
33
80
  // In core this is a TextAncestor.Provider value={false} See
@@ -39,10 +86,19 @@ const View: React.AbstractComponent<
39
86
  !hasTextAncestor,
40
87
  'Nesting of <View> within <Text> is not currently supported.',
41
88
  );
42
-
43
- return <ViewNativeComponent {...props} ref={forwardedRef} />;
89
+ return (
90
+ <ViewNativeComponent
91
+ {...props}
92
+ ref={forwardedRef}
93
+ onKeyDown={_keyDown}
94
+ onKeyDownCapture={_keyDownCapture}
95
+ onKeyUp={_keyUp}
96
+ onKeyUpCapture={_keyUpCapture}
97
+ />
98
+ );
44
99
  }}
45
100
  </TextAncestor.Consumer>
101
+ // Windows]
46
102
  );
47
103
  });
48
104