@fluentui-react-native/focus-zone 0.9.15 → 0.9.18

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/CHANGELOG.json CHANGED
@@ -2,7 +2,52 @@
2
2
  "name": "@fluentui-react-native/focus-zone",
3
3
  "entries": [
4
4
  {
5
- "date": "Wed, 06 Apr 2022 22:56:55 GMT",
5
+ "date": "Tue, 12 Apr 2022 21:52:38 GMT",
6
+ "tag": "@fluentui-react-native/focus-zone_v0.9.18",
7
+ "version": "0.9.18",
8
+ "comments": {
9
+ "patch": [
10
+ {
11
+ "author": "sanajmi@microsoft.com",
12
+ "package": "@fluentui-react-native/focus-zone",
13
+ "commit": "86b38c2e20e29fb4248bfd64e534da45deb35dfa",
14
+ "comment": "Scroll scrollView when Focus moves out of viewport"
15
+ }
16
+ ]
17
+ }
18
+ },
19
+ {
20
+ "date": "Tue, 12 Apr 2022 00:35:08 GMT",
21
+ "tag": "@fluentui-react-native/focus-zone_v0.9.17",
22
+ "version": "0.9.17",
23
+ "comments": {
24
+ "patch": [
25
+ {
26
+ "author": "sanajmi@microsoft.com",
27
+ "package": "@fluentui-react-native/focus-zone",
28
+ "commit": "832066543f281fdec866f738d36f7f73f6bbb4f7",
29
+ "comment": "Add support for nested focus zones"
30
+ }
31
+ ]
32
+ }
33
+ },
34
+ {
35
+ "date": "Fri, 08 Apr 2022 18:53:11 GMT",
36
+ "tag": "@fluentui-react-native/focus-zone_v0.9.16",
37
+ "version": "0.9.16",
38
+ "comments": {
39
+ "patch": [
40
+ {
41
+ "author": "amchiu@microsoft.com",
42
+ "package": "@fluentui-react-native/focus-zone",
43
+ "commit": "15d60684291bc64a6d104448587804bbcfbbb1e4",
44
+ "comment": "Handle FocusZone edge cases"
45
+ }
46
+ ]
47
+ }
48
+ },
49
+ {
50
+ "date": "Wed, 06 Apr 2022 22:58:22 GMT",
6
51
  "tag": "@fluentui-react-native/focus-zone_v0.9.15",
7
52
  "version": "0.9.15",
8
53
  "comments": {
package/CHANGELOG.md CHANGED
@@ -1,12 +1,36 @@
1
1
  # Change Log - @fluentui-react-native/focus-zone
2
2
 
3
- This log was last generated on Wed, 06 Apr 2022 22:56:55 GMT and should not be manually modified.
3
+ This log was last generated on Tue, 12 Apr 2022 21:52:38 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## 0.9.18
8
+
9
+ Tue, 12 Apr 2022 21:52:38 GMT
10
+
11
+ ### Patches
12
+
13
+ - Scroll scrollView when Focus moves out of viewport (sanajmi@microsoft.com)
14
+
15
+ ## 0.9.17
16
+
17
+ Tue, 12 Apr 2022 00:35:08 GMT
18
+
19
+ ### Patches
20
+
21
+ - Add support for nested focus zones (sanajmi@microsoft.com)
22
+
23
+ ## 0.9.16
24
+
25
+ Fri, 08 Apr 2022 18:53:11 GMT
26
+
27
+ ### Patches
28
+
29
+ - Handle FocusZone edge cases (amchiu@microsoft.com)
30
+
7
31
  ## 0.9.15
8
32
 
9
- Wed, 06 Apr 2022 22:56:55 GMT
33
+ Wed, 06 Apr 2022 22:58:22 GMT
10
34
 
11
35
  ### Patches
12
36
 
@@ -49,6 +49,11 @@ static inline CGFloat GetMinDistanceBetweenRectVerticesAndPoint(NSRect rect, NSP
49
49
  /// This function does not take into account the geometric position of the view.
50
50
  static NSView *GetFirstKeyViewWithin(NSView *parentView)
51
51
  {
52
+ if ([[parentView subviews] count] < 1)
53
+ {
54
+ return nil;
55
+ }
56
+
52
57
  for (NSView *view in [parentView subviews]) {
53
58
  if ([view canBecomeKeyView]) {
54
59
  return view;
@@ -142,25 +147,45 @@ static inline BOOL IsHorizontalNavigationWithinZoneAction(FocusZoneAction action
142
147
  return action == FocusZoneActionRightArrow || action == FocusZoneActionLeftArrow;
143
148
  }
144
149
 
150
+ /// Returns the topmost view of the given view's superview heirarchy that is a FocusZone.
151
+ /// Returns nil if no FocusZone is found.
145
152
  static RCTFocusZone *GetFocusZoneAncestor(NSView *view)
146
153
  {
147
154
  NSView *candidateView = view;
148
155
  NSView *topLevelView = [[view window] contentView];
156
+ RCTFocusZone *focusZoneAncestor = nil;
149
157
  while (candidateView != nil && candidateView != topLevelView)
150
158
  {
151
159
  if ([candidateView isKindOfClass:[RCTFocusZone class]])
152
160
  {
153
- return (RCTFocusZone *)candidateView;
161
+ focusZoneAncestor = (RCTFocusZone *)candidateView;
154
162
  }
155
163
  candidateView = [candidateView superview];
156
164
  }
157
- return nil;
165
+ return focusZoneAncestor;
166
+ }
167
+
168
+ /// Bypass FocusZone if it's empty or has no focusable elements
169
+ static BOOL ShouldSkipFocusZone(NSView *view)
170
+ {
171
+ if([view isKindOfClass:[RCTFocusZone class]])
172
+ {
173
+ NSView *keyView = GetFirstKeyViewWithin(view);
174
+ // FocusZone is empty or has no focusable elements
175
+ if (keyView == nil)
176
+ {
177
+ return YES;
178
+ }
179
+ }
180
+
181
+ return NO;
158
182
  }
159
183
 
184
+ /// Accept firstResponder on FocusZone itself in order to reassign it within the FocusZone.
160
185
  - (BOOL)acceptsFirstResponder
161
186
  {
162
- // Accept firstResponder on FocusZone itself in order to reassign it within the FocusZone.
163
- return !_disabled;
187
+ // Reject first responder if FocusZone is disabled or should be skipped.
188
+ return !_disabled && !ShouldSkipFocusZone(self);
164
189
  }
165
190
 
166
191
  - (BOOL)becomeFirstResponder
@@ -341,34 +366,32 @@ static RCTFocusZone *GetFocusZoneAncestor(NSView *view)
341
366
  NSView *nextViewToFocus;
342
367
 
343
368
  [[self window] recalculateKeyViewLoop];
369
+
370
+ // Find the first view outside the FocusZone (or any parent FocusZones) to place focus
371
+ RCTFocusZone *focusZoneAncestor = GetFocusZoneAncestor(self);
344
372
 
345
373
  if (action == FocusZoneActionTab) // Advance to next zone
346
374
  {
347
- IsViewLeadingCandidateForNextFocus block = ^BOOL(NSView *candidateView)
375
+ nextViewToFocus = [self nextValidKeyView];
376
+ while([nextViewToFocus isDescendantOf:focusZoneAncestor])
348
377
  {
349
- return YES;
350
- };
351
-
352
- nextViewToFocus = [([self nextViewToFocusForCondition:block] ?: self) nextValidKeyView];
353
- }
354
- else // action == FocusZoneActionShiftTab per the conditional in keyDown
355
- {
356
- nextViewToFocus = [self previousValidKeyView];
357
- }
358
-
359
- if ([nextViewToFocus isDescendantOf:self])
360
- {
361
- nextViewToFocus = nil;
378
+ nextViewToFocus = [nextViewToFocus nextValidKeyView];
379
+ }
362
380
  }
363
381
  else if (action == FocusZoneActionShiftTab)
364
382
  {
365
- // If the previous view is in a FocusZone, focus the default tabbable element.
366
- // (For FocusZoneActionTab, this is handled by becomeFirstResponder.)
367
- RCTFocusZone *nextFocusZone = GetFocusZoneAncestor(nextViewToFocus);
368
- NSView *element = [nextFocusZone defaultKeyView];
369
- if (element != nil)
383
+ nextViewToFocus = [self previousValidKeyView];
384
+ while([nextViewToFocus isDescendantOf:focusZoneAncestor])
370
385
  {
371
- nextViewToFocus = element;
386
+ nextViewToFocus = [nextViewToFocus previousValidKeyView];
387
+ }
388
+
389
+ // If the previous view is in a FocusZone, focus on its defaultKeyView
390
+ // (For FocusZoneActionTab, this is handled by becomeFirstResponder).
391
+ RCTFocusZone *focusZoneAncestor = GetFocusZoneAncestor(nextViewToFocus);
392
+ NSView *ancestorKeyView = [focusZoneAncestor defaultKeyView];
393
+ if (ancestorKeyView != nil) {
394
+ nextViewToFocus = [focusZoneAncestor defaultKeyView];
372
395
  }
373
396
  }
374
397
 
@@ -412,6 +435,7 @@ static RCTFocusZone *GetFocusZoneAncestor(NSView *view)
412
435
  if (!passthrough && viewToFocus != nil)
413
436
  {
414
437
  [[self window] makeFirstResponder:viewToFocus];
438
+ [viewToFocus scrollRectToVisible:[viewToFocus bounds]];
415
439
  }
416
440
  else
417
441
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluentui-react-native/focus-zone",
3
- "version": "0.9.15",
3
+ "version": "0.9.18",
4
4
  "description": "A cross-platform FocusZone component using the Fluent Design System",
5
5
  "main": "lib-commonjs/index.js",
6
6
  "module": "lib/index.js",