@apexnative/navigation 1.0.0-alpha.5 → 1.0.0-alpha.6

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.
Files changed (182) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README.md +1 -1
  3. package/android/CLAUDE.md +14 -12
  4. package/android/CORE.md +9 -6
  5. package/android/src/main/java/dev/apexnative/navigation/NavigationActivity.kt +36 -5
  6. package/android/src/main/java/dev/apexnative/navigation/options/BottomTabsOptions.kt +13 -8
  7. package/android/src/main/java/dev/apexnative/navigation/react/NavigationTurboModule.kt +3 -3
  8. package/android/src/main/java/dev/apexnative/navigation/react/ReloadCoordinator.kt +0 -2
  9. package/android/src/main/java/dev/apexnative/navigation/react/ScreenEnvironment.kt +177 -0
  10. package/android/src/main/java/dev/apexnative/navigation/react/ScreenRegions.kt +12 -49
  11. package/android/src/main/java/dev/apexnative/navigation/react/ScrollEvents.kt +49 -128
  12. package/android/src/main/java/dev/apexnative/navigation/safearea/SafeAreaView.kt +6 -6
  13. package/android/src/main/java/dev/apexnative/navigation/utils/ViewExtensions.kt +0 -13
  14. package/android/src/main/java/dev/apexnative/navigation/viewcontrollers/arrangement/ArrangementController.kt +9 -7
  15. package/android/src/main/java/dev/apexnative/navigation/viewcontrollers/bottomtabs/BottomTabsCollapseBehavior.kt +5 -3
  16. package/android/src/main/java/dev/apexnative/navigation/viewcontrollers/bottomtabs/BottomTabsController.kt +13 -10
  17. package/android/src/main/java/dev/apexnative/navigation/viewcontrollers/bottomtabs/CustomTabRowGeometry.kt +22 -0
  18. package/android/src/main/java/dev/apexnative/navigation/viewcontrollers/bottomtabs/TabsRoom.kt +0 -5
  19. package/android/src/main/java/dev/apexnative/navigation/viewcontrollers/component/ComponentViewController.kt +7 -8
  20. package/android/src/main/java/dev/apexnative/navigation/viewcontrollers/component/ScreenSafeArea.kt +29 -11
  21. package/android/src/main/java/dev/apexnative/navigation/viewcontrollers/externalcomponent/ExternalComponentViewController.kt +2 -6
  22. package/android/src/main/java/dev/apexnative/navigation/viewcontrollers/modal/ModalCoordinator.kt +20 -2
  23. package/android/src/main/java/dev/apexnative/navigation/viewcontrollers/modal/ModalSheet.kt +119 -8
  24. package/android/src/main/java/dev/apexnative/navigation/viewcontrollers/modal/ModalViews.kt +7 -0
  25. package/android/src/main/java/dev/apexnative/navigation/viewcontrollers/modal/SheetBack.kt +42 -0
  26. package/android/src/main/java/dev/apexnative/navigation/viewcontrollers/navigator/Navigator.kt +4 -0
  27. package/android/src/main/java/dev/apexnative/navigation/viewcontrollers/parent/ParentController.kt +3 -6
  28. package/android/src/main/java/dev/apexnative/navigation/viewcontrollers/stack/PreparedFrame.kt +3 -3
  29. package/android/src/main/java/dev/apexnative/navigation/viewcontrollers/stack/StackCommands.kt +2 -2
  30. package/android/src/main/java/dev/apexnative/navigation/viewcontrollers/stack/StackController.kt +4 -0
  31. package/android/src/main/java/dev/apexnative/navigation/viewcontrollers/stack/StackViews.kt +3 -0
  32. package/android/src/main/java/dev/apexnative/navigation/viewcontrollers/viewcontroller/ScrollEventListener.kt +6 -9
  33. package/android/src/main/java/dev/apexnative/navigation/views/animations/AnimationLayer.kt +73 -0
  34. package/android/src/main/java/dev/apexnative/navigation/views/animations/ValueInterpolation.kt +14 -0
  35. package/android/src/main/java/dev/apexnative/navigation/views/bottomtabs/BottomTabsLayout.kt +61 -2
  36. package/android/src/main/java/dev/apexnative/navigation/views/bottomtabs/CustomTabRow.kt +72 -10
  37. package/android/src/main/java/dev/apexnative/navigation/views/element/ElementTransitions.kt +9 -2
  38. package/android/src/main/java/dev/apexnative/navigation/views/element/animators/ElementPictures.kt +11 -0
  39. package/android/src/main/java/dev/apexnative/navigation/views/element/animators/FlightGeometry.kt +318 -25
  40. package/android/src/main/java/dev/apexnative/navigation/views/element/animators/ImageMatrixAnimator.kt +18 -20
  41. package/android/src/main/java/dev/apexnative/navigation/views/element/animators/PlainViewAnimator.kt +17 -25
  42. package/android/src/main/java/dev/apexnative/navigation/views/element/animators/ReactImageAnimator.kt +15 -22
  43. package/android/src/main/java/dev/apexnative/navigation/views/element/animators/SharedAnimatorFactory.kt +12 -9
  44. package/android/src/main/java/dev/apexnative/navigation/views/element/animators/TextChangeAnimator.kt +84 -35
  45. package/android/src/main/java/dev/apexnative/navigation/views/element/animators/ViewChangeAnimator.kt +49 -40
  46. package/docs-md/architecture/transitions.md +4 -2
  47. package/docs-md/containers/modals.md +2 -0
  48. package/docs-md/containers/overlays.md +1 -1
  49. package/docs-md/containers/side-menu.md +1 -1
  50. package/docs-md/containers/tabs.md +2 -0
  51. package/docs-md/flows/bottom-sheets.md +1 -1
  52. package/docs-md/fundamentals/starting-the-app.md +1 -1
  53. package/docs-md/help/glossary.md +2 -2
  54. package/docs-md/help/troubleshooting.md +21 -0
  55. package/docs-md/index.json +12 -0
  56. package/docs-md/migration/from-expo-router.md +1 -1
  57. package/docs-md/migration/from-react-native-navigation.md +1 -1
  58. package/docs-md/migration/from-react-navigation.md +2 -2
  59. package/docs-md/screen-ui/back-and-gestures.md +14 -0
  60. package/docs-md/screen-ui/bar-buttons.md +4 -4
  61. package/docs-md/screen-ui/search.md +1 -1
  62. package/docs-md/screen-ui/system-ui.md +16 -11
  63. package/docs-md/screen-ui/toolbar-and-fab.md +2 -2
  64. package/docs-md/screen-ui/top-bar.md +8 -4
  65. package/ios/Animations/ANNFrameDriver.mm +2 -0
  66. package/ios/Animations/Elements/ANNSharedElementFlight.mm +70 -4
  67. package/ios/Animations/Interpolators/ANNInterpolate.h +2 -30
  68. package/ios/Animations/Interpolators/ANNTransformParts.h +48 -0
  69. package/ios/Animations/Interpolators/ANNTransformParts.mm +507 -0
  70. package/ios/Animations/Interpolators/ANNViewTracks.h +6 -4
  71. package/ios/Animations/Interpolators/ANNViewTracks.mm +49 -9
  72. package/ios/CLAUDE.md +17 -15
  73. package/ios/CORE.md +24 -20
  74. package/ios/Contract/ANNCommandRunner.h +8 -7
  75. package/ios/Contract/ANNCommandRunner.mm +21 -27
  76. package/ios/Contract/ANNLayoutNode.h +3 -3
  77. package/ios/Contract/ANNLayoutReader.h +3 -3
  78. package/ios/Core/ANNJavaScriptCalls.h +11 -12
  79. package/ios/Core/ANNJavaScriptCalls.mm +7 -16
  80. package/ios/Core/ANNReloadCoordinator.mm +4 -8
  81. package/ios/Core/ApexNavigation+Internal.h +1 -1
  82. package/ios/Layouts/Arrangement/ANNArrangementState.h +2 -17
  83. package/ios/Layouts/Arrangement/ANNArrangementState.mm +0 -38
  84. package/ios/Layouts/Arrangement/ANNArrangementViewController.mm +4 -4
  85. package/ios/Layouts/Screen/ANNComponentViewController.h +2 -2
  86. package/ios/Layouts/Screen/ANNComponentViewController.mm +9 -22
  87. package/ios/Layouts/Screen/ANNPreviewInteraction.h +7 -4
  88. package/ios/Layouts/Screen/ANNPreviewInteraction.mm +72 -10
  89. package/ios/Layouts/Screen/ANNScreenEnvironment.h +63 -0
  90. package/ios/Layouts/Screen/ANNScreenEnvironment.mm +181 -0
  91. package/ios/Layouts/Screen/ANNScreenRegions.h +3 -18
  92. package/ios/Layouts/Screen/ANNScreenRegions.mm +0 -38
  93. package/ios/Layouts/Screen/ANNScreenSafeArea.h +4 -9
  94. package/ios/Layouts/Screen/ANNScreenSafeArea.mm +14 -16
  95. package/ios/Layouts/Stack/ANNPreviewPush.h +7 -6
  96. package/ios/Layouts/Stack/ANNPreviewPush.mm +57 -5
  97. package/ios/Layouts/Tabs/ANNBottomTabsAccessoryView.h +12 -1
  98. package/ios/Layouts/Tabs/ANNBottomTabsAccessoryView.mm +23 -0
  99. package/ios/Layouts/Tabs/ANNBottomTabsController.mm +2 -1
  100. package/ios/Layouts/Tabs/ANNBottomTabsCustomRow.mm +8 -3
  101. package/ios/Layouts/Tabs/ANNBottomTabsPresenter.h +4 -0
  102. package/ios/Layouts/Tabs/ANNBottomTabsPresenter.mm +123 -36
  103. package/ios/Layouts/Tabs/ANNTabsDesign.h +6 -5
  104. package/ios/Layouts/Tabs/ANNTabsDesign.mm +9 -1
  105. package/ios/Layouts/Tabs/UITabBar+utils.h +5 -5
  106. package/ios/Layouts/Tabs/UITabBar+utils.mm +32 -13
  107. package/ios/Options/ANNBottomTabsOptions.h +2 -0
  108. package/ios/Options/ANNBottomTabsOptions.mm +1 -0
  109. package/ios/Options/ANNOptions.h +18 -0
  110. package/ios/Options/ANNOptions.mm +112 -1
  111. package/ios/Options/ANNOptionsReader.mm +110 -0
  112. package/ios/Options/Params/ANNParam.h +15 -0
  113. package/ios/Options/Params/ANNParam.mm +61 -0
  114. package/ios/Options/Params/Color.h +3 -0
  115. package/ios/Options/Params/Color.mm +21 -0
  116. package/ios/Options/Params/Image.h +4 -0
  117. package/ios/Options/Params/Image.mm +20 -0
  118. package/ios/React/ANNReactView.mm +6 -25
  119. package/ios/React/ANNSafeAreaViewComponentView.mm +26 -15
  120. package/ios/React/ANNSurfaceHostingView.h +6 -0
  121. package/ios/React/ANNSurfaceHostingView.mm +116 -0
  122. package/ios/TopBar/ANNBackButtonPresenter.mm +6 -5
  123. package/ios/TopBar/ANNBarAppearance.h +2 -1
  124. package/ios/TopBar/ANNBarAppearance.mm +111 -30
  125. package/ios/TopBar/ANNBarBackgroundComponent.mm +16 -0
  126. package/ios/TopBar/ANNBarButtonComponentView.h +4 -4
  127. package/ios/TopBar/ANNBarButtonComponentView.mm +1 -1
  128. package/ios/TopBar/ANNBarButtons.h +5 -3
  129. package/ios/TopBar/ANNBarButtons.mm +186 -17
  130. package/ios/TopBar/ANNLargeTitlePresenter.mm +24 -4
  131. package/ios/TopBar/ANNMainList.h +3 -0
  132. package/ios/TopBar/ANNMainList.mm +4 -0
  133. package/ios/TopBar/ANNScrollEdgeEffects.h +22 -6
  134. package/ios/TopBar/ANNScrollEdgeEffects.mm +123 -16
  135. package/ios/TopBar/ANNSearchPresenter.mm +2 -2
  136. package/ios/TopBar/ANNSearchResultsViewController.mm +5 -5
  137. package/ios/TopBar/ANNTopBarPresenter.h +3 -2
  138. package/ios/TopBar/ANNTopBarPresenter.mm +95 -22
  139. package/ios/TurboModules/ANNTurboModule.mm +20 -16
  140. package/lib/module/ARCHITECTURE.md +8 -4
  141. package/lib/module/api/hooks/useSafeAreaInsets.js +4 -3
  142. package/lib/module/api/hooks/useSafeAreaInsets.js.map +1 -1
  143. package/lib/module/api/options/OptionsChain.js +2 -2
  144. package/lib/module/engine/commands.js +21 -1
  145. package/lib/module/engine/commands.js.map +1 -1
  146. package/lib/module/engine/screens.js +29 -4
  147. package/lib/module/engine/screens.js.map +1 -1
  148. package/lib/typescript/api/app/createNavigation.d.ts +3 -3
  149. package/lib/typescript/api/hooks/useSafeAreaInsets.d.ts +4 -3
  150. package/lib/typescript/api/hooks/useSafeAreaInsets.d.ts.map +1 -1
  151. package/lib/typescript/api/options/OptionsChain.d.ts +2 -2
  152. package/lib/typescript/engine/commands.d.ts.map +1 -1
  153. package/lib/typescript/engine/screens.d.ts +20 -6
  154. package/lib/typescript/engine/screens.d.ts.map +1 -1
  155. package/lib/typescript/interfaces/options/animations.d.ts +12 -7
  156. package/lib/typescript/interfaces/options/animations.d.ts.map +1 -1
  157. package/lib/typescript/interfaces/options/bottomTabs.d.ts +18 -5
  158. package/lib/typescript/interfaces/options/bottomTabs.d.ts.map +1 -1
  159. package/lib/typescript/interfaces/options/buttons.d.ts +8 -8
  160. package/lib/typescript/interfaces/options/system.d.ts +8 -5
  161. package/lib/typescript/interfaces/options/system.d.ts.map +1 -1
  162. package/lib/typescript/interfaces/options/toolbar.d.ts +2 -2
  163. package/lib/typescript/interfaces/options/topBar.d.ts +32 -29
  164. package/lib/typescript/interfaces/options/topBar.d.ts.map +1 -1
  165. package/package.json +1 -1
  166. package/src/ARCHITECTURE.md +8 -4
  167. package/src/api/app/createNavigation.ts +3 -3
  168. package/src/api/hooks/useSafeAreaInsets.ts +4 -3
  169. package/src/api/options/OptionsChain.ts +2 -2
  170. package/src/engine/commands.ts +30 -6
  171. package/src/engine/screens.tsx +29 -8
  172. package/src/interfaces/options/animations.ts +12 -7
  173. package/src/interfaces/options/bottomTabs.ts +18 -5
  174. package/src/interfaces/options/buttons.ts +8 -8
  175. package/src/interfaces/options/system.ts +8 -5
  176. package/src/interfaces/options/toolbar.ts +2 -2
  177. package/src/interfaces/options/topBar.ts +32 -29
  178. package/android/src/main/java/dev/apexnative/navigation/react/ArrangementStates.kt +0 -42
  179. package/android/src/main/java/dev/apexnative/navigation/react/ScreenInsets.kt +0 -70
  180. package/android/src/main/java/dev/apexnative/navigation/viewcontrollers/bottomtabs/CustomTabRowPlacer.kt +0 -223
  181. package/ios/Layouts/Screen/ANNScreenInsets.h +0 -30
  182. package/ios/Layouts/Screen/ANNScreenInsets.mm +0 -70
@@ -2,7 +2,10 @@
2
2
 
3
3
  @implementation ANNTabsDesign
4
4
 
5
- // Read once: the Info.plist of a running app doesn't change.
5
+ // Read once: the Info.plist of a running app doesn't change. iOS 26 keeps the earlier design for the key; iOS 27 keeps
6
+ // it only for an app built with an SDK before iOS 27 and ignores it for one built with the iOS 27 SDK (an app linked
7
+ // against the iOS 26 SDK keeps the earlier design on iOS 27, one linked against the iOS 27 SDK gets the glass). The
8
+ // core is compiled with the app, so the SDK it is compiled with is the app's.
6
9
  + (BOOL)isCompatibilityMode {
7
10
  static BOOL compatibility;
8
11
  static dispatch_once_t once;
@@ -11,6 +14,11 @@
11
14
  id value = NSBundle.mainBundle.infoDictionary[@"UIDesignRequiresCompatibility"];
12
15
  compatibility = [value respondsToSelector:@selector(boolValue)] && [value boolValue];
13
16
  }
17
+ #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 270000
18
+ if (@available(iOS 27.0, *)) {
19
+ compatibility = NO;
20
+ }
21
+ #endif
14
22
  });
15
23
  return compatibility;
16
24
  }
@@ -4,18 +4,18 @@
4
4
 
5
5
  /**
6
6
  * The button of an item in the tab bar. UIKit has no public API for it: this reads the private
7
- * `view` of the item, and is nil when UIKit has no such view (or the item none).
7
+ * `view` of the item, the core's one private read of the bar, and is nil when the item has no
8
+ * button (out of the bar, or before its layout). When UIKit has no such key any more, DEBUG logs it
9
+ * once.
8
10
  */
9
11
  - (UIView *)viewOfItem:(UITabBarItem *)item;
10
12
 
11
- - (UIView *)tabBarItemViewAtIndex:(NSUInteger)index;
12
-
13
13
  - (void)removeTabBarItemTitles;
14
14
 
15
15
  /**
16
16
  * Icons in the middle of the buttons of this tab bar, for items without titles: before iOS 26 (and
17
- * in its compatibility mode) a button keeps the room of its title; the iOS 26 design centers the
18
- * icons itself, and this does nothing there. UIKit has no public API for it: the layout of the
17
+ * in its compatibility mode, `ANNTabsDesign`) a button keeps the room of its title; the iOS 26
18
+ * design centers the icons itself, and this does nothing there. UIKit has no public API for it: the layout of the
19
19
  * private button class changes once for the app, and only tab bars with centered images move their
20
20
  * icons (and badges). `NO` gives the buttons the layout of UIKit back.
21
21
  */
@@ -1,5 +1,7 @@
1
1
  #import "UITabBar+utils.h"
2
+ #import "ANNTabsDesign.h"
2
3
  #import "UIView+Utils.h"
4
+ #import <React/RCTLog.h>
3
5
  #import <objc/runtime.h>
4
6
 
5
7
  static const void *ANNItemImagesCenteredKey = &ANNItemImagesCenteredKey;
@@ -37,17 +39,16 @@ static void ANNTabBarButtonLayoutSubviews(UIView *button, SEL _cmd) {
37
39
  badge.center = CGPointMake(badge.center.x, badge.center.y + offset);
38
40
  }
39
41
 
40
- // The design of iOS 26 centers the icon of an item without a title itself; in its compatibility
41
- // mode (UIDesignRequiresCompatibility) the tab bar is drawn as before.
42
+ // The design of iOS 26 centers the icon of an item without a title itself; the design before it
43
+ // (before iOS 26, and the compatibility mode where UIKit keeps it) keeps the title's room.
42
44
  static BOOL ANNTabBarButtonsKeepTitleRoom(void) {
43
- if (@available(iOS 26.0, *)) {
44
- return [[NSBundle.mainBundle objectForInfoDictionaryKey:@"UIDesignRequiresCompatibility"]
45
- boolValue];
46
- }
47
- return YES;
45
+ return !ANNTabsDesign.isGlass;
48
46
  }
49
47
 
50
- // Once for the app; the buttons of other tab bars keep the layout of UIKit.
48
+ // Once for the app; the buttons of other tab bars keep the layout of UIKit. No public API does this: in the
49
+ // compatibility mode of iOS 26 UIKit ignores `imageInsets` and a symbol's baseline offset, and a symbol drawn into a
50
+ // taller bitmap is scaled down and stops being a symbol. `badgePositionAdjustment` would move the badge alone, so the
51
+ // button's layout moves both.
51
52
  static void ANNInstallTabBarButtonLayout(void) {
52
53
  static dispatch_once_t once;
53
54
  dispatch_once(&once, ^{
@@ -65,18 +66,36 @@ static void ANNInstallTabBarButtonLayout(void) {
65
66
  });
66
67
  }
67
68
 
69
+ // Once per app run, in DEBUG: the tab items' buttons can't be found any more.
70
+ static void ANNWarnNoButtonOfItem(void) {
71
+ #if DEBUG
72
+ static dispatch_once_t once;
73
+ dispatch_once(&once, ^{
74
+ RCTLogWarn(@"[ApexNavigation] This iOS version gives no button for a tab item: "
75
+ @"bottomTab.testID on the tab buttons, the dot before iOS 26 and the long "
76
+ @"press on a tab don't apply.");
77
+ });
78
+ #endif
79
+ }
80
+
68
81
  @implementation UITabBar (utils)
69
82
 
70
83
  - (UIView *)viewOfItem:(UITabBarItem *)item {
84
+ if (!item) {
85
+ return nil;
86
+ }
87
+ // An item out of the bar (in More, or before the bar's first layout) has no button: that is no failure. Only an
88
+ // item without the `view` key, or with something else under it, says that UIKit changed.
71
89
  if (![item respondsToSelector:NSSelectorFromString(@"view")]) {
90
+ ANNWarnNoButtonOfItem();
72
91
  return nil;
73
92
  }
74
93
  id view = [item valueForKey:@"view"];
75
- return [view isKindOfClass:UIView.class] ? view : nil;
76
- }
77
-
78
- - (UIView *)tabBarItemViewAtIndex:(NSUInteger)index {
79
- return index < self.items.count ? [self viewOfItem:self.items[index]] : nil;
94
+ if (view && ![view isKindOfClass:UIView.class]) {
95
+ ANNWarnNoButtonOfItem();
96
+ return nil;
97
+ }
98
+ return view;
80
99
  }
81
100
 
82
101
  - (void)removeTabBarItemTitles {
@@ -11,6 +11,8 @@ NS_ASSUME_NONNULL_BEGIN
11
11
 
12
12
  @property(nonatomic, strong) Bool *visible;
13
13
  @property(nonatomic, strong) Bool *animate;
14
+ /// `'platform'` or `'none'`; read on Android only: the system switches tabs at once.
15
+ @property(nonatomic, strong) Text *switchAnimation;
14
16
  /// The index of the tab to select; a whole number (the fraction is dropped).
15
17
  @property(nonatomic, strong) Double *currentTabIndex;
16
18
  @property(nonatomic, strong) Text *currentTabId;
@@ -6,6 +6,7 @@
6
6
  return @[
7
7
  [ANNOptionField boolField:@"visible"],
8
8
  [ANNOptionField boolField:@"animate"],
9
+ [ANNOptionField enumField:@"switchAnimation" values:@[ @"platform", @"none" ]],
9
10
  [ANNOptionField doubleField:@"currentTabIndex"],
10
11
  [ANNOptionField textField:@"currentTabId"],
11
12
  [ANNOptionField textField:@"testID"],
@@ -20,6 +20,13 @@ NS_ASSUME_NONNULL_BEGIN
20
20
  /// The group of options under `key`: nil when it is not an object (`null` included), which reads as an empty group.
21
21
  NSDictionary *_Nullable ANNOptionsDictionary(NSDictionary *_Nullable dict, NSString *key);
22
22
 
23
+ /// Two values a group of options holds are the same: params and groups by `isSameValueAs:`, arrays item by item,
24
+ /// anything else as `ANNJSONValuesSame` says. nil is the same only as nil (an unset array is not an empty one).
25
+ BOOL ANNOptionValuesSame(id _Nullable a, id _Nullable b);
26
+
27
+ /// A hash of a value `ANNOptionValuesSame` compares: values that are the same have the same hash.
28
+ NSUInteger ANNOptionValueHash(id _Nullable value);
29
+
23
30
  #if DEBUG
24
31
  /// Development only: checks the field table of `root` and of every group class reached through its group and
25
32
  /// group-array fields.
@@ -57,6 +64,17 @@ void ANNCheckOptionClassesFrom(Class root);
57
64
  /// These over a copy of `defaults`; neither changes.
58
65
  - (instancetype)withDefault:(nullable ANNOptions *)defaults;
59
66
 
67
+ /// A group of the same class with the same options, field by field at any depth: two reads of the same JSON, a copy,
68
+ /// two resolutions of the same layers. The fields are the field table's; a module's group (an empty table) compares
69
+ /// every property of an options kind it declares. A value that is nil is the same only as nil.
70
+ ///
71
+ /// Not `isEqual:`: a group changes in place (a merge, the pick of a menu's item), so a hash by value would move under
72
+ /// a set or a dictionary that holds it. `==` and `isEqual:` stay identity.
73
+ - (BOOL)isSameValueAs:(nullable ANNOptions *)other;
74
+
75
+ /// A hash consistent with `isSameValueAs:`; it changes when the group does.
76
+ - (NSUInteger)valueHash;
77
+
60
78
  @end
61
79
 
62
80
  NS_ASSUME_NONNULL_END
@@ -11,7 +11,6 @@ NSDictionary *ANNOptionsDictionary(NSDictionary *dict, NSString *key) {
11
11
  return [value isKindOfClass:NSDictionary.class] ? value : nil;
12
12
  }
13
13
 
14
- #if DEBUG
15
14
  // The kinds of property a group holds options in.
16
15
  static BOOL ANNIsOptionClass(Class cls) {
17
16
  return [cls isSubclassOfClass:ANNParam.class] || [cls isSubclassOfClass:ANNOptions.class] ||
@@ -33,6 +32,7 @@ static Class ANNPropertyClass(objc_property_t property) {
33
32
  return name ? NSClassFromString(name) : nil;
34
33
  }
35
34
 
35
+ #if DEBUG
36
36
  // There is no iOS test target: in development each group of the core checks once that its table names every property
37
37
  // that holds options, and that every field of the table has its property (the stand-in for the whole-tree test of
38
38
  // Android). A missing field would be neither read, merged, copied nor given defaults.
@@ -86,6 +86,94 @@ static NSArray<ANNOptionField *> *ANNFieldsOf(Class cls) {
86
86
  }
87
87
  }
88
88
 
89
+ // The properties that hold the options of a group, asked once per class: its field table's, or for a module's group
90
+ // (its own read and merge, an empty table) every property of an options kind its classes declare up to `ANNOptions`.
91
+ static NSArray<NSString *> *ANNValuePropertiesOf(Class cls) {
92
+ static NSMutableDictionary<NSString *, NSArray<NSString *> *> *propertiesByClass;
93
+ NSString *name = NSStringFromClass(cls);
94
+ @synchronized(ANNOptions.class) {
95
+ if (!propertiesByClass) {
96
+ propertiesByClass = [NSMutableDictionary new];
97
+ }
98
+ NSArray<NSString *> *names = propertiesByClass[name];
99
+ if (names) {
100
+ return names;
101
+ }
102
+ }
103
+ NSArray<ANNOptionField *> *fields = ANNFieldsOf(cls);
104
+ NSMutableArray<NSString *> *found = [NSMutableArray new];
105
+ if (fields.count) {
106
+ for (ANNOptionField *field in fields) {
107
+ [found addObject:field.property];
108
+ }
109
+ } else {
110
+ NSSet<NSString *> *inherited =
111
+ [NSSet setWithArray:@[ @"description", @"debugDescription" ]];
112
+ for (Class current = cls; current && current != ANNOptions.class;
113
+ current = class_getSuperclass(current)) {
114
+ unsigned int count = 0;
115
+ objc_property_t *properties = class_copyPropertyList(current, &count);
116
+ for (unsigned int i = 0; i < count; i++) {
117
+ NSString *property = @(property_getName(properties[i]));
118
+ Class propertyClass = ANNPropertyClass(properties[i]);
119
+ if (propertyClass && ANNIsOptionClass(propertyClass) &&
120
+ ![inherited containsObject:property] && ![found containsObject:property]) {
121
+ [found addObject:property];
122
+ }
123
+ }
124
+ free(properties);
125
+ }
126
+ }
127
+ NSArray<NSString *> *names = [found copy];
128
+ @synchronized(ANNOptions.class) {
129
+ propertiesByClass[name] = names;
130
+ }
131
+ return names;
132
+ }
133
+
134
+ BOOL ANNOptionValuesSame(id a, id b) {
135
+ if (a == b) {
136
+ return YES;
137
+ }
138
+ if ([a isKindOfClass:ANNParam.class]) {
139
+ return [b isKindOfClass:ANNParam.class] && [(ANNParam *)a isSameValueAs:b];
140
+ }
141
+ if ([a isKindOfClass:ANNOptions.class]) {
142
+ return [b isKindOfClass:ANNOptions.class] && [(ANNOptions *)a isSameValueAs:b];
143
+ }
144
+ if ([a isKindOfClass:NSArray.class]) {
145
+ if (![b isKindOfClass:NSArray.class] || [a count] != [b count]) {
146
+ return NO;
147
+ }
148
+ NSArray *items = b;
149
+ NSUInteger index = 0;
150
+ for (id item in (NSArray *)a) {
151
+ if (!ANNOptionValuesSame(item, items[index++])) {
152
+ return NO;
153
+ }
154
+ }
155
+ return YES;
156
+ }
157
+ return ANNJSONValuesSame(a, b);
158
+ }
159
+
160
+ NSUInteger ANNOptionValueHash(id value) {
161
+ if ([value isKindOfClass:ANNParam.class]) {
162
+ return [(ANNParam *)value valueHash];
163
+ }
164
+ if ([value isKindOfClass:ANNOptions.class]) {
165
+ return [(ANNOptions *)value valueHash];
166
+ }
167
+ if ([value isKindOfClass:NSArray.class]) {
168
+ NSUInteger hash = [value count];
169
+ for (id item in value) {
170
+ hash = hash * 31 + ANNOptionValueHash(item);
171
+ }
172
+ return hash;
173
+ }
174
+ return ANNJSONValueHash(value);
175
+ }
176
+
89
177
  #if DEBUG
90
178
  // Runs the check on `root` and on every class reached through its group and group-array fields, so a class that only
91
179
  // an array holds (a button, an action of a fab, a token of the search bar) is checked although no object of it is made.
@@ -326,4 +414,27 @@ static NSArray *ANNCopyItems(NSArray *items) {
326
414
  return result;
327
415
  }
328
416
 
417
+ - (BOOL)isSameValueAs:(ANNOptions *)other {
418
+ if (other == self) {
419
+ return YES;
420
+ }
421
+ if (other.class != self.class) {
422
+ return NO;
423
+ }
424
+ for (NSString *property in ANNValuePropertiesOf(self.class)) {
425
+ if (!ANNOptionValuesSame([self valueForKey:property], [other valueForKey:property])) {
426
+ return NO;
427
+ }
428
+ }
429
+ return YES;
430
+ }
431
+
432
+ - (NSUInteger)valueHash {
433
+ NSUInteger hash = (NSUInteger)(__bridge void *)self.class;
434
+ for (NSString *property in ANNValuePropertiesOf(self.class)) {
435
+ hash = hash * 31 + ANNOptionValueHash([self valueForKey:property]);
436
+ }
437
+ return hash;
438
+ }
439
+
329
440
  @end
@@ -1,12 +1,121 @@
1
1
  #import "ANNOptionsReader.h"
2
2
  #import "ANNAssert.h"
3
3
  #import "ANNNavigationOptions.h"
4
+ #if DEBUG
5
+ #import <React/RCTLog.h>
6
+ #endif
4
7
 
5
8
  // The parse runs on the main queue, one tree at a time: the path and the first failure are its state. A group read
6
9
  // outside a parse (a module that reads its own JSON) finds an empty path and keeps no failure.
7
10
  static NSMutableArray<NSString *> *ANNPathComponents;
8
11
  static NSString *ANNFirstFailure;
9
12
 
13
+ #if DEBUG
14
+ // A deep mutable copy of `json` with `value` at `path` (keys, and indexes of arrays); nil `value` removes the key.
15
+ static id ANNJSONWith(id json, NSArray *path, id value) {
16
+ if (path.count == 0) {
17
+ return value;
18
+ }
19
+ NSArray *rest = [path subarrayWithRange:NSMakeRange(1, path.count - 1)];
20
+ if ([json isKindOfClass:NSArray.class]) {
21
+ NSMutableArray *items = [json mutableCopy];
22
+ NSUInteger index = [path[0] unsignedIntegerValue];
23
+ items[index] = ANNJSONWith(items[index], rest, value);
24
+ return items;
25
+ }
26
+ NSMutableDictionary *fields = [json mutableCopy];
27
+ id inner = ANNJSONWith(fields[path[0]], rest, value);
28
+ if (inner) {
29
+ fields[path[0]] = inner;
30
+ } else {
31
+ [fields removeObjectForKey:path[0]];
32
+ }
33
+ return fields;
34
+ }
35
+
36
+ // There is no iOS test target: in development the value equality of the options (`isSameValueAs:`) checks itself
37
+ // once on a tree with a value of each kind: two reads, a copy and a merge give the same options and the same hash, and
38
+ // a change of one value at any depth gives other options. A module's group (the menu) compares by its properties.
39
+ static void ANNCheckSameValues(void) {
40
+ NSDictionary *button = @{
41
+ @"id" : @"save",
42
+ @"text" : @"Save",
43
+ @"icon" : @{@"system" : @"star"},
44
+ @"enabled" : @YES,
45
+ @"badge" : @1,
46
+ @"fontSize" : @15,
47
+ @"menu" : @{
48
+ @"title" : @"More",
49
+ @"items" : @[ @{@"id" : @"details", @"title" : @"Details", @"checked" : @YES} ],
50
+ },
51
+ };
52
+ NSDictionary *json = @{
53
+ @"topBar" : @{
54
+ @"title" : @{@"text" : @"Home", @"color" : @(0xFF112233)},
55
+ @"rightButtonColor" :
56
+ @{@"dynamic" : @{@"light" : @(0xFF000000), @"dark" : @(0xFFFFFFFF)}},
57
+ @"leftButtonColor" : NSNull.null,
58
+ @"rightButtons" : @[ button ],
59
+ @"leftButtons" : @[],
60
+ @"height" : @44,
61
+ },
62
+ @"keyCommands" : @[ @{@"input" : @"k", @"modifiers" : @[ @"command" ]} ],
63
+ };
64
+ ANNNavigationOptions *options = [[ANNNavigationOptions alloc] initWithDict:json];
65
+ ANNNavigationOptions *again = [[ANNNavigationOptions alloc] initWithDict:json];
66
+ ANNNavigationOptions *copy = [options copy];
67
+ ANNNavigationOptions *overEmpty = [options withDefault:[ANNNavigationOptions new]];
68
+ for (ANNNavigationOptions *same in @[ again, copy, overEmpty ]) {
69
+ if (![options isSameValueAs:same] || options.valueHash != same.valueHash) {
70
+ RCTLogError(@"[ApexNavigation] options read, copied or resolved from the same JSON are "
71
+ @"not the same value");
72
+ }
73
+ }
74
+ // Each change: the path of one value and its new value; an unset key is not the same as `null` or `[]`.
75
+ NSDictionary<NSString *, NSArray *> *changes = @{
76
+ @"a text" : @[ @[ @"topBar", @"title", @"text" ], @"Profile" ],
77
+ @"a color" : @[ @[ @"topBar", @"title", @"color" ], @(0xFF112234) ],
78
+ @"a side of a color pair" :
79
+ @[ @[ @"topBar", @"rightButtonColor", @"dynamic", @"dark" ], @(0xFFEEEEEE) ],
80
+ @"a number" : @[ @[ @"topBar", @"height" ], @45 ],
81
+ @"an image" : @[ @[ @"topBar", @"rightButtons", @0, @"icon", @"system" ], @"heart" ],
82
+ @"a boolean" : @[ @[ @"topBar", @"rightButtons", @0, @"enabled" ], @NO ],
83
+ @"a boolean for a number" : @[ @[ @"topBar", @"rightButtons", @0, @"badge" ], @YES ],
84
+ @"a font" : @[ @[ @"topBar", @"rightButtons", @0, @"fontSize" ], @16 ],
85
+ @"a module's group" :
86
+ @[ @[ @"topBar", @"rightButtons", @0, @"menu", @"items", @0, @"checked" ], @NO ],
87
+ @"an object of an array" : @[ @[ @"keyCommands", @0, @"modifiers", @0 ], @"shift" ],
88
+ };
89
+ NSDictionary<NSString *, NSArray *> *removals = @{
90
+ @"a color of `null` and no color" : @[ @"topBar", @"leftButtonColor" ],
91
+ @"an empty array and no array" : @[ @"topBar", @"leftButtons" ],
92
+ };
93
+ NSMutableDictionary<NSString *, id> *variants = [NSMutableDictionary new];
94
+ [changes enumerateKeysAndObjectsUsingBlock:^(NSString *what, NSArray *change, BOOL *stop) {
95
+ variants[what] = ANNJSONWith(json, change[0], change[1]);
96
+ }];
97
+ [removals enumerateKeysAndObjectsUsingBlock:^(NSString *what, NSArray *path, BOOL *stop) {
98
+ variants[what] = ANNJSONWith(json, path, nil);
99
+ }];
100
+ [variants enumerateKeysAndObjectsUsingBlock:^(NSString *what, NSDictionary *variant,
101
+ BOOL *stop) {
102
+ ANNNavigationOptions *changed = [[ANNNavigationOptions alloc] initWithDict:variant];
103
+ if ([options isSameValueAs:changed] || [changed isSameValueAs:options]) {
104
+ RCTLogError(@"[ApexNavigation] options that differ in %@ are the same value", what);
105
+ }
106
+ }];
107
+ ANNNavigationOptions *merged = [options copy];
108
+ [merged mergeOptions:[[ANNNavigationOptions alloc]
109
+ initWithDict:@{@"topBar" : @{@"title" : @{@"text" : @"Profile"}}}]];
110
+ ANNNavigationOptions *read = [[ANNNavigationOptions alloc]
111
+ initWithDict:ANNJSONWith(json, @[ @"topBar", @"title", @"text" ], @"Profile")];
112
+ if (![merged isSameValueAs:read] || merged.valueHash != read.valueHash) {
113
+ RCTLogError(@"[ApexNavigation] merged options are not the same value as the same options "
114
+ @"read at once");
115
+ }
116
+ }
117
+ #endif
118
+
10
119
  @implementation ANNOptionsReader
11
120
 
12
121
  + (ANNNavigationOptions *)optionsFrom:(NSDictionary *)json unreadablePath:(NSString **)unreadablePath {
@@ -15,6 +124,7 @@ static NSString *ANNFirstFailure;
15
124
  static dispatch_once_t checkOnce;
16
125
  dispatch_once(&checkOnce, ^{
17
126
  ANNCheckOptionClassesFrom(ANNNavigationOptions.class);
127
+ ANNCheckSameValues();
18
128
  });
19
129
  #endif
20
130
  NSMutableArray<NSString *> *outerPath = ANNPathComponents;
@@ -8,6 +8,14 @@ BOOL ANNJSONIsBoolean(id _Nullable value);
8
8
  /// A JSON number that is finite: never a boolean, `NaN` or an infinity.
9
9
  BOOL ANNJSONIsNumber(id _Nullable value);
10
10
 
11
+ /// Two values as the options keep them are the same: a boolean is never the same as a number, arrays and objects
12
+ /// compare item by item, anything else (a string, a number, `null`, a color) by `isEqual:`. nil is the same only as
13
+ /// nil.
14
+ BOOL ANNJSONValuesSame(id _Nullable a, id _Nullable b);
15
+
16
+ /// A hash of a value `ANNJSONValuesSame` compares: values that are the same have the same hash.
17
+ NSUInteger ANNJSONValueHash(id _Nullable value);
18
+
11
19
  /// One value of the options as the JSON gave it. Immutable: trees of options may share it. `null` is a value too where
12
20
  /// the kind has an explicit "none" (a text, a color): it takes the place of what the layers under it gave.
13
21
  @interface ANNParam : NSObject
@@ -23,6 +31,13 @@ BOOL ANNJSONIsNumber(id _Nullable value);
23
31
  /// The options gave `null`.
24
32
  - (BOOL)isNull;
25
33
 
34
+ /// A param of the same class with the same value: two reads of the same JSON are the same, two params without a value
35
+ /// are the same. `==` and `isEqual:` stay identity.
36
+ - (BOOL)isSameValueAs:(nullable ANNParam *)other;
37
+
38
+ /// A hash consistent with `isSameValueAs:`.
39
+ - (NSUInteger)valueHash;
40
+
26
41
  @end
27
42
 
28
43
  NS_ASSUME_NONNULL_END
@@ -9,6 +9,56 @@ BOOL ANNJSONIsNumber(id value) {
9
9
  return [value isKindOfClass:NSNumber.class] && !ANNJSONIsBoolean(value) && isfinite([value doubleValue]);
10
10
  }
11
11
 
12
+ BOOL ANNJSONValuesSame(id a, id b) {
13
+ if (a == b) {
14
+ return YES;
15
+ }
16
+ if (!a || !b) {
17
+ return NO;
18
+ }
19
+ if ([a isKindOfClass:NSArray.class]) {
20
+ if (![b isKindOfClass:NSArray.class] || [a count] != [b count]) {
21
+ return NO;
22
+ }
23
+ NSArray *items = b;
24
+ __block BOOL same = YES;
25
+ [(NSArray *)a enumerateObjectsUsingBlock:^(id item, NSUInteger index, BOOL *stop) {
26
+ same = ANNJSONValuesSame(item, items[index]);
27
+ *stop = !same;
28
+ }];
29
+ return same;
30
+ }
31
+ if ([a isKindOfClass:NSDictionary.class]) {
32
+ if (![b isKindOfClass:NSDictionary.class] || [a count] != [b count]) {
33
+ return NO;
34
+ }
35
+ NSDictionary *fields = b;
36
+ __block BOOL same = YES;
37
+ [(NSDictionary *)a enumerateKeysAndObjectsUsingBlock:^(id key, id value, BOOL *stop) {
38
+ same = ANNJSONValuesSame(value, fields[key]);
39
+ *stop = !same;
40
+ }];
41
+ return same;
42
+ }
43
+ // `isEqual:` of NSNumber takes `true` for 1: a badge of `true` (a dot) and of `1` (a number) are not the same.
44
+ if (ANNJSONIsBoolean(a) != ANNJSONIsBoolean(b)) {
45
+ return NO;
46
+ }
47
+ return [a isEqual:b];
48
+ }
49
+
50
+ // An object's hash is its count only (Foundation's); an array mixes its items in, so lists of other values differ.
51
+ NSUInteger ANNJSONValueHash(id value) {
52
+ if ([value isKindOfClass:NSArray.class]) {
53
+ NSUInteger hash = [value count];
54
+ for (id item in value) {
55
+ hash = hash * 31 + ANNJSONValueHash(item);
56
+ }
57
+ return hash;
58
+ }
59
+ return [value hash];
60
+ }
61
+
12
62
  @implementation ANNParam
13
63
 
14
64
  - (instancetype)initWithValue:(id)value {
@@ -26,4 +76,15 @@ BOOL ANNJSONIsNumber(id value) {
26
76
  return _value == NSNull.null;
27
77
  }
28
78
 
79
+ - (BOOL)isSameValueAs:(ANNParam *)other {
80
+ if (other == self) {
81
+ return YES;
82
+ }
83
+ return other.class == self.class && ANNJSONValuesSame(_value, other.value);
84
+ }
85
+
86
+ - (NSUInteger)valueHash {
87
+ return ANNJSONValueHash(_value);
88
+ }
89
+
29
90
  @end
@@ -38,6 +38,9 @@ NS_ASSUME_NONNULL_BEGIN
38
38
  /// A pair that has only one of its sides.
39
39
  - (BOOL)isPartial;
40
40
 
41
+ /// The same color: a pair by its sides (its dynamic color is made anew at each read), anything else by its value.
42
+ - (BOOL)isSameValueAs:(nullable ANNParam *)other;
43
+
41
44
  @end
42
45
 
43
46
  NS_ASSUME_NONNULL_END
@@ -40,6 +40,27 @@
40
40
  return [super get];
41
41
  }
42
42
 
43
+ - (BOOL)isSameValueAs:(ANNParam *)other {
44
+ if (other == self) {
45
+ return YES;
46
+ }
47
+ if (other.class != self.class) {
48
+ return NO;
49
+ }
50
+ Color *color = (Color *)other;
51
+ if (_light || _dark || color.light || color.dark) {
52
+ return ANNJSONValuesSame(_light, color.light) && ANNJSONValuesSame(_dark, color.dark);
53
+ }
54
+ return [super isSameValueAs:other];
55
+ }
56
+
57
+ - (NSUInteger)valueHash {
58
+ if (_light || _dark) {
59
+ return _light.hash * 31 + _dark.hash;
60
+ }
61
+ return [super valueHash];
62
+ }
63
+
43
64
  - (UIColor *)withDefault:(UIColor *)defaultValue {
44
65
  if (!self.isPartial) {
45
66
  return self.hasValue ? self.get : defaultValue;
@@ -19,6 +19,10 @@ NS_ASSUME_NONNULL_BEGIN
19
19
  /// What the options name; nil without a value.
20
20
  @property(nonatomic, strong, readonly, nullable) ANNImageSource *source;
21
21
 
22
+ /// The same image the options name: a source by its `sourceKey` (what a file holds now isn't compared, so a file the
23
+ /// app writes again at the same path is the same value), an image that came already by identity.
24
+ - (BOOL)isSameValueAs:(nullable ANNParam *)other;
25
+
22
26
  @end
23
27
 
24
28
  NS_ASSUME_NONNULL_END
@@ -17,6 +17,26 @@
17
17
  return source ? [ANNOptionImages imageOf:source] : nil;
18
18
  }
19
19
 
20
+ - (BOOL)isSameValueAs:(ANNParam *)other {
21
+ if (other == self) {
22
+ return YES;
23
+ }
24
+ if (other.class != self.class) {
25
+ return NO;
26
+ }
27
+ ANNImageSource *source = self.source;
28
+ ANNImageSource *otherSource = ((Image *)other).source;
29
+ if (source || otherSource) {
30
+ return [source.sourceKey isEqualToString:otherSource.sourceKey];
31
+ }
32
+ return self.value == other.value;
33
+ }
34
+
35
+ - (NSUInteger)valueHash {
36
+ ANNImageSource *source = self.source;
37
+ return source ? source.sourceKey.hash : (NSUInteger)(__bridge void *)self.value;
38
+ }
39
+
20
40
  // A source that doesn't load is no image: the default then, as without a value.
21
41
  - (UIImage *)withDefault:(UIImage *)defaultValue {
22
42
  UIImage *image = self.hasValue ? self.get : nil;