Skip to content

Commit ffc40de

Browse files
authored
Send NavigationButtonPressed event also on Swipe-Back on screen (#8222)
* Send NavigationButtonPressedEvent also on Swipe-Back on screen * little cleanup * documentation update
1 parent 19e3c49 commit ffc40de

4 files changed

Lines changed: 34 additions & 3 deletions

File tree

ios/RNNNavigationOptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ extern const NSInteger BLUR_TOPBAR_TAG;
3636
@property(nonatomic, strong) WindowOptions *window;
3737

3838
@property(nonatomic, strong) Bool *popGesture;
39+
@property(nonatomic, strong) Bool *navigationButtonEventOnSwipeBack;
3940
@property(nonatomic, strong) Image *backgroundImage;
4041
@property(nonatomic, strong) Image *rootBackgroundImage;
4142
@property(nonatomic, strong) Text *modalPresentationStyle;

ios/RNNNavigationOptions.mm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ - (instancetype)initWithDict:(NSDictionary *)dict {
4141
self.window = [[WindowOptions alloc] initWithDict:dict[@"window"]];
4242

4343
self.popGesture = [[Bool alloc] initWithValue:dict[@"popGesture"]];
44+
self.navigationButtonEventOnSwipeBack = [[Bool alloc] initWithValue:dict[@"navigationButtonEventOnSwipeBack"]];
4445
self.backgroundImage = [ImageParser parse:dict key:@"backgroundImage"];
4546
self.rootBackgroundImage = [ImageParser parse:dict key:@"rootBackgroundImage"];
4647
self.modalPresentationStyle = [[Text alloc] initWithValue:dict[@"modalPresentationStyle"]];
@@ -73,6 +74,8 @@ - (RNNNavigationOptions *)mergeOptions:(RNNNavigationOptions *)options {
7374

7475
if (options.popGesture.hasValue)
7576
result.popGesture = options.popGesture;
77+
if (options.navigationButtonEventOnSwipeBack.hasValue)
78+
result.navigationButtonEventOnSwipeBack = options.navigationButtonEventOnSwipeBack;
7679
if (options.backgroundImage.hasValue)
7780
result.backgroundImage = options.backgroundImage;
7881
if (options.rootBackgroundImage.hasValue)
@@ -104,6 +107,7 @@ - (RNNNavigationOptions *)copy {
104107
[newOptions.window mergeOptions:self.window];
105108

106109
newOptions.popGesture = self.popGesture;
110+
newOptions.navigationButtonEventOnSwipeBack = self.navigationButtonEventOnSwipeBack;
107111
newOptions.backgroundImage = self.backgroundImage;
108112
newOptions.rootBackgroundImage = self.rootBackgroundImage;
109113
newOptions.modalPresentationStyle = self.modalPresentationStyle;

ios/StackControllerDelegate.mm

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,27 @@ - (instancetype)initWithEventEmitter:(RNNEventEmitter *)eventEmitter {
2626
- (void)navigationController:(UINavigationController *)navigationController
2727
willShowViewController:(UIViewController *)viewController
2828
animated:(BOOL)animated {
29-
if (_presentedViewController &&
30-
![navigationController.viewControllers containsObject:_presentedViewController]) {
31-
_isPopping = YES;
29+
if (_presentedViewController) {
30+
if (![navigationController.viewControllers containsObject:_presentedViewController]) {
31+
_isPopping = YES;
32+
}
33+
34+
id<UIViewControllerTransitionCoordinator> coordinator = navigationController.transitionCoordinator;
35+
if (coordinator && coordinator.isInteractive) {
36+
UIViewController *poppingViewController = _presentedViewController;
37+
[coordinator notifyWhenInteractionChangesUsingBlock:^(id<UIViewControllerTransitionCoordinatorContext> context) {
38+
if (!context.isCancelled) {
39+
if ([poppingViewController conformsToProtocol:@protocol(RNNLayoutProtocol)]) {
40+
UIViewController<RNNLayoutProtocol> *rnnVC = (UIViewController<RNNLayoutProtocol> *)poppingViewController;
41+
if ([rnnVC.options.navigationButtonEventOnSwipeBack withDefault:NO]) {
42+
NSString *buttonId = [rnnVC.options.topBar.backButton.identifier withDefault:@"RNN.back"];
43+
[self->_eventEmitter sendOnNavigationButtonPressed:rnnVC.layoutInfo.componentId
44+
buttonId:buttonId];
45+
}
46+
}
47+
}
48+
}];
49+
}
3250
}
3351
}
3452

website/docs/api/options-root.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,14 @@ Enable or disable swipe back to pop gesture.
141141
| ------- | -------- | -------- |
142142
| boolean | No | iOS |
143143

144+
## `navigationButtonEventOnSwipeBack`
145+
146+
Enable NavigationButtonPressed event sending on Swipe-back on pushed VC.
147+
148+
| Type | Required | Platform | Default |
149+
| ------- | -------- | -------- | ------- |
150+
| boolean | No | iOS | false |
151+
144152
## `backgroundImage`
145153

146154
Background image of the screen.

0 commit comments

Comments
 (0)