Skip to content

Commit 1d2cdd5

Browse files
committed
feat(ios): add “interactiveDismissModeEnabled” API (#14103)
* feat(ios): add “interactiveDismissModeEnabled” API * chore: add docs
1 parent e577bce commit 1d2cdd5

File tree

6 files changed

+100
-0
lines changed

6 files changed

+100
-0
lines changed

apidoc/Titanium/UI/NavigationWindow.yml

+10
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ properties:
3131
availability: creation
3232
optional: false
3333

34+
- name: interactiveDismissModeEnabled
35+
summary: |
36+
A boolean indicating whether or not child windows of this navigation window
37+
should have the ability to be swipe-to-closed over the full width of it's window or not.
38+
type: Boolean
39+
default: false
40+
platforms: [iphone, ipad, macos]
41+
since: "12.5.0"
42+
availability: creation
43+
3444
methods:
3545
- name: closeWindow
3646
summary: Closes a window and removes it from the navigation window.

apidoc/Titanium/UI/TabGroup.yml

+10
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,16 @@ properties:
609609
platforms: [android, iphone, ipad, macos]
610610
since: "12.1.0"
611611

612+
- name: interactiveDismissModeEnabled
613+
summary: |
614+
A boolean indicating whether or not child windows of this tab group
615+
should have the ability to be swipe-to-closed over the full width of it's window or not.
616+
type: Boolean
617+
default: false
618+
platforms: [iphone, ipad, macos]
619+
since: "12.5.0"
620+
availability: creation
621+
612622
examples:
613623
- title: Alloy XML Markup
614624
example: |

iphone/Classes/TiUINavigationWindowProxy.h

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
TiWindowProxy *current;
1717
BOOL transitionIsAnimating;
1818
BOOL transitionWithGesture;
19+
20+
UIPanGestureRecognizer *fullWidthBackGestureRecognizer;
1921
}
2022

2123
// Private API

iphone/Classes/TiUINavigationWindowProxy.m

+38
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,16 @@ @implementation TiUINavigationWindowProxy
1616

1717
- (void)_destroy
1818
{
19+
if (fullWidthBackGestureRecognizer != nil) {
20+
[fullWidthBackGestureRecognizer setDelegate:nil];
21+
[navController.view removeGestureRecognizer:fullWidthBackGestureRecognizer];
22+
}
23+
1924
RELEASE_TO_NIL(rootWindow);
2025
RELEASE_TO_NIL(navController);
2126
RELEASE_TO_NIL(current);
27+
RELEASE_TO_NIL(fullWidthBackGestureRecognizer);
28+
2229
[super_destroy];
2330
}
2431

@@ -88,14 +95,45 @@ - (UINavigationController *)controller
8895
[TiUtils configureController:navController withObject:self];
8996
[navController.interactivePopGestureRecognizer addTarget:selfaction:@selector(popGestureStateHandler:)];
9097
[[navController interactivePopGestureRecognizer] setDelegate:self];
98+
99+
BOOL interactiveDismissModeEnabled = [TiUtils boolValue:[selfvalueForKey:@"interactiveDismissModeEnabled"] def:NO];
100+
if (interactiveDismissModeEnabled) {
101+
[selfconfigureFullWidthSwipeToClose];
102+
}
91103
}
92104
return navController;
93105
}
94106

107+
- (void)configureFullWidthSwipeToClose
108+
{
109+
fullWidthBackGestureRecognizer = [[UIPanGestureRecognizer alloc] init];
110+
111+
if (navController.interactivePopGestureRecognizer == nil) {
112+
return;
113+
}
114+
115+
id targets = [navController.interactivePopGestureRecognizer valueForKey:@"targets"];
116+
if (targets == nil) {
117+
return;
118+
}
119+
120+
[fullWidthBackGestureRecognizer setValue:targets forKey:@"targets"];
121+
[fullWidthBackGestureRecognizer setDelegate:self];
122+
[navController.view addGestureRecognizer:fullWidthBackGestureRecognizer];
123+
}
124+
95125
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
96126
{
97127
BOOL isRootWindow = (current == rootWindow);
98128

129+
BOOL interactiveDismissModeEnabled = [TiUtils boolValue:[selfvalueForKey:@"interactiveDismissModeEnabled"] def:NO];
130+
if (interactiveDismissModeEnabled && [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) {
131+
BOOL isSystemSwipeToCloseEnabled = navController.interactivePopGestureRecognizer.isEnabled == YES;
132+
BOOL areThereStackedViewControllers = navController.viewControllers.count > 1;
133+
134+
return isSystemSwipeToCloseEnabled || areThereStackedViewControllers;
135+
}
136+
99137
if (current != nil && !isRootWindow) {
100138
return [TiUtils boolValue:[current valueForKey:@"swipeToClose"] def:YES];
101139
}

iphone/Classes/TiUITabProxy.h

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
BOOL activeIconOriginal;
3131

3232
id<TiOrientationController> parentOrientationController;
33+
34+
UIPanGestureRecognizer *fullWidthBackGestureRecognizer;
3335
}
3436

3537
- (void)setTabGroup:(TiUITabGroupProxy *)proxy;

iphone/Classes/TiUITabProxy.m

+38
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,20 @@ - (void)_destroy
3232
{
3333
[[NSNotificationCenterdefaultCenter] removeObserver:selfname:kTiTraitCollectionChangedobject:nil];
3434

35+
if (fullWidthBackGestureRecognizer != nil) {
36+
[fullWidthBackGestureRecognizer setDelegate:nil];
37+
[controller.view removeGestureRecognizer:fullWidthBackGestureRecognizer];
38+
}
39+
3540
if (rootWindow != nil) {
3641
[selfcleanNavStack:YES];
3742
}
3843
RELEASE_TO_NIL(controllerStack);
3944
RELEASE_TO_NIL(rootWindow);
4045
RELEASE_TO_NIL(controller);
4146
RELEASE_TO_NIL(current);
47+
RELEASE_TO_NIL(fullWidthBackGestureRecognizer);
48+
4249
[super_destroy];
4350
}
4451

@@ -260,12 +267,43 @@ - (UINavigationController *)controller
260267
[controllerStack addObject:[selfrootController]];
261268
[controller.interactivePopGestureRecognizer addTarget:selfaction:@selector(popGestureStateHandler:)];
262269
[[controller interactivePopGestureRecognizer] setDelegate:self];
270+
271+
BOOL interactiveDismissModeEnabled = [TiUtils boolValue:[tabGroup valueForKey:@"interactiveDismissModeEnabled"] def:NO];
272+
if (interactiveDismissModeEnabled) {
273+
[selfconfigureFullWidthSwipeToClose];
274+
}
263275
}
264276
return controller;
265277
}
266278

279+
- (void)configureFullWidthSwipeToClose
280+
{
281+
fullWidthBackGestureRecognizer = [[UIPanGestureRecognizer alloc] init];
282+
283+
if (controller.interactivePopGestureRecognizer == nil) {
284+
return;
285+
}
286+
287+
id targets = [controller.interactivePopGestureRecognizer valueForKey:@"targets"];
288+
if (targets == nil) {
289+
return;
290+
}
291+
292+
[fullWidthBackGestureRecognizer setValue:targets forKey:@"targets"];
293+
[fullWidthBackGestureRecognizer setDelegate:self];
294+
[controller.view addGestureRecognizer:fullWidthBackGestureRecognizer];
295+
}
296+
267297
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
268298
{
299+
BOOL interactiveDismissModeEnabled = [TiUtils boolValue:[selfvalueForKey:@"interactiveDismissModeEnabled"] def:NO];
300+
if (interactiveDismissModeEnabled && [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) {
301+
BOOL isSystemSwipeToCloseEnabled = controller.interactivePopGestureRecognizer.isEnabled == YES;
302+
BOOL areThereStackedViewControllers = controller.viewControllers.count > 1;
303+
304+
return isSystemSwipeToCloseEnabled || areThereStackedViewControllers;
305+
}
306+
269307
if (current != nil) {
270308
return [TiUtils boolValue:[current valueForKey:@"swipeToClose"] def:YES];
271309
}

0 commit comments

Comments
 (0)
close