hybrid-navigation 4.0.2 → 4.0.4

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.
@@ -123,6 +123,7 @@ public class TabBar extends FrameLayout {
123
123
  if (tabBarItem != null && tabView != null) {
124
124
  bindTabWithData(tabBarItem, tabView, this);
125
125
  tabView.initialise();
126
+ post(() -> relayoutTabs(resolveAvailableWidth()));
126
127
  }
127
128
  }
128
129
 
@@ -293,12 +294,15 @@ public class TabBar extends FrameLayout {
293
294
  }
294
295
 
295
296
  private int resolveAvailableWidth() {
296
- int availableWidth = tabContainer.getWidth();
297
+ int availableWidth = getWidth();
297
298
  if (availableWidth <= 0) {
298
- availableWidth = getWidth();
299
+ availableWidth = getMeasuredWidth();
300
+ }
301
+ if (availableWidth <= 0 && getParent() instanceof View) {
302
+ availableWidth = ((View) getParent()).getWidth();
299
303
  }
300
304
  if (availableWidth <= 0) {
301
- availableWidth = getMeasuredWidth();
305
+ availableWidth = tabContainer.getWidth();
302
306
  }
303
307
  if (availableWidth <= 0) {
304
308
  availableWidth = AppUtils.getScreenWidth(getContext());
@@ -306,16 +310,43 @@ public class TabBar extends FrameLayout {
306
310
  return availableWidth;
307
311
  }
308
312
 
313
+ private int resolveMeasuredWidth(int widthMeasureSpec) {
314
+ if (MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.UNSPECIFIED) {
315
+ return 0;
316
+ }
317
+ return MeasureSpec.getSize(widthMeasureSpec);
318
+ }
319
+
309
320
  private void relayoutTabs(int availableWidth) {
310
321
  if (availableWidth <= 0 || tabs.isEmpty() || tabBarItems.isEmpty()) {
311
322
  return;
312
323
  }
313
324
 
314
325
  int itemWidth = getTabWidth(getContext(), availableWidth, tabBarItems.size());
326
+ boolean changed = false;
315
327
  for (TabView tab : tabs) {
316
- tab.setTabWidth(itemWidth);
328
+ ViewGroup.LayoutParams params = tab.getLayoutParams();
329
+ if (params == null || params.width != itemWidth) {
330
+ tab.setTabWidth(itemWidth);
331
+ changed = true;
332
+ }
333
+ }
334
+ if (changed) {
335
+ tabContainer.requestLayout();
336
+ }
337
+ }
338
+
339
+ @Override
340
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
341
+ int measuredWidth = resolveMeasuredWidth(widthMeasureSpec);
342
+ if (measuredWidth > 0) {
343
+ relayoutTabs(measuredWidth);
344
+ }
345
+ super.onMeasure(widthMeasureSpec, heightMeasureSpec);
346
+ int actualWidth = getMeasuredWidth();
347
+ if (actualWidth > 0 && actualWidth != measuredWidth) {
348
+ relayoutTabs(actualWidth);
317
349
  }
318
- tabContainer.requestLayout();
319
350
  }
320
351
 
321
352
  @Override
@@ -80,7 +80,7 @@ public class HybridFragment extends AwesomeFragment {
80
80
  private void setBackgroundForModal(@NonNull Style style) {
81
81
  int color = mStyle.getScreenBackgroundColor();
82
82
  if (Color.alpha(color) == 255) {
83
- style.setScreenBackgroundColor(Color.parseColor("#77000000"));
83
+ style.setScreenBackgroundColor(Color.TRANSPARENT);
84
84
  }
85
85
  }
86
86
 
@@ -7,7 +7,6 @@ import android.os.Bundle;
7
7
  import androidx.annotation.NonNull;
8
8
  import androidx.annotation.Nullable;
9
9
 
10
- import com.facebook.react.bridge.Arguments;
11
10
  import com.navigation.androidx.AwesomeFragment;
12
11
  import com.navigation.androidx.FragmentHelper;
13
12
  import com.navigation.androidx.Style;
@@ -121,37 +120,6 @@ public class ReactTabBarFragment extends TabBarFragment {
121
120
  this.options = options;
122
121
  }
123
122
 
124
- public void setIntercepted(boolean intercepted) {
125
- this.intercepted = intercepted;
126
- }
127
-
128
- private boolean intercepted = true;
129
-
130
- @Override
131
- public void setSelectedIndex(int index, @NonNull Runnable completion) {
132
- if (shouldIntercept()) {
133
- sendSwitchTabEvent(index);
134
- // restore tab bar selected index
135
- setTabBarSelectedIndex(getSelectedIndex());
136
- completion.run();
137
- } else {
138
- super.setSelectedIndex(index, completion);
139
- intercepted = true;
140
- }
141
- }
142
-
143
- private boolean shouldIntercept() {
144
- return isAdded() && reactManager.hasRootLayout() && this.intercepted;
145
- }
146
-
147
- private void sendSwitchTabEvent(int index) {
148
- Bundle data = new Bundle();
149
- data.putString("sceneId", getSceneId());
150
- data.putInt("from", getSelectedIndex());
151
- data.putInt("to", index);
152
- NativeEvent.getInstance().emitOnSwitchTab(Arguments.fromBundle(data));
153
- }
154
-
155
123
  public Style getStyle() {
156
124
  return mStyle;
157
125
  }
@@ -160,14 +160,7 @@ public class TabNavigator implements Navigator {
160
160
 
161
161
  popToStackRootIfNeeded(extras, tabBarFragment);
162
162
 
163
- if (!(tabBarFragment instanceof ReactTabBarFragment reactTabBarFragment)) {
164
- tabBarFragment.setSelectedIndex(to, () -> callback.invoke(null, true));
165
- return;
166
- }
167
-
168
- reactTabBarFragment.setIntercepted(false);
169
- reactTabBarFragment.setSelectedIndex(to, () -> callback.invoke(null, true));
170
- reactTabBarFragment.setIntercepted(true);
163
+ tabBarFragment.setSelectedIndex(to, () -> callback.invoke(null, true));
171
164
  }
172
165
 
173
166
  private boolean isSameTab(int to, @NonNull ReadableMap extras) {
@@ -110,13 +110,14 @@
110
110
  }
111
111
 
112
112
  - (void)handleDismissWithViewController:(UIViewController *) vc callback:(RCTResponseSenderBlock)callback {
113
- BOOL animated = YES;
114
- if ([vc isKindOfClass:[HBDViewController class]]) {
113
+ UIViewController *modalHost = [self modalHostViewControllerForViewController:vc];
114
+ BOOL isModal = modalHost.modalPresentationStyle == UIModalPresentationOverFullScreen;
115
+ BOOL animated = !isModal;
116
+ if (!isModal && [vc isKindOfClass:[HBDViewController class]]) {
115
117
  HBDViewController *hbdvc = (HBDViewController *)vc;
116
118
  animated = hbdvc.animatedTransition;
117
119
  }
118
120
 
119
- UIViewController *modalHost = [self modalHostViewControllerForViewController:vc];
120
121
  UIViewController *presenting = modalHost.presentingViewController;
121
122
 
122
123
  [modalHost dismissViewControllerAnimated:animated completion:^{
@@ -142,13 +143,7 @@
142
143
  vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
143
144
  [vc setRequestCode:requestCode];
144
145
 
145
- BOOL animated = YES;
146
- if ([vc isKindOfClass:[HBDViewController class]]) {
147
- HBDViewController *hbdvc = (HBDViewController *)vc;
148
- animated = hbdvc.animatedTransition;
149
- }
150
-
151
- [presenting presentViewController:vc animated:animated completion:^{
146
+ [presenting presentViewController:vc animated:NO completion:^{
152
147
  callback(@[NSNull.null, @YES]);
153
148
  }];
154
149
  }
@@ -175,7 +170,7 @@
175
170
  [vc setRequestCode:requestCode];
176
171
  [vc setPresentingSceneId:presenting.sceneId];
177
172
 
178
- [presenting presentViewController:vc animated:YES completion:^{
173
+ [presenting presentViewController:vc animated:NO completion:^{
179
174
  callback(@[NSNull.null, @YES]);
180
175
  }];
181
176
  }
@@ -37,9 +37,7 @@
37
37
  if (options) {
38
38
  NSNumber *selectedIndex = options[@"selectedIndex"];
39
39
  if (selectedIndex) {
40
- tabBarController.intercepted = NO;
41
40
  tabBarController.selectedIndex = (NSUInteger) [selectedIndex integerValue];
42
- tabBarController.intercepted = YES;
43
41
  }
44
42
  }
45
43
 
@@ -108,14 +106,7 @@
108
106
  }
109
107
  }
110
108
 
111
- if ([tabBarController isKindOfClass:[HBDTabBarController class]]) {
112
- HBDTabBarController *hbdTabBarController = (HBDTabBarController *)tabBarController;
113
- hbdTabBarController.intercepted = NO;
114
- tabBarController.selectedIndex = to;
115
- hbdTabBarController.intercepted = YES;
116
- } else {
117
- tabBarController.selectedIndex = to;
118
- }
109
+ tabBarController.selectedIndex = to;
119
110
 
120
111
  callback(@[NSNull.null, @YES]);
121
112
  }
@@ -2,8 +2,6 @@
2
2
 
3
3
  @interface HBDTabBarController : UITabBarController
4
4
 
5
- @property(nonatomic, assign) BOOL intercepted;
6
-
7
5
  - (void)updateTabBar:(NSDictionary *)options;
8
6
 
9
7
  - (void)setTabItem:(NSArray<NSDictionary *> *)options;
@@ -1,10 +1,8 @@
1
1
  #import "HBDTabBarController.h"
2
2
 
3
3
  #import "HBDReactViewController.h"
4
- #import "HBDReactBridgeManager.h"
5
4
  #import "HBDUtils.h"
6
5
  #import "HBDFadeAnimation.h"
7
- #import "HBDNativeEvent.h"
8
6
 
9
7
  #import <React/RCTLog.h>
10
8
 
@@ -31,7 +29,6 @@
31
29
  [super viewDidLoad];
32
30
  self.definesPresentationContext = NO;
33
31
  self.delegate = self;
34
- self.intercepted = YES;
35
32
  }
36
33
 
37
34
  - (void)setTabItem:(NSArray<NSDictionary *> *)options {
@@ -116,16 +113,6 @@
116
113
  }
117
114
 
118
115
  - (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
119
- if ([[HBDReactBridgeManager get] hasRootLayout] && self.intercepted) {
120
- long from = self.selectedIndex;
121
- long to = [self.childViewControllers indexOfObject:viewController];
122
- [[HBDNativeEvent getInstance] emitOnSwitchTab:@{
123
- @"sceneId": self.sceneId,
124
- @"from": @(from),
125
- @"to": @(to),
126
- }];
127
- return NO;
128
- }
129
116
  return YES;
130
117
  }
131
118
 
@@ -172,7 +172,7 @@
172
172
  }
173
173
 
174
174
  - (void)setModalBackgroundColor {
175
- self.view.backgroundColor = [UIColor.blackColor colorWithAlphaComponent:0.5];
175
+ self.view.backgroundColor = UIColor.clearColor;
176
176
 
177
177
  NSString *screenColor = self.options[@"screenBackgroundColor"];
178
178
 
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": "4.0.2",
4
+ "version": "4.0.4",
5
5
  "main": "./dist/index",
6
6
  "module": "./dist/index",
7
7
  "types": "./dist/index.d.ts",