hybrid-navigation 2.17.5 → 2.17.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.
@@ -33,5 +33,5 @@ dependencies {
33
33
  implementation fileTree(dir: 'libs', include: ['*.jar'])
34
34
  implementation 'com.facebook.react:react-native:+'
35
35
  // api project(':navigation')
36
- api 'io.github.listenzz:AndroidNavigation:13.6.8'
36
+ api 'io.github.listenzz:AndroidNavigation:13.6.9'
37
37
  }
@@ -38,7 +38,7 @@ public class HybridFragment extends AwesomeFragment {
38
38
  public ReactBridgeManager getReactBridgeManager() {
39
39
  return bridgeManager;
40
40
  }
41
-
41
+
42
42
  public boolean isReactModuleRegisterCompleted() {
43
43
  return bridgeManager.isReactModuleRegisterCompleted();
44
44
  }
@@ -125,7 +125,7 @@ public class HybridFragment extends AwesomeFragment {
125
125
 
126
126
  return super.preferredStatusBarHidden();
127
127
  }
128
-
128
+
129
129
  @Override
130
130
  protected boolean preferredNavigationBarHidden() {
131
131
  if (getPresentationStyle() == PresentationStyle.OverFullScreen) {
@@ -180,6 +180,16 @@ public class HybridFragment extends AwesomeFragment {
180
180
  return options.getBoolean("passThroughTouches");
181
181
  }
182
182
 
183
+ protected boolean shouldAnimatedTransition() {
184
+ Bundle options = getOptions();
185
+ return options.getBoolean("animatedTransition", true);
186
+ }
187
+
188
+ protected boolean forceScreenLandscape() {
189
+ Bundle options = getOptions();
190
+ return options.getBoolean("forceScreenLandscape", false);
191
+ }
192
+
183
193
  protected boolean forceTransparentDialogWindow() {
184
194
  return garden.forceTransparentDialogWindow;
185
195
  }
@@ -12,6 +12,7 @@ import static com.reactnative.hybridnavigation.HBDEventEmitter.ON_COMPONENT_APPE
12
12
  import static com.reactnative.hybridnavigation.HBDEventEmitter.ON_COMPONENT_DISAPPEAR;
13
13
  import static com.reactnative.hybridnavigation.HBDEventEmitter.ON_COMPONENT_RESULT;
14
14
 
15
+ import android.content.pm.ActivityInfo;
15
16
  import android.graphics.Color;
16
17
  import android.os.Bundle;
17
18
  import android.view.Gravity;
@@ -23,6 +24,7 @@ import androidx.annotation.NonNull;
23
24
  import androidx.annotation.Nullable;
24
25
  import androidx.appcompat.widget.Toolbar;
25
26
 
27
+ import com.facebook.common.logging.FLog;
26
28
  import com.facebook.react.ReactInstanceManager;
27
29
  import com.facebook.react.bridge.Arguments;
28
30
  import com.facebook.react.bridge.ReactContext;
@@ -132,6 +134,23 @@ public class ReactFragment extends HybridFragment implements ReactBridgeManager.
132
134
  unmountReactView();
133
135
  }
134
136
 
137
+ @Override
138
+ public void onStart() {
139
+ super.onStart();
140
+ if (forceScreenLandscape()) {
141
+ requireActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
142
+ }
143
+ }
144
+
145
+ @Override
146
+ public void onStop() {
147
+ super.onStop();
148
+ if (forceScreenLandscape() && isRemoving()) {
149
+ requireActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
150
+ unmountReactView();
151
+ }
152
+ }
153
+
135
154
  @Override
136
155
  public void onReload() {
137
156
  unmountReactView();
@@ -151,6 +170,7 @@ public class ReactFragment extends HybridFragment implements ReactBridgeManager.
151
170
  }
152
171
 
153
172
  if (reactRootView != null) {
173
+ FLog.w(TAG, "销毁页面:" + getModuleName());
154
174
  reactRootView.unmountReactApplication();
155
175
  ViewGroup parent = (ViewGroup) reactRootView.getParent();
156
176
  parent.removeView(reactRootView);
@@ -42,6 +42,11 @@ public class ReactStackFragment extends StackFragment {
42
42
  protected void pushFragmentSync(AwesomeFragment fragment, @NonNull Runnable completion, @NonNull TransitionAnimation animation) {
43
43
  if (fragment instanceof ReactFragment) {
44
44
  ReactFragment reactFragment = (ReactFragment) fragment;
45
+ if (!reactFragment.shouldAnimatedTransition()) {
46
+ super.pushFragmentSync(fragment, completion, TransitionAnimation.None);
47
+ return;
48
+ }
49
+
45
50
  if (reactFragment.shouldPassThroughTouches()) {
46
51
  super.pushFragmentSync(fragment, completion, BetterPush);
47
52
  return;
@@ -55,6 +60,11 @@ public class ReactStackFragment extends StackFragment {
55
60
  AwesomeFragment topFragment = getTopFragment();
56
61
  if (topFragment instanceof ReactFragment) {
57
62
  ReactFragment reactFragment = (ReactFragment) topFragment;
63
+ if (!reactFragment.shouldAnimatedTransition()) {
64
+ super.popToFragmentSync(fragment, completion, TransitionAnimation.None);
65
+ return;
66
+ }
67
+
58
68
  if (reactFragment.shouldPassThroughTouches()) {
59
69
  super.popToFragmentSync(fragment, completion, BetterPush);
60
70
  return;
@@ -67,6 +77,11 @@ public class ReactStackFragment extends StackFragment {
67
77
  protected void redirectToFragmentSync(@NonNull AwesomeFragment fragment, @NonNull Runnable completion, @NonNull TransitionAnimation animation, @Nullable AwesomeFragment from) {
68
78
  if (fragment instanceof ReactFragment) {
69
79
  ReactFragment reactFragment = (ReactFragment) fragment;
80
+ if (!reactFragment.shouldAnimatedTransition()) {
81
+ super.redirectToFragmentSync(fragment, completion, TransitionAnimation.None, from);
82
+ return;
83
+ }
84
+
70
85
  if (reactFragment.shouldPassThroughTouches()) {
71
86
  super.redirectToFragmentSync(fragment, completion, BetterRedirect, from);
72
87
  return;
@@ -15,6 +15,7 @@
15
15
  @property(nonatomic, copy) NSString *tabBarUnselectedItemColorHexString;
16
16
  @property(nonatomic, strong, readonly) UIColor *tabBarBackgroundColor;
17
17
  @property(nonatomic, assign, readonly) BOOL alwaysSplitNavigationBarTransition;
18
+ @property(nonatomic, assign) UIInterfaceOrientationMask interfaceOrientation;
18
19
 
19
20
  - (instancetype)initWithOptions:(NSDictionary *)options;
20
21
 
@@ -57,6 +57,7 @@ static GlobalStyle *globalStyle;
57
57
  - (instancetype)initWithOptions:(NSDictionary *)options {
58
58
  if (self = [super init]) {
59
59
  _options = options;
60
+ _interfaceOrientation = UIInterfaceOrientationMaskPortrait;
60
61
 
61
62
  // screenBackgroundColor
62
63
  NSString *screenBackgroundColor = options[@"screenBackgroundColor"];
@@ -19,5 +19,6 @@
19
19
  #import "HBDDrawerNavigator.h"
20
20
 
21
21
  #import "HBDUtils.h"
22
+ #import "GlobalStyle.h"
22
23
 
23
24
  #endif /* HybridNavigation_h */
@@ -88,7 +88,7 @@
88
88
  }
89
89
 
90
90
  if ([action isEqualToString:@"pop"]) {
91
- [self handlePopWithNavigationController:nav callback:callback];
91
+ [self handlePopWithNavigationController:nav viewController:vc callback:callback];
92
92
  return;
93
93
  }
94
94
 
@@ -121,14 +121,37 @@
121
121
  }
122
122
 
123
123
  vc.hidesBottomBarWhenPushed = nav.hidesBottomBarWhenPushed;
124
- [[HBDAnimationObserver sharedObserver] beginAnimation];
125
- [nav pushViewController:vc animated:YES];
126
- [self animateAlongsideTransition:nav callback:callback];
124
+
125
+ BOOL animated = YES;
126
+ if ([vc isKindOfClass:[HBDViewController class]]) {
127
+ HBDViewController *hdbvc = (HBDViewController *)vc;
128
+ animated = hdbvc.animatedTransition;
129
+ }
130
+
131
+ if (animated) {
132
+ [[HBDAnimationObserver sharedObserver] beginAnimation];
133
+ [nav pushViewController:vc animated:YES];
134
+ [self animateAlongsideTransition:nav callback:callback];
135
+ } else {
136
+ [nav pushViewController:vc animated:NO];
137
+ callback(@[NSNull.null, @YES]);
138
+ }
127
139
  }
128
140
 
129
- - (void)handlePopWithNavigationController:(UINavigationController *)nav callback:(RCTResponseSenderBlock)callback {
130
- [nav popViewControllerAnimated:YES];
131
- [self animateAlongsideTransition:nav callback:callback];
141
+ - (void)handlePopWithNavigationController:(UINavigationController *)nav viewController:(UIViewController *)vc callback:(RCTResponseSenderBlock)callback {
142
+ BOOL animated = YES;
143
+ if ([vc isKindOfClass:[HBDViewController class]]) {
144
+ HBDViewController *hdbvc = (HBDViewController *)vc;
145
+ animated = hdbvc.animatedTransition;
146
+ }
147
+
148
+ if (animated) {
149
+ [nav popViewControllerAnimated:YES];
150
+ [self animateAlongsideTransition:nav callback:callback];
151
+ } else {
152
+ [nav popViewControllerAnimated:NO];
153
+ callback(@[NSNull.null, @YES]);
154
+ }
132
155
  }
133
156
 
134
157
  - (void)handlePopToWithNavigationController:(UINavigationController *)nav extras:(NSDictionary *)extras callback:(RCTResponseSenderBlock)callback {
@@ -138,8 +161,41 @@
138
161
  return;
139
162
  }
140
163
 
141
- [nav popToViewController:vc animated:YES];
142
- [self animateAlongsideTransition:nav callback:callback];
164
+ UIViewController *from_vc = [self findFromViewControllerWithNavigationController:nav extras:extras];
165
+
166
+ BOOL animated = YES;
167
+ if ([from_vc isKindOfClass:[HBDViewController class]]) {
168
+ HBDViewController *hbdvc = (HBDViewController *)from_vc;
169
+ animated = hbdvc.animatedTransition;
170
+ }
171
+
172
+ if (animated) {
173
+ [nav popToViewController:vc animated:YES];
174
+ [self animateAlongsideTransition:nav callback:callback];
175
+ }else {
176
+ [nav popToViewController:vc animated:NO];
177
+ callback(@[NSNull.null, @YES]);
178
+ }
179
+
180
+ }
181
+
182
+ - (UIViewController *)findFromViewControllerWithNavigationController:(UINavigationController *)nav extras:(NSDictionary *)extras {
183
+ NSArray *children = nav.childViewControllers;
184
+ NSString *moduleName = extras[@"from"];
185
+ BOOL inclusive = [extras[@"inclusive"] boolValue];
186
+
187
+ for (NSUInteger i = children.count; i > 0; i--) {
188
+ NSUInteger index = i - 1;
189
+ HBDViewController *vc = children[index];
190
+ if ([moduleName isEqualToString:vc.moduleName] || [moduleName isEqualToString:vc.sceneId]) {
191
+ if (inclusive && index > 0) {
192
+ return children[index - 1];
193
+ }
194
+ return vc;
195
+ }
196
+ }
197
+
198
+ return nil;
143
199
  }
144
200
 
145
201
  - (UIViewController *)findViewControllerWithNavigationController:(UINavigationController *)nav extras:(NSDictionary *)extras {
@@ -162,8 +218,23 @@
162
218
  }
163
219
 
164
220
  - (void)handlePopToRootWithNavigationController:(UINavigationController *)nav extras:(NSDictionary *)extras callback:(RCTResponseSenderBlock)callback {
165
- [nav popToRootViewControllerAnimated:YES];
166
- [self animateAlongsideTransition:nav callback:callback];
221
+
222
+ UIViewController *from_vc = [self findFromViewControllerWithNavigationController:nav extras:extras];
223
+
224
+ BOOL animated = YES;
225
+
226
+ if ([from_vc isKindOfClass:[HBDViewController class]]) {
227
+ HBDViewController *hbdvc = (HBDViewController *)from_vc;
228
+ animated = hbdvc.animatedTransition;
229
+ }
230
+
231
+ if (animated) {
232
+ [nav popToRootViewControllerAnimated:YES];
233
+ [self animateAlongsideTransition:nav callback:callback];
234
+ }else {
235
+ [nav popToRootViewControllerAnimated:NO];
236
+ callback(@[NSNull.null, @YES]);
237
+ }
167
238
  }
168
239
 
169
240
  - (void)handleRedirectToWithNavigationController:(UINavigationController *)nav target:(UIViewController *)target extras:(NSDictionary *)extras callback:(RCTResponseSenderBlock)callback {
@@ -177,10 +248,22 @@
177
248
  callback(@[NSNull.null, @NO]);
178
249
  return;
179
250
  }
251
+ BOOL animated = YES;
252
+
253
+ if ([vc isKindOfClass:[HBDViewController class]]) {
254
+ HBDViewController *hbdvc = (HBDViewController *)vc;
255
+ animated = hbdvc.animatedTransition;
256
+ }
257
+
258
+ if (animated) {
259
+ [[HBDAnimationObserver sharedObserver] beginAnimation];
260
+ [nav redirectToViewController:vc target:target animated:YES];
261
+ [self animateAlongsideTransition:nav callback:callback];
262
+ }else {
263
+ [nav redirectToViewController:vc target:target animated:NO];
264
+ callback(@[NSNull.null, @YES]);
265
+ }
180
266
 
181
- [[HBDAnimationObserver sharedObserver] beginAnimation];
182
- [nav redirectToViewController:vc target:target animated:YES];
183
- [self animateAlongsideTransition:nav callback:callback];
184
267
  }
185
268
 
186
269
  - (void)handlePushLayoutWithNavigationController:(UINavigationController *)nav extras:(NSDictionary *)extras callback:(RCTResponseSenderBlock)callback {
@@ -11,10 +11,10 @@
11
11
  label.backgroundColor = [UITabBarItem appearance].badgeColor ?: [UIColor colorWithRed:1 green:58.0 / 255.0 blue:47. / 255. alpha:1];
12
12
 
13
13
  CGFloat percentX = (index + 0.5) / self.items.count;
14
- CGFloat x = ceilf((float) (percentX * self.frame.size.width + 10));
15
- CGFloat y = 5;
14
+ CGFloat x = ceilf((float) (percentX * self.frame.size.width + 8));
15
+ CGFloat y = 6;
16
16
  //10为小红点的高度和宽度
17
- label.frame = CGRectMake(x, y, 10, 10);
17
+ label.frame = CGRectMake(x, y, 8, 8);
18
18
  [self addSubview:label];
19
19
  //把小红点移到最顶层
20
20
  [self bringSubviewToFront:label];
@@ -32,7 +32,7 @@
32
32
 
33
33
  - (void)styleLabel:(UILabel *)label {
34
34
  CGRect rect = label.bounds;
35
- CGFloat radius = 5;
35
+ CGFloat radius = 4;
36
36
  UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:rect
37
37
  byRoundingCorners:UIRectCornerAllCorners
38
38
  cornerRadii:CGSizeMake(radius, radius)];
@@ -7,6 +7,7 @@
7
7
  @property(nonatomic, copy, readonly) NSString *moduleName;
8
8
  @property(nonatomic, copy, readonly) NSDictionary *props;
9
9
  @property(nonatomic, copy, readonly) NSDictionary *options;
10
+ @property(nonatomic, assign, readonly) BOOL animatedTransition;
10
11
 
11
12
  - (instancetype)initWithModuleName:(NSString *)moduleName props:(NSDictionary *)props options:(NSDictionary *)options NS_DESIGNATED_INITIALIZER;
12
13
 
@@ -13,6 +13,8 @@
13
13
  @property(nonatomic, copy, readwrite) NSDictionary *props;
14
14
  @property(nonatomic, copy, readwrite) NSDictionary *options;
15
15
  @property(nonatomic, assign) BOOL forceTransparentDialogWindow;
16
+ @property(nonatomic, assign) BOOL forceScreenLandscape;
17
+ @property(nonatomic, assign, readwrite) BOOL animatedTransition;
16
18
 
17
19
  @end
18
20
 
@@ -35,8 +37,18 @@
35
37
  _moduleName = moduleName;
36
38
  _options = options;
37
39
  _props = props;
40
+ _animatedTransition = YES;
41
+
42
+ if (options[@"animatedTransition"]) {
43
+ _animatedTransition = [options[@"animatedTransition"] boolValue];
44
+ }
45
+
46
+ if (options[@"forceScreenLandscape"]) {
47
+ _forceScreenLandscape = [options[@"forceScreenLandscape"] boolValue];
48
+ }
38
49
 
39
50
  self.forceTransparentDialogWindow = [options[@"forceTransparentDialogWindow"] boolValue];
51
+
40
52
  [self applyNavigationBarOptions:options];
41
53
  [self applyTabBarOptions:options];
42
54
  }
@@ -96,6 +108,50 @@
96
108
  }
97
109
  }
98
110
 
111
+ - (void)willMoveToParentViewController:(UIViewController *)parent {
112
+ if (self.forceScreenLandscape) {
113
+ if (parent) {
114
+ [self setScreenOrientation:UIInterfaceOrientationLandscapeRight usingMask:UIInterfaceOrientationMaskLandscapeRight];
115
+ } else {
116
+ [self setScreenOrientation:UIInterfaceOrientationPortrait usingMask:UIInterfaceOrientationMaskPortrait];
117
+ }
118
+ }
119
+ }
120
+
121
+ - (void)setScreenOrientation:(UIInterfaceOrientation) orientation usingMask:(UIInterfaceOrientationMask) mask {
122
+ [GlobalStyle globalStyle].interfaceOrientation = mask;
123
+
124
+ if (@available(iOS 16.0, *)) {
125
+ UIWindowScene *windowScene = [self getWindowScene];
126
+ if (windowScene != nil) {
127
+ UIWindowSceneGeometryPreferencesIOS *geometryPreferences = [[UIWindowSceneGeometryPreferencesIOS alloc] initWithInterfaceOrientations:mask];
128
+ [windowScene requestGeometryUpdateWithPreferences:geometryPreferences errorHandler:^(NSError * _Nonnull error) {
129
+ #if DEBUG
130
+ if (error) {
131
+ NSLog(@"Failed to update geometry with UIInterfaceOrientationMask: %@", error);
132
+ }
133
+ #endif
134
+ }];
135
+ }
136
+ } else {
137
+ UIDevice* currentDevice = [UIDevice currentDevice];
138
+ [currentDevice setValue:@(UIInterfaceOrientationUnknown) forKey:@"orientation"];
139
+ [currentDevice setValue:@(orientation) forKey:@"orientation"];
140
+ }
141
+
142
+ [UIViewController attemptRotationToDeviceOrientation];
143
+ }
144
+
145
+ - (UIWindowScene *)getWindowScene API_AVAILABLE(ios(13.0)){
146
+ NSArray *array = [[[UIApplication sharedApplication] connectedScenes] allObjects];
147
+ for (id connectedScene in array) {
148
+ if ([connectedScene isKindOfClass:[UIWindowScene class]]) {
149
+ return connectedScene;
150
+ }
151
+ }
152
+ return nil;
153
+ }
154
+
99
155
  - (void)statusBarFrameWillChange:(NSNotification *)notification {
100
156
  [self setNeedsStatusBarAppearanceUpdate];
101
157
  }
@@ -15,7 +15,7 @@
15
15
  if (children.count > 1) {
16
16
  controller.hidesBottomBarWhenPushed = self.hidesBottomBarWhenPushed;
17
17
  }
18
- [self setViewControllers:children animated:YES];
18
+ [self setViewControllers:children animated:animated];
19
19
  }
20
20
 
21
21
  @end
package/lib/Options.d.ts CHANGED
@@ -44,6 +44,8 @@ export interface NavigationOption {
44
44
  export interface NavigationItem extends NavigationOption {
45
45
  passThroughTouches?: boolean;
46
46
  forceTransparentDialogWindow?: boolean;
47
+ animatedTransition?: boolean;
48
+ forceScreenLandscape?: boolean;
47
49
  topBarHidden?: boolean;
48
50
  extendedLayoutIncludesTopBar?: boolean;
49
51
  swipeBackEnabled?: boolean;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "hybrid-navigation",
3
3
  "description": "React Native Navigation that supports seamless navigation between Native and React.",
4
- "version": "2.17.5",
4
+ "version": "2.17.6",
5
5
  "main": "./lib/index.js",
6
6
  "typings": "./lib/index.d.ts",
7
7
  "react-native": "src/index",
package/src/Options.ts CHANGED
@@ -45,6 +45,8 @@ export interface NavigationOption {
45
45
  export interface NavigationItem extends NavigationOption {
46
46
  passThroughTouches?: boolean // 触摸事件是否可以穿透到下一层页面,很少用。
47
47
  forceTransparentDialogWindow?: boolean // 当页面是 Dialog 时,是否强制背景透明
48
+ animatedTransition?: boolean
49
+ forceScreenLandscape?: boolean // 是否强制横屏
48
50
  topBarHidden?: boolean // 是否隐藏 TopBar
49
51
  extendedLayoutIncludesTopBar?: boolean // 页面内容是否延伸到 TopBar 底下,通常用于需要动态改变 `topBarAlpha` 的场合
50
52
  swipeBackEnabled?: boolean // 是否可以通过右滑返回。如果 `backInteractive` 设置为 false, 那么该值无效。Android 下,只有开启了侧滑返回功能,该值才会生效。