hybrid-navigation 2.12.4 → 2.13.0-beta.0

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 (74) hide show
  1. package/README.md +63 -0
  2. package/android/src/main/java/com/reactnative/hybridnavigation/GardenModule.java +2 -2
  3. package/android/src/main/java/com/reactnative/hybridnavigation/NavigationModule.java +29 -30
  4. package/android/src/main/java/com/reactnative/hybridnavigation/Navigator.java +2 -3
  5. package/android/src/main/java/com/reactnative/hybridnavigation/ReactBridgeManager.java +4 -4
  6. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/DrawerNavigator.java +6 -6
  7. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +24 -33
  8. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java +22 -22
  9. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +8 -8
  10. package/ios/HybridNavigation/GlobalStyle.h +0 -8
  11. package/ios/HybridNavigation/GlobalStyle.m +2 -8
  12. package/ios/HybridNavigation/HBDUtils.h +5 -13
  13. package/ios/HybridNavigation/HBDUtils.m +2 -12
  14. package/ios/HybridNavigation/Navigator/HBDDrawerNavigator.h +0 -9
  15. package/ios/HybridNavigation/Navigator/HBDDrawerNavigator.m +91 -67
  16. package/ios/HybridNavigation/Navigator/HBDNavigatorRegistry.h +2 -7
  17. package/ios/HybridNavigation/Navigator/HBDNavigatorRegistry.m +28 -26
  18. package/ios/HybridNavigation/Navigator/HBDScreenNavigator.h +0 -9
  19. package/ios/HybridNavigation/Navigator/HBDScreenNavigator.m +127 -99
  20. package/ios/HybridNavigation/Navigator/HBDStackNavigator.h +0 -9
  21. package/ios/HybridNavigation/Navigator/HBDStackNavigator.m +199 -142
  22. package/ios/HybridNavigation/Navigator/HBDTabNavigator.h +0 -9
  23. package/ios/HybridNavigation/Navigator/HBDTabNavigator.m +144 -124
  24. package/ios/HybridNavigation/{Bridge → ReactBridge}/HBDEventEmitter.h +1 -11
  25. package/ios/HybridNavigation/{Bridge → ReactBridge}/HBDEventEmitter.m +4 -10
  26. package/ios/HybridNavigation/ReactBridge/HBDGardenModule.h +5 -0
  27. package/ios/HybridNavigation/ReactBridge/HBDGardenModule.m +128 -0
  28. package/ios/HybridNavigation/ReactBridge/HBDNavigationModule.h +6 -0
  29. package/ios/HybridNavigation/ReactBridge/HBDNavigationModule.m +237 -0
  30. package/ios/HybridNavigation/ReactBridge/HBDNavigator.h +20 -0
  31. package/ios/HybridNavigation/{Bridge → ReactBridge}/HBDReactBridgeManager.h +12 -20
  32. package/ios/HybridNavigation/{Bridge → ReactBridge}/HBDReactBridgeManager.m +91 -91
  33. package/ios/HybridNavigation/View/HBDBarButtonItem.h +0 -8
  34. package/ios/HybridNavigation/View/HBDBarButtonItem.m +1 -11
  35. package/ios/HybridNavigation/View/HBDNavigationBar.h +0 -8
  36. package/ios/HybridNavigation/View/HBDNavigationBar.m +3 -12
  37. package/ios/HybridNavigation/View/HBDReactTabBar.h +0 -8
  38. package/ios/HybridNavigation/View/HBDReactTabBar.m +1 -8
  39. package/ios/HybridNavigation/View/HBDRootView.h +0 -9
  40. package/ios/HybridNavigation/View/HBDRootView.m +0 -8
  41. package/ios/HybridNavigation/View/HBDTitleView.h +0 -9
  42. package/ios/HybridNavigation/View/HBDTitleView.m +1 -26
  43. package/ios/HybridNavigation/View/UITabBar+Badge.h +0 -8
  44. package/ios/HybridNavigation/View/UITabBar+Badge.m +0 -7
  45. package/ios/HybridNavigation/ViewController/HBDDrawerController.h +0 -8
  46. package/ios/HybridNavigation/ViewController/HBDDrawerController.m +2 -9
  47. package/ios/HybridNavigation/ViewController/HBDFadeAnimation.h +9 -0
  48. package/ios/HybridNavigation/ViewController/HBDFadeAnimation.m +22 -0
  49. package/ios/HybridNavigation/ViewController/HBDNavigationController.h +0 -8
  50. package/ios/HybridNavigation/ViewController/HBDNavigationController.m +17 -120
  51. package/ios/HybridNavigation/ViewController/HBDPopAnimation.h +0 -7
  52. package/ios/HybridNavigation/ViewController/HBDPopAnimation.m +1 -8
  53. package/ios/HybridNavigation/ViewController/HBDPushAnimation.h +0 -7
  54. package/ios/HybridNavigation/ViewController/HBDPushAnimation.m +1 -8
  55. package/ios/HybridNavigation/ViewController/HBDReactViewController.h +0 -8
  56. package/ios/HybridNavigation/ViewController/HBDReactViewController.m +59 -26
  57. package/ios/HybridNavigation/ViewController/HBDTabBarController.h +0 -8
  58. package/ios/HybridNavigation/ViewController/HBDTabBarController.m +12 -9
  59. package/ios/HybridNavigation/ViewController/HBDViewController+Garden.m +23 -33
  60. package/ios/HybridNavigation/ViewController/HBDViewController.h +1 -8
  61. package/ios/HybridNavigation/ViewController/HBDViewController.m +6 -23
  62. package/ios/HybridNavigation/ViewController/UINavigationController+HBD.h +0 -8
  63. package/ios/HybridNavigation/ViewController/UINavigationController+HBD.m +0 -8
  64. package/ios/HybridNavigation/ViewController/UIViewController+HBD.h +2 -16
  65. package/ios/HybridNavigation/ViewController/UIViewController+HBD.m +32 -46
  66. package/lib/Navigator.d.ts +25 -25
  67. package/lib/Navigator.js +116 -73
  68. package/package.json +4 -5
  69. package/src/Navigator.ts +96 -58
  70. package/ios/HybridNavigation/Bridge/HBDGardenModule.h +0 -14
  71. package/ios/HybridNavigation/Bridge/HBDGardenModule.m +0 -155
  72. package/ios/HybridNavigation/Bridge/HBDNavigationModule.h +0 -15
  73. package/ios/HybridNavigation/Bridge/HBDNavigationModule.m +0 -272
  74. package/ios/HybridNavigation/Navigator/HBDNavigator.h +0 -26
@@ -1,13 +1,7 @@
1
- //
2
- // GlobalStyle.m
3
- // HybridNavigation
4
- //
5
- // Created by Listen on 2018/2/8.
6
- // Copyright © 2018年 Listen. All rights reserved.
7
- //
8
-
9
1
  #import "GlobalStyle.h"
2
+
10
3
  #import "HBDUtils.h"
4
+
11
5
  #import <React/RCTUtils.h>
12
6
 
13
7
  @interface GlobalStyle ()
@@ -1,11 +1,3 @@
1
- //
2
- // HBDUtils.h
3
- // HybridNavigation
4
- //
5
- // Created by Listen on 2017/12/25.
6
- // Copyright © 2018年 Listen. All rights reserved.
7
- //
8
-
9
1
  #import <UIKit/UIKit.h>
10
2
  #import <objc/runtime.h>
11
3
 
@@ -29,13 +21,13 @@ UIKIT_STATIC_INLINE BOOL imageHasAlphaChannel(UIImage *image) {
29
21
  alpha == kCGImageAlphaPremultipliedLast);
30
22
  }
31
23
 
32
- UIKIT_STATIC_INLINE void hbd_exchangeImplementations(Class klass, SEL originalSelector, SEL swizzledSelector) {
33
- Method originalMethod = class_getInstanceMethod(klass, originalSelector);
34
- Method swizzledMethod = class_getInstanceMethod(klass, swizzledSelector);
24
+ UIKIT_STATIC_INLINE void hbd_exchangeImplementations(Class clazz, SEL originalSelector, SEL swizzledSelector) {
25
+ Method originalMethod = class_getInstanceMethod(clazz, originalSelector);
26
+ Method swizzledMethod = class_getInstanceMethod(clazz, swizzledSelector);
35
27
 
36
- BOOL success = class_addMethod(klass, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod));
28
+ BOOL success = class_addMethod(clazz, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod));
37
29
  if (success) {
38
- class_replaceMethod(klass, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod));
30
+ class_replaceMethod(clazz, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod));
39
31
  } else {
40
32
  method_exchangeImplementations(originalMethod, swizzledMethod);
41
33
  }
@@ -1,12 +1,5 @@
1
- //
2
- // HBDUtils.m
3
- // HybridNavigation
4
- //
5
- // Created by Listen on 2017/12/25.
6
- // Copyright © 2018年 Listen. All rights reserved.
7
- //
8
-
9
1
  #import "HBDUtils.h"
2
+
10
3
  #import <React/RCTConvert.h>
11
4
 
12
5
  @implementation HBDUtils
@@ -172,10 +165,7 @@
172
165
  }
173
166
 
174
167
  + (BOOL)isIphoneX {
175
- if (@available(iOS 11.0, *)) {
176
- return UIApplication.sharedApplication.keyWindow.safeAreaInsets.bottom > 0.0;
177
- }
178
- return NO;
168
+ return UIApplication.sharedApplication.keyWindow.safeAreaInsets.bottom > 0.0;
179
169
  }
180
170
 
181
171
  + (BOOL)isInCall {
@@ -1,12 +1,3 @@
1
- //
2
- // HBDDrawerNavigator.h
3
- // HybridNavigation
4
- //
5
- // Created by Listen on 2018/6/28.
6
- // Copyright © 2018年 Listen. All rights reserved.
7
- //
8
-
9
- #import <Foundation/Foundation.h>
10
1
  #import "HBDNavigator.h"
11
2
 
12
3
  @interface HBDDrawerNavigator : NSObject <HBDNavigator>
@@ -1,12 +1,5 @@
1
- //
2
- // HBDDrawerNavigator.m
3
- // HybridNavigation
4
- //
5
- // Created by Listen on 2018/6/28.
6
- // Copyright © 2018年 Listen. All rights reserved.
7
- //
8
-
9
1
  #import "HBDDrawerNavigator.h"
2
+
10
3
  #import "HBDReactBridgeManager.h"
11
4
 
12
5
  @implementation HBDDrawerNavigator
@@ -19,91 +12,122 @@
19
12
  return @[@"toggleMenu", @"openMenu", @"closeMenu"];
20
13
  }
21
14
 
22
- - (UIViewController *)createViewControllerWithLayout:(NSDictionary *)layout {
23
- NSDictionary *drawer = layout[self.name];
24
- NSArray *children = drawer[@"children"];
25
- if (children.count == 2) {
26
- NSDictionary *content = children[0];
27
- NSDictionary *menu = children[1];
28
-
29
- UIViewController *contentController = [[HBDReactBridgeManager get] controllerWithLayout:content];
30
- UIViewController *menuController = [[HBDReactBridgeManager get] controllerWithLayout:menu];
31
-
32
- if (contentController && menuController) {
33
- HBDDrawerController *drawerController = [[HBDDrawerController alloc] initWithContentViewController:contentController menuViewController:menuController];
34
- NSDictionary *options = drawer[@"options"];
35
- if (options) {
36
- NSNumber *maxDrawerWidth = options[@"maxDrawerWidth"];
37
- if (maxDrawerWidth) {
38
- [drawerController setMaxDrawerWidth:[maxDrawerWidth floatValue]];
39
- }
40
-
41
- NSNumber *minDrawerMargin = options[@"minDrawerMargin"];
42
- if (minDrawerMargin) {
43
- [drawerController setMinDrawerMargin:[minDrawerMargin floatValue]];
44
- }
45
-
46
- NSNumber *menuInteractive = options[@"menuInteractive"];
47
- if (menuInteractive) {
48
- drawerController.menuInteractive = [menuInteractive boolValue];
49
- }
50
- }
51
- return drawerController;
15
+ - (UIViewController *)viewControllerWithLayout:(NSDictionary *)layout {
16
+ NSDictionary *model = layout[self.name];
17
+ if (!model) {
18
+ return nil;
19
+ }
20
+
21
+ NSArray *children = model[@"children"];
22
+ if (children.count < 2) {
23
+ return nil;
24
+ }
25
+
26
+ UIViewController *content = [[HBDReactBridgeManager get] viewControllerWithLayout:children[0]];
27
+ UIViewController *menu = [[HBDReactBridgeManager get] viewControllerWithLayout:children[1]];
28
+
29
+ if (!content || !menu) {
30
+ return nil;
31
+ }
32
+
33
+ HBDDrawerController *drawer = [[HBDDrawerController alloc] initWithContentViewController:content menuViewController:menu];
34
+ NSDictionary *options = model[@"options"];
35
+
36
+ if (options) {
37
+ NSNumber *maxDrawerWidth = options[@"maxDrawerWidth"];
38
+ if (maxDrawerWidth) {
39
+ [drawer setMaxDrawerWidth:[maxDrawerWidth floatValue]];
40
+ }
41
+
42
+ NSNumber *minDrawerMargin = options[@"minDrawerMargin"];
43
+ if (minDrawerMargin) {
44
+ [drawer setMinDrawerMargin:[minDrawerMargin floatValue]];
45
+ }
46
+
47
+ NSNumber *menuInteractive = options[@"menuInteractive"];
48
+ if (menuInteractive) {
49
+ drawer.menuInteractive = [menuInteractive boolValue];
52
50
  }
53
51
  }
54
- return nil;
52
+
53
+ return drawer;
55
54
  }
56
55
 
57
- - (NSDictionary *)buildRouteGraphWithViewController:(UIViewController *)vc {
58
- if ([vc isKindOfClass:[HBDDrawerController class]]) {
59
- HBDDrawerController *drawer = (HBDDrawerController *) vc;
60
- NSDictionary *content = [[HBDReactBridgeManager get] buildRouteGraphWithViewController:drawer.contentController];
61
- NSDictionary *menu = [[HBDReactBridgeManager get] buildRouteGraphWithViewController:drawer.menuController];
62
- return @{
63
- @"layout": @"drawer",
64
- @"sceneId": vc.sceneId,
65
- @"children": @[content, menu],
66
- @"mode": [vc hbd_mode],
67
- };
56
+ - (NSDictionary *)routeGraphWithViewController:(UIViewController *)vc {
57
+ if (![vc isKindOfClass:[HBDDrawerController class]]) {
58
+ return nil;
68
59
  }
69
- return nil;
60
+
61
+ HBDDrawerController *drawer = (HBDDrawerController *) vc;
62
+ NSDictionary *content = [[HBDReactBridgeManager get] routeGraphWithViewController:drawer.contentController];
63
+ NSDictionary *menu = [[HBDReactBridgeManager get] routeGraphWithViewController:drawer.menuController];
64
+ return @{
65
+ @"layout": @"drawer",
66
+ @"sceneId": drawer.sceneId,
67
+ @"children": @[content, menu],
68
+ @"mode": [drawer hbd_mode],
69
+ };
70
70
  }
71
71
 
72
72
  - (HBDViewController *)primaryViewControllerWithViewController:(UIViewController *)vc {
73
- if ([vc isKindOfClass:[HBDDrawerController class]]) {
74
- HBDDrawerController *drawer = (HBDDrawerController *) vc;
75
- if (drawer.isMenuOpened) {
76
- return [[HBDReactBridgeManager get] primaryViewControllerWithViewController:drawer.menuController];
77
- } else {
78
- return [[HBDReactBridgeManager get] primaryViewControllerWithViewController:drawer.contentController];
79
- }
73
+ if (![vc isKindOfClass:[HBDDrawerController class]]) {
74
+ return nil;
75
+ }
76
+
77
+ HBDDrawerController *drawer = (HBDDrawerController *)vc;
78
+ if (drawer.isMenuOpened) {
79
+ return [[HBDReactBridgeManager get] primaryViewControllerWithViewController:drawer.menuController];
80
+ } else {
81
+ return [[HBDReactBridgeManager get] primaryViewControllerWithViewController:drawer.contentController];
80
82
  }
81
- return nil;
82
83
  }
83
84
 
84
- - (void)handleNavigationWithViewController:(UIViewController *)vc action:(NSString *)action extras:(NSDictionary *)extras resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject {
85
+ - (void)handleNavigationWithViewController:(UIViewController *)vc action:(NSString *)action extras:(NSDictionary *)extras callback:(RCTResponseSenderBlock)callback {
86
+ if (!vc.hbd_inViewHierarchy) {
87
+ callback(@[NSNull.null, @NO]);
88
+ return;
89
+ }
90
+
85
91
  HBDDrawerController *drawer = [vc drawerController];
86
92
  if (!drawer) {
87
- resolve(@(NO));
93
+ callback(@[NSNull.null, @NO]);
88
94
  return;
89
95
  }
90
96
 
91
97
  if (!drawer.hbd_viewAppeared) {
92
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t) (0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
93
- [self handleNavigationWithViewController:vc action:action extras:extras resolver:resolve rejecter:reject];
94
- });
98
+ [self performSelector:@selector(handleNavigation:) withObject:@{
99
+ @"viewController": vc,
100
+ @"action": action,
101
+ @"extras": extras,
102
+ @"callback": callback,
103
+ } afterDelay:0.05];
95
104
  return;
96
105
  }
106
+
107
+ callback(@[NSNull.null, @YES]);
97
108
 
98
109
  if ([action isEqualToString:@"toggleMenu"]) {
99
110
  [drawer toggleMenu];
100
- } else if ([action isEqualToString:@"openMenu"]) {
111
+ return;
112
+ }
113
+
114
+ if ([action isEqualToString:@"openMenu"]) {
101
115
  [drawer openMenu];
102
- } else if ([action isEqualToString:@"closeMenu"]) {
116
+ return;
117
+ }
118
+
119
+ if ([action isEqualToString:@"closeMenu"]) {
103
120
  [drawer closeMenu];
121
+ return;
104
122
  }
123
+ }
124
+
125
+ -(void)handleNavigation:(NSDictionary *)params {
126
+ [self handleNavigationWithViewController:params[@"viewController"] action:params[@"action"] extras:params[@"extras"] callback:params[@"callback"]];
127
+ }
105
128
 
106
- resolve(@(YES));
129
+ - (void)invalidate {
130
+ [NSObject cancelPreviousPerformRequestsWithTarget:self];
107
131
  }
108
132
 
109
133
  @end
@@ -1,10 +1,3 @@
1
- //
2
- // HBDNavigatorRegistry.h
3
- // HybridNavigation
4
- //
5
- // Created by 李生 on 2021/1/7.
6
- //
7
-
8
1
  #import "HBDNavigator.h"
9
2
 
10
3
  NS_ASSUME_NONNULL_BEGIN
@@ -23,6 +16,8 @@ NS_ASSUME_NONNULL_BEGIN
23
16
 
24
17
  - (NSArray<NSString *> *)allLayouts;
25
18
 
19
+ - (NSArray<id<HBDNavigator>> *)allNavigators;
20
+
26
21
  @end
27
22
 
28
23
  NS_ASSUME_NONNULL_END
@@ -1,25 +1,18 @@
1
- //
2
- // HBDNavigatorRegistry.m
3
- // HybridNavigation
4
- //
5
- // Created by 李生 on 2021/1/7.
6
- //
7
-
8
1
  #import "HBDNavigatorRegistry.h"
9
2
 
10
- #import <React/RCTLog.h>
11
-
12
3
  #import "HBDScreenNavigator.h"
13
4
  #import "HBDStackNavigator.h"
14
5
  #import "HBDTabNavigator.h"
15
6
  #import "HBDDrawerNavigator.h"
16
-
17
7
  #import "HBDNavigationController.h"
18
8
  #import "HBDTabBarController.h"
19
9
 
10
+ #import <React/RCTLog.h>
11
+
20
12
  @interface HBDNavigatorRegistry ()
21
13
 
22
14
  @property(nonatomic, strong) NSMutableArray<NSString *> *layouts;
15
+ @property(nonatomic, strong) NSMutableArray<id <HBDNavigator>> *navigators;
23
16
  @property(nonatomic, strong) NSMutableDictionary<NSString *, id <HBDNavigator>> *actionNavigatorPairs;
24
17
  @property(nonatomic, strong) NSMutableDictionary<NSString *, id <HBDNavigator>> *layoutNavigatorPairs;
25
18
  @property(nonatomic, strong) NSMutableDictionary<NSString *, NSString *> *classLayoutPairs;
@@ -45,8 +38,6 @@
45
38
  }
46
39
 
47
40
  - (void)registerNavigator:(id <HBDNavigator>)navigator {
48
- [self.layouts addObject:[navigator name]];
49
-
50
41
  for (NSString *action in [navigator supportActions]) {
51
42
  id <HBDNavigator> duplicated = self.actionNavigatorPairs[action];
52
43
  if (duplicated) {
@@ -56,11 +47,15 @@
56
47
  }
57
48
 
58
49
  NSString *layout = [navigator name];
50
+ [self.layouts addObject:layout];
51
+
59
52
  id <HBDNavigator> duplicatedLayout = self.layoutNavigatorPairs[layout];
60
53
  if (duplicatedLayout) {
61
54
  RCTLogError(@"[Navigator] The layout %@ that %@ wants to register has been registered by %@", layout, [navigator class], [duplicatedLayout class]);
62
55
  }
63
56
  self.layoutNavigatorPairs[layout] = navigator;
57
+
58
+ [self.navigators addObject:navigator];
64
59
  }
65
60
 
66
61
  - (id <HBDNavigator>)navigatorForAction:(NSString *)action {
@@ -73,21 +68,24 @@
73
68
 
74
69
  - (NSString *)layoutForViewController:(UIViewController *)vc {
75
70
  NSString *layout = self.classLayoutPairs[NSStringFromClass([vc class])];
76
- if (!layout) {
77
- if ([vc isKindOfClass:[HBDViewController class]]) {
78
- return @"screen";
79
- }
80
- if ([vc isKindOfClass:[HBDNavigationController class]]) {
81
- return @"stack";
82
- }
83
- if ([vc isKindOfClass:[HBDTabBarController class]]) {
84
- return @"tabs";
85
- }
86
- if ([vc isKindOfClass:[HBDDrawerController class]]) {
87
- return @"drawer";
88
- }
71
+ if (layout) {
72
+ return layout;
73
+ }
74
+
75
+ if ([vc isKindOfClass:[HBDViewController class]]) {
76
+ return @"screen";
77
+ }
78
+ if ([vc isKindOfClass:[HBDNavigationController class]]) {
79
+ return @"stack";
89
80
  }
90
- return layout;
81
+ if ([vc isKindOfClass:[HBDTabBarController class]]) {
82
+ return @"tabs";
83
+ }
84
+ if ([vc isKindOfClass:[HBDDrawerController class]]) {
85
+ return @"drawer";
86
+ }
87
+
88
+ return nil;
91
89
  }
92
90
 
93
91
  - (void)setLayout:(NSString *)layout forViewController:(UIViewController *)vc {
@@ -101,4 +99,8 @@
101
99
  return [self.layouts copy];
102
100
  }
103
101
 
102
+ - (NSArray<id<HBDNavigator>> *)allNavigators {
103
+ return [self.navigators copy];
104
+ }
105
+
104
106
  @end
@@ -1,12 +1,3 @@
1
- //
2
- // HBDScreenNavigator.h
3
- // HybridNavigation
4
- //
5
- // Created by Listen on 2018/6/28.
6
- // Copyright © 2018年 Listen. All rights reserved.
7
- //
8
-
9
- #import <Foundation/Foundation.h>
10
1
  #import "HBDNavigator.h"
11
2
 
12
3
  @interface HBDScreenNavigator : NSObject <HBDNavigator>