@fluentui-react-native/focus-zone 0.9.14 → 0.9.17

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": "Tue, 05 Apr 2022 20:04:12 GMT",
5
+ "date": "Tue, 12 Apr 2022 00:34:43 GMT",
6
+ "tag": "@fluentui-react-native/focus-zone_v0.9.17",
7
+ "version": "0.9.17",
8
+ "comments": {
9
+ "patch": [
10
+ {
11
+ "author": "sanajmi@microsoft.com",
12
+ "package": "@fluentui-react-native/focus-zone",
13
+ "commit": "832066543f281fdec866f738d36f7f73f6bbb4f7",
14
+ "comment": "Add support for nested focus zones"
15
+ }
16
+ ]
17
+ }
18
+ },
19
+ {
20
+ "date": "Fri, 08 Apr 2022 18:53:11 GMT",
21
+ "tag": "@fluentui-react-native/focus-zone_v0.9.16",
22
+ "version": "0.9.16",
23
+ "comments": {
24
+ "patch": [
25
+ {
26
+ "author": "amchiu@microsoft.com",
27
+ "package": "@fluentui-react-native/focus-zone",
28
+ "commit": "15d60684291bc64a6d104448587804bbcfbbb1e4",
29
+ "comment": "Handle FocusZone edge cases"
30
+ }
31
+ ]
32
+ }
33
+ },
34
+ {
35
+ "date": "Wed, 06 Apr 2022 22:58:22 GMT",
36
+ "tag": "@fluentui-react-native/focus-zone_v0.9.15",
37
+ "version": "0.9.15",
38
+ "comments": {
39
+ "patch": [
40
+ {
41
+ "author": "beachball",
42
+ "package": "@fluentui-react-native/focus-zone",
43
+ "comment": "Bump @fluentui-react-native/interactive-hooks to v0.14.8",
44
+ "commit": "bcd4ac6dc74295095a0564905024ef32d6450cff"
45
+ }
46
+ ]
47
+ }
48
+ },
49
+ {
50
+ "date": "Tue, 05 Apr 2022 20:05:50 GMT",
6
51
  "tag": "@fluentui-react-native/focus-zone_v0.9.14",
7
52
  "version": "0.9.14",
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 Tue, 05 Apr 2022 20:04:12 GMT and should not be manually modified.
3
+ This log was last generated on Tue, 12 Apr 2022 00:34:43 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## 0.9.17
8
+
9
+ Tue, 12 Apr 2022 00:34:43 GMT
10
+
11
+ ### Patches
12
+
13
+ - Add support for nested focus zones (sanajmi@microsoft.com)
14
+
15
+ ## 0.9.16
16
+
17
+ Fri, 08 Apr 2022 18:53:11 GMT
18
+
19
+ ### Patches
20
+
21
+ - Handle FocusZone edge cases (amchiu@microsoft.com)
22
+
23
+ ## 0.9.15
24
+
25
+ Wed, 06 Apr 2022 22:58:22 GMT
26
+
27
+ ### Patches
28
+
29
+ - Bump @fluentui-react-native/interactive-hooks to v0.14.8
30
+
7
31
  ## 0.9.14
8
32
 
9
- Tue, 05 Apr 2022 20:04:12 GMT
33
+ Tue, 05 Apr 2022 20:05:50 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,44 @@ 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;
158
166
  }
159
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;
182
+ }
183
+ /// Accept firstResponder on FocusZone itself in order to reassign it within the FocusZone.
160
184
  - (BOOL)acceptsFirstResponder
161
185
  {
162
- // Accept firstResponder on FocusZone itself in order to reassign it within the FocusZone.
163
- return !_disabled;
186
+ // Reject first responder if FocusZone is disabled or should be skipped.
187
+ return !_disabled && !ShouldSkipFocusZone(self);
164
188
  }
165
189
 
166
190
  - (BOOL)becomeFirstResponder
@@ -341,34 +365,32 @@ static RCTFocusZone *GetFocusZoneAncestor(NSView *view)
341
365
  NSView *nextViewToFocus;
342
366
 
343
367
  [[self window] recalculateKeyViewLoop];
368
+
369
+ // Find the first view outside the FocusZone (or any parent FocusZones) to place focus
370
+ RCTFocusZone *focusZoneAncestor = GetFocusZoneAncestor(self);
344
371
 
345
372
  if (action == FocusZoneActionTab) // Advance to next zone
346
373
  {
347
- IsViewLeadingCandidateForNextFocus block = ^BOOL(NSView *candidateView)
374
+ nextViewToFocus = [self nextValidKeyView];
375
+ while([nextViewToFocus isDescendantOf:focusZoneAncestor])
348
376
  {
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;
377
+ nextViewToFocus = [nextViewToFocus nextValidKeyView];
378
+ }
362
379
  }
363
380
  else if (action == FocusZoneActionShiftTab)
364
381
  {
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)
382
+ nextViewToFocus = [self previousValidKeyView];
383
+ while([nextViewToFocus isDescendantOf:focusZoneAncestor])
370
384
  {
371
- nextViewToFocus = element;
385
+ nextViewToFocus = [nextViewToFocus previousValidKeyView];
386
+ }
387
+
388
+ // If the previous view is in a FocusZone, focus on its defaultKeyView
389
+ // (For FocusZoneActionTab, this is handled by becomeFirstResponder).
390
+ RCTFocusZone *focusZoneAncestor = GetFocusZoneAncestor(nextViewToFocus);
391
+ NSView *ancestorKeyView = [focusZoneAncestor defaultKeyView];
392
+ if (ancestorKeyView != nil) {
393
+ nextViewToFocus = [focusZoneAncestor defaultKeyView];
372
394
  }
373
395
  }
374
396
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluentui-react-native/focus-zone",
3
- "version": "0.9.14",
3
+ "version": "0.9.17",
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",
@@ -23,7 +23,7 @@
23
23
  },
24
24
  "dependencies": {
25
25
  "@fluentui-react-native/component-cache": "^1.3.2",
26
- "@fluentui-react-native/interactive-hooks": ">=0.14.7 <1.0.0",
26
+ "@fluentui-react-native/interactive-hooks": ">=0.14.8 <1.0.0",
27
27
  "@uifabricshared/foundation-composable": ">=0.10.3 <1.0.0",
28
28
  "@uifabricshared/foundation-settings": ">=0.11.3 <1.0.0"
29
29
  },