Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ios): add “interactiveDismissModeEnabled” API #14103

Merged
merged 2 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions apidoc/Titanium/UI/NavigationWindow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ properties:
availability: creation
optional: false

- name: interactiveDismissModeEnabled
summary: |
A boolean indicating whether or not child windows of this navigation window
should have the ability to be swipe-to-closed over the full width of it's window or not.
type: Boolean
default: false
platforms: [iphone, ipad, macos]
since: "12.5.0"
availability: creation

methods:
- name: closeWindow
summary: Closes a window and removes it from the navigation window.
Expand Down
10 changes: 10 additions & 0 deletions apidoc/Titanium/UI/TabGroup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,16 @@ properties:
platforms: [android, iphone, ipad, macos]
since: "12.1.0"

- name: interactiveDismissModeEnabled
summary: |
A boolean indicating whether or not child windows of this tab group
should have the ability to be swipe-to-closed over the full width of it's window or not.
type: Boolean
default: false
platforms: [iphone, ipad, macos]
since: "12.5.0"
availability: creation

examples:
- title: Alloy XML Markup
example: |
Expand Down
2 changes: 2 additions & 0 deletions iphone/Classes/TiUINavigationWindowProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
TiWindowProxy *current;
BOOL transitionIsAnimating;
BOOL transitionWithGesture;

UIPanGestureRecognizer *fullWidthBackGestureRecognizer;
}

// Private API
Expand Down
38 changes: 38 additions & 0 deletions iphone/Classes/TiUINavigationWindowProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,16 @@ @implementation TiUINavigationWindowProxy

- (void)_destroy
{
if (fullWidthBackGestureRecognizer != nil) {
[fullWidthBackGestureRecognizer setDelegate:nil];
[navController.view removeGestureRecognizer:fullWidthBackGestureRecognizer];
}

RELEASE_TO_NIL(rootWindow);
RELEASE_TO_NIL(navController);
RELEASE_TO_NIL(current);
RELEASE_TO_NIL(fullWidthBackGestureRecognizer);

[super _destroy];
}

Expand Down Expand Up @@ -88,14 +95,45 @@ - (UINavigationController *)controller
[TiUtils configureController:navController withObject:self];
[navController.interactivePopGestureRecognizer addTarget:self action:@selector(popGestureStateHandler:)];
[[navController interactivePopGestureRecognizer] setDelegate:self];

BOOL interactiveDismissModeEnabled = [TiUtils boolValue:[self valueForKey:@"interactiveDismissModeEnabled"] def:NO];
if (interactiveDismissModeEnabled) {
[self configureFullWidthSwipeToClose];
}
}
return navController;
}

- (void)configureFullWidthSwipeToClose
{
fullWidthBackGestureRecognizer = [[UIPanGestureRecognizer alloc] init];

if (navController.interactivePopGestureRecognizer == nil) {
return;
}

id targets = [navController.interactivePopGestureRecognizer valueForKey:@"targets"];
if (targets == nil) {
return;
}

[fullWidthBackGestureRecognizer setValue:targets forKey:@"targets"];
[fullWidthBackGestureRecognizer setDelegate:self];
[navController.view addGestureRecognizer:fullWidthBackGestureRecognizer];
}

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
BOOL isRootWindow = (current == rootWindow);

BOOL interactiveDismissModeEnabled = [TiUtils boolValue:[self valueForKey:@"interactiveDismissModeEnabled"] def:NO];
if (interactiveDismissModeEnabled && [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) {
BOOL isSystemSwipeToCloseEnabled = navController.interactivePopGestureRecognizer.isEnabled == YES;
BOOL areThereStackedViewControllers = navController.viewControllers.count > 1;

return isSystemSwipeToCloseEnabled || areThereStackedViewControllers;
}

if (current != nil && !isRootWindow) {
return [TiUtils boolValue:[current valueForKey:@"swipeToClose"] def:YES];
}
Expand Down
2 changes: 2 additions & 0 deletions iphone/Classes/TiUITabProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
BOOL activeIconOriginal;

id<TiOrientationController> parentOrientationController;

UIPanGestureRecognizer *fullWidthBackGestureRecognizer;
}

- (void)setTabGroup:(TiUITabGroupProxy *)proxy;
Expand Down
38 changes: 38 additions & 0 deletions iphone/Classes/TiUITabProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,20 @@ - (void)_destroy
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:kTiTraitCollectionChanged object:nil];

if (fullWidthBackGestureRecognizer != nil) {
[fullWidthBackGestureRecognizer setDelegate:nil];
[controller.view removeGestureRecognizer:fullWidthBackGestureRecognizer];
}

if (rootWindow != nil) {
[self cleanNavStack:YES];
}
RELEASE_TO_NIL(controllerStack);
RELEASE_TO_NIL(rootWindow);
RELEASE_TO_NIL(controller);
RELEASE_TO_NIL(current);
RELEASE_TO_NIL(fullWidthBackGestureRecognizer);

[super _destroy];
}

Expand Down Expand Up @@ -260,12 +267,43 @@ - (UINavigationController *)controller
[controllerStack addObject:[self rootController]];
[controller.interactivePopGestureRecognizer addTarget:self action:@selector(popGestureStateHandler:)];
[[controller interactivePopGestureRecognizer] setDelegate:self];

BOOL interactiveDismissModeEnabled = [TiUtils boolValue:[tabGroup valueForKey:@"interactiveDismissModeEnabled"] def:NO];
if (interactiveDismissModeEnabled) {
[self configureFullWidthSwipeToClose];
}
}
return controller;
}

- (void)configureFullWidthSwipeToClose
{
fullWidthBackGestureRecognizer = [[UIPanGestureRecognizer alloc] init];

if (controller.interactivePopGestureRecognizer == nil) {
return;
}

id targets = [controller.interactivePopGestureRecognizer valueForKey:@"targets"];
if (targets == nil) {
return;
}

[fullWidthBackGestureRecognizer setValue:targets forKey:@"targets"];
[fullWidthBackGestureRecognizer setDelegate:self];
[controller.view addGestureRecognizer:fullWidthBackGestureRecognizer];
}

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
BOOL interactiveDismissModeEnabled = [TiUtils boolValue:[self valueForKey:@"interactiveDismissModeEnabled"] def:NO];
if (interactiveDismissModeEnabled && [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) {
BOOL isSystemSwipeToCloseEnabled = controller.interactivePopGestureRecognizer.isEnabled == YES;
BOOL areThereStackedViewControllers = controller.viewControllers.count > 1;

return isSystemSwipeToCloseEnabled || areThereStackedViewControllers;
}

if (current != nil) {
return [TiUtils boolValue:[current valueForKey:@"swipeToClose"] def:YES];
}
Expand Down
Loading