hybrid-navigation 4.0.6 → 4.0.8

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.
@@ -582,6 +582,15 @@ public abstract class AwesomeFragment extends InternalFragment {
582
582
 
583
583
  // ------ StackFragment -----
584
584
 
585
+ /** The covered stack entry can resume while a redirect prepares its return state. */
586
+ protected final boolean isResumingForRedirect() {
587
+ AwesomeFragment parent = getParentAwesomeFragment();
588
+ if (parent instanceof StackFragment stack && stack.isRedirectPrecursor(this)) {
589
+ return true;
590
+ }
591
+ return parent != null && parent.isResumingForRedirect();
592
+ }
593
+
585
594
  @NonNull
586
595
  public StackFragment requireStackFragment() {
587
596
  StackFragment stackFragment = getStackFragment();
@@ -30,15 +30,20 @@ public class FragmentHelper {
30
30
  if (fragmentManager.isDestroyed()) {
31
31
  return;
32
32
  }
33
+ AwesomeFragment topFragment = (AwesomeFragment) fragmentManager.findFragmentById(containerId);
34
+ addFragmentToBackStack(fragmentManager, containerId, fragment, animation, topFragment);
35
+ }
33
36
 
37
+ static void addFragmentToBackStack(@NonNull FragmentManager fragmentManager, int containerId,
38
+ @NonNull AwesomeFragment fragment, @NonNull TransitionAnimation animation,
39
+ @Nullable AwesomeFragment predecessor) {
34
40
  FragmentTransaction transaction = fragmentManager.beginTransaction();
35
41
  transaction.setReorderingAllowed(true);
36
42
  transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
37
- AwesomeFragment topFragment = (AwesomeFragment) fragmentManager.findFragmentById(containerId);
38
- if (topFragment != null && topFragment.isAdded()) {
39
- topFragment.setAnimation(animation);
40
- transaction.setMaxLifecycle(topFragment, Lifecycle.State.STARTED);
41
- transaction.hide(topFragment);
43
+ if (predecessor != null && predecessor.isAdded()) {
44
+ predecessor.setAnimation(animation);
45
+ transaction.setMaxLifecycle(predecessor, Lifecycle.State.STARTED);
46
+ transaction.hide(predecessor);
42
47
  }
43
48
  fragment.setAnimation(animation);
44
49
 
@@ -213,6 +213,13 @@ public class StackFragment extends AwesomeFragment {
213
213
  popToFragmentSync(rootFragment, completion, animation);
214
214
  }
215
215
 
216
+ @Nullable
217
+ private AwesomeFragment mRedirectPrecursor;
218
+
219
+ boolean isRedirectPrecursor(@NonNull AwesomeFragment fragment) {
220
+ return mRedirectPrecursor == fragment;
221
+ }
222
+
216
223
  public void redirectToFragment(@NonNull AwesomeFragment fragment) {
217
224
  scheduleTaskAtStarted(() -> redirectToFragmentSync(fragment, () -> {
218
225
  }, TransitionAnimation.Redirect, null));
@@ -241,34 +248,33 @@ public class StackFragment extends AwesomeFragment {
241
248
  SystemUI.hideIme(getWindow());
242
249
  }
243
250
 
244
- topFragment.setAnimation(animation);
245
-
246
- AwesomeFragment target = from;
247
- if (target == null) {
248
- target = topFragment;
251
+ AwesomeFragment target = from != null ? from : topFragment;
252
+ if (target.getParentFragment() != this || FragmentHelper.getIndexAtBackStack(target) < 0) {
253
+ // Without an entry to pop (e.g. an embedded screen), the visual operation is a push.
254
+ TransitionAnimation pushAnimation = animation == TransitionAnimation.Redirect ? TransitionAnimation.Push : animation;
255
+ pushFragmentSync(fragment, completion, pushAnimation);
256
+ return;
249
257
  }
250
258
 
259
+ topFragment.setAnimation(animation);
251
260
  AwesomeFragment precursor = FragmentHelper.getFragmentBefore(target);
252
- if (precursor != null && precursor.isAdded()) {
253
- precursor.setAnimation(animation);
254
- }
255
-
256
261
  FragmentManager fragmentManager = getChildFragmentManager();
257
- fragmentManager.beginTransaction().setMaxLifecycle(topFragment, Lifecycle.State.STARTED).commit();
258
- fragmentManager.popBackStack(target.getSceneId(), FragmentManager.POP_BACK_STACK_INCLUSIVE);
259
-
260
- FragmentTransaction transaction = fragmentManager.beginTransaction();
261
- transaction.setReorderingAllowed(true);
262
- transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
263
- if (precursor != null && precursor.isAdded()) {
264
- transaction.hide(precursor);
265
- transaction.setMaxLifecycle(precursor, Lifecycle.State.STARTED);
262
+ FragmentTransaction lifecycle = fragmentManager.beginTransaction()
263
+ .setMaxLifecycle(topFragment, Lifecycle.State.STARTED);
264
+ if (precursor != null) {
265
+ lifecycle.setMaxLifecycle(precursor, Lifecycle.State.RESUMED);
266
+ }
267
+ mRedirectPrecursor = precursor;
268
+ try {
269
+ // The replacement must record RESUMED as the state to restore when popped.
270
+ lifecycle.commitNow();
271
+ // Batch the visual operations so the outgoing view can slide under the incoming one.
272
+ fragmentManager.popBackStack(target.getSceneId(), FragmentManager.POP_BACK_STACK_INCLUSIVE);
273
+ FragmentHelper.addFragmentToBackStack(fragmentManager, R.id.navigation_content, fragment, animation, precursor);
274
+ fragmentManager.executePendingTransactions();
275
+ } finally {
276
+ mRedirectPrecursor = null;
266
277
  }
267
- fragment.setAnimation(animation);
268
- transaction.add(R.id.navigation_content, fragment, fragment.getSceneId());
269
- transaction.addToBackStack(fragment.getSceneId());
270
- transaction.commit();
271
- fragmentManager.executePendingTransactions();
272
278
 
273
279
  completion.run();
274
280
  }
@@ -58,6 +58,9 @@ public class ReactFragment extends HybridFragment implements ReactManager.ReactB
58
58
  @Override
59
59
  public void onResume() {
60
60
  super.onResume();
61
+ if (isResumingForRedirect()) {
62
+ return;
63
+ }
61
64
  if (isViewReady()) {
62
65
  sendViewAppearEvent(true);
63
66
  }
@@ -163,7 +166,7 @@ public class ReactFragment extends HybridFragment implements ReactManager.ReactB
163
166
  }
164
167
  firstRenderCompleted = true;
165
168
 
166
- if (isViewReady() && isResumed()) {
169
+ if (isViewReady() && isResumed() && !isResumingForRedirect()) {
167
170
  sendViewAppearEvent(true);
168
171
  }
169
172
  }
@@ -1,7 +1,7 @@
1
1
  <?xml version="1.0" encoding="utf-8"?>
2
2
  <resources>
3
3
  <dimen name="nav_tab_item_min_width">120dp</dimen>
4
- <dimen name="nav_tab_item_width_padding">12dp</dimen>
4
+ <dimen name="nav_tab_item_width_padding">4dp</dimen>
5
5
  <dimen name="nav_tab_item_title_size">12dp</dimen>
6
6
  <dimen name="nav_tab_item_icon_grid">24dp</dimen>
7
7
  <dimen name="nav_tab_item_icon_grid_margin_top">2dp</dimen>
@@ -1,6 +1,6 @@
1
1
  #import "HBDNativeEvent.h"
2
2
  #import "HBDReactBridgeManager.h"
3
- #import <React-RuntimeApple/ReactCommon/RCTHost.h>
3
+ #import <ReactCommon/RCTHost.h>
4
4
  #import <React/RCTLog.h>
5
5
 
6
6
  @implementation HBDNativeEvent
@@ -1,6 +1,6 @@
1
1
  #import <React/RCTBridge.h>
2
2
  #import "HBDNavigator.h"
3
- #import <React-RuntimeApple/ReactCommon/RCTHost.h>
3
+ #import <ReactCommon/RCTHost.h>
4
4
 
5
5
  extern NSString *const ReactModuleRegistryDidCompletedNotification;
6
6
  extern const NSInteger ResultOK;
@@ -1,11 +1,11 @@
1
1
  #import "HBDRootView.h"
2
2
 
3
- #import "RCTConstants.h"
4
- #import "RCTDefines.h"
5
- #import "RCTSurface.h"
6
- #import "RCTSurfaceDelegate.h"
7
- #import "RCTSurfaceView.h"
8
- #import "RCTUtils.h"
3
+ #import <React/RCTConstants.h>
4
+ #import <React/RCTDefines.h>
5
+ #import <React/RCTSurface.h>
6
+ #import <React/RCTSurfaceDelegate.h>
7
+ #import <React/RCTSurfaceView.h>
8
+ #import <React/RCTUtils.h>
9
9
 
10
10
  @interface HBDRootView ()
11
11
 
@@ -12,6 +12,9 @@
12
12
 
13
13
  @property(nonatomic, assign) BOOL firstRenderCompleted;
14
14
  @property(nonatomic, assign) BOOL viewAppeared;
15
+ @property(nonatomic, assign) BOOL appearanceEventSent;
16
+ @property(nonatomic, assign) BOOL appearanceEventScheduled;
17
+ @property(nonatomic, assign) NSUInteger appearanceEventGeneration;
15
18
  @property(nonatomic, strong, readwrite) HBDRootView *rootView;
16
19
 
17
20
  @end
@@ -44,6 +47,9 @@
44
47
 
45
48
  - (void)handleReload {
46
49
  self.firstRenderCompleted = NO;
50
+ self.appearanceEventGeneration += 1;
51
+ self.appearanceEventScheduled = NO;
52
+ self.appearanceEventSent = NO;
47
53
  }
48
54
 
49
55
  - (void)loadView {
@@ -69,6 +75,7 @@
69
75
  - (void)viewDidLayoutSubviews {
70
76
  [super viewDidLayoutSubviews];
71
77
  [self updateReactViewFrame];
78
+ [self scheduleAppearEventAfterLayout];
72
79
  }
73
80
 
74
81
  - (void)updateReactViewFrame {
@@ -98,57 +105,88 @@
98
105
  }
99
106
  }
100
107
 
108
+ // Appearance can start before UIKit has attached and laid out the new scene.
109
+ // Flush that layout first, then notify JS on the next main-queue turn so child
110
+ // safe-area measurements are enqueued before visibility-dependent content.
111
+ - (void)scheduleAppearEventAfterLayout {
112
+ if (!self.firstRenderCompleted || !self.viewAppeared || self.appearanceEventSent ||
113
+ self.appearanceEventScheduled || !self.isViewLoaded || !self.view.window ||
114
+ self.view.bounds.size.width <= 0 || self.view.bounds.size.height <= 0) {
115
+ return;
116
+ }
117
+ self.appearanceEventScheduled = YES;
118
+ NSUInteger generation = self.appearanceEventGeneration;
119
+ __weak HBDReactViewController *weakSelf = self;
120
+ dispatch_async(dispatch_get_main_queue(), ^{
121
+ HBDReactViewController *controller = weakSelf;
122
+ if (!controller || controller.appearanceEventGeneration != generation) {
123
+ return;
124
+ }
125
+ [controller.view.window layoutIfNeeded];
126
+ [controller.view layoutIfNeeded];
127
+ [controller.rootView layoutIfNeeded];
128
+ dispatch_async(dispatch_get_main_queue(), ^{
129
+ HBDReactViewController *current = weakSelf;
130
+ if (!current || current.appearanceEventGeneration != generation) {
131
+ return;
132
+ }
133
+ current.appearanceEventScheduled = NO;
134
+ if (!current.firstRenderCompleted || !current.viewAppeared ||
135
+ current.appearanceEventSent || !current.view.window ||
136
+ current.view.bounds.size.width <= 0 || current.view.bounds.size.height <= 0) {
137
+ return;
138
+ }
139
+ current.appearanceEventSent = YES;
140
+ [current emitAppearEvent];
141
+ });
142
+ });
143
+ }
144
+
145
+ - (void)emitAppearEvent {
146
+ [[HBDNativeEvent getInstance] emitOnComponentAppear:@{@"sceneId": self.sceneId}];
147
+ }
148
+
149
+ - (void)emitDisappearEvent {
150
+ [[HBDNativeEvent getInstance] emitOnComponentDisappear:@{@"sceneId": self.sceneId}];
151
+ }
152
+
153
+ - (void)finishAppearance {
154
+ self.viewAppeared = NO;
155
+ self.appearanceEventGeneration += 1;
156
+ self.appearanceEventScheduled = NO;
157
+ if (self.appearanceEventSent) {
158
+ self.appearanceEventSent = NO;
159
+ [self emitDisappearEvent];
160
+ }
161
+ }
162
+
101
163
  - (void)viewWillAppear:(BOOL)animated {
102
164
  [super viewWillAppear:animated];
103
165
  id <UIViewControllerTransitionCoordinator> coordinator = self.transitionCoordinator;
104
166
  if (coordinator && !coordinator.interactive) {
105
- if (!self.viewAppeared) {
106
- self.viewAppeared = YES;
107
- if (self.firstRenderCompleted) {
108
- [[HBDNativeEvent getInstance] emitOnComponentAppear:@{
109
- @"sceneId": self.sceneId,
110
- }];
111
- }
112
- }
167
+ self.viewAppeared = YES;
168
+ [self scheduleAppearEventAfterLayout];
113
169
  }
114
170
  }
115
171
 
116
172
  - (void)viewDidAppear:(BOOL)animated {
117
173
  [super viewDidAppear:animated];
118
- if (!self.viewAppeared) {
119
- self.viewAppeared = YES;
120
- if (self.firstRenderCompleted) {
121
- [[HBDNativeEvent getInstance] emitOnComponentAppear:@{
122
- @"sceneId": self.sceneId,
123
- }];
124
- }
125
- }
174
+ self.viewAppeared = YES;
175
+ [self scheduleAppearEventAfterLayout];
126
176
  }
127
177
 
128
178
  - (void)viewWillDisappear:(BOOL)animated {
129
179
  [super viewWillDisappear:animated];
130
180
  id <UIViewControllerTransitionCoordinator> coordinator = self.transitionCoordinator;
131
- if (coordinator && !coordinator.interactive) {
132
- if (self.viewAppeared) {
133
- self.viewAppeared = NO;
134
- if (self.firstRenderCompleted) {
135
- [[HBDNativeEvent getInstance] emitOnComponentDisappear:@{
136
- @"sceneId": self.sceneId,
137
- }];
138
- }
139
- }
181
+ if (coordinator && !coordinator.interactive && self.viewAppeared) {
182
+ [self finishAppearance];
140
183
  }
141
184
  }
142
185
 
143
186
  - (void)viewDidDisappear:(BOOL)animated {
144
187
  [super viewDidDisappear:animated];
145
188
  if (self.viewAppeared) {
146
- self.viewAppeared = NO;
147
- if (self.firstRenderCompleted) {
148
- [[HBDNativeEvent getInstance] emitOnComponentDisappear:@{
149
- @"sceneId": self.sceneId,
150
- }];
151
- }
189
+ [self finishAppearance];
152
190
  }
153
191
  }
154
192
 
@@ -157,13 +195,7 @@
157
195
  return;
158
196
  }
159
197
  self.firstRenderCompleted = YES;
160
- if (self.viewAppeared) {
161
- if (self.firstRenderCompleted) {
162
- [[HBDNativeEvent getInstance] emitOnComponentAppear:@{
163
- @"sceneId": self.sceneId,
164
- }];
165
- }
166
- }
198
+ [self scheduleAppearEventAfterLayout];
167
199
  }
168
200
 
169
201
  - (void)didReceiveResultCode:(NSInteger)resultCode resultData:(NSDictionary *)data requestCode:(NSInteger)requestCode {
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.6",
4
+ "version": "4.0.8",
5
5
  "main": "./dist/index",
6
6
  "module": "./dist/index",
7
7
  "types": "./dist/index.d.ts",