From 67f3f41ed796b493222098d2771e778fcc67fd60 Mon Sep 17 00:00:00 2001 From: Surik Date: Thu, 31 Oct 2024 15:32:21 +0400 Subject: [PATCH] Updated automations screens presentation logic and added new support function to the delegate --- .../QONAutomationsFlowCoordinator.m | 29 ++++++++++++++++--- .../Public/QONScreenCustomizationDelegate.h | 10 +++++++ 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/Sources/Qonversion/Automations/Main/QONAutomationsFlowCoordinator/QONAutomationsFlowCoordinator.m b/Sources/Qonversion/Automations/Main/QONAutomationsFlowCoordinator/QONAutomationsFlowCoordinator.m index 76cb1703..99f11bab 100644 --- a/Sources/Qonversion/Automations/Main/QONAutomationsFlowCoordinator/QONAutomationsFlowCoordinator.m +++ b/Sources/Qonversion/Automations/Main/QONAutomationsFlowCoordinator/QONAutomationsFlowCoordinator.m @@ -136,11 +136,32 @@ - (void)showAutomationWithID:(NSString *)automationID completion:(nullable QONSh if (configuration.presentationStyle == QONScreenPresentationStylePush) { [presentationViewController.navigationController pushViewController:viewController animated:configuration.animated]; } else { - QONAutomationsNavigationController *navigationController = [[QONAutomationsNavigationController alloc] initWithRootViewController:viewController]; - navigationController.navigationBarHidden = YES; UIModalPresentationStyle style = configuration.presentationStyle == QONScreenPresentationStylePopover ? UIModalPresentationPopover : UIModalPresentationFullScreen; - navigationController.modalPresentationStyle = style; - [presentationViewController presentViewController:navigationController animated:configuration.animated completion:nil]; + + if (style == UIModalPresentationPopover) { + viewController.modalPresentationStyle = style; + + UIView *sourceView = nil; + if ([weakSelf.screenCustomizationDelegate respondsToSelector:@selector(viewForPopoverPresentation)]) { + sourceView = [weakSelf.screenCustomizationDelegate viewForPopoverPresentation]; + } + + if (sourceView) { + viewController.popoverPresentationController.sourceRect = sourceView.bounds; + viewController.popoverPresentationController.sourceView = sourceView; + } else { + viewController.popoverPresentationController.permittedArrowDirections = 0; + viewController.popoverPresentationController.sourceRect = CGRectMake(CGRectGetMidX(presentationViewController.view.bounds), CGRectGetMidY(presentationViewController.view.bounds),0,0); + viewController.popoverPresentationController.sourceView = presentationViewController.view; + } + + [presentationViewController presentViewController:viewController animated:configuration.animated completion:nil]; + } else { + QONAutomationsNavigationController *navigationController = [[QONAutomationsNavigationController alloc] initWithRootViewController:viewController]; + navigationController.navigationBarHidden = YES; + navigationController.modalPresentationStyle = style; + [presentationViewController presentViewController:navigationController animated:configuration.animated completion:nil]; + } } run_block_on_main(completion, true, nil); diff --git a/Sources/Qonversion/Public/QONScreenCustomizationDelegate.h b/Sources/Qonversion/Public/QONScreenCustomizationDelegate.h index a3fd809c..04744204 100644 --- a/Sources/Qonversion/Public/QONScreenCustomizationDelegate.h +++ b/Sources/Qonversion/Public/QONScreenCustomizationDelegate.h @@ -8,6 +8,8 @@ #import "QONScreenPresentationConfiguration.h" +@class UIView; + /** The delegate is responsible for customizing screens representation */ @@ -23,4 +25,12 @@ NS_SWIFT_NAME(Qonversion.ScreenCustomizationDelegate) - (QONScreenPresentationConfiguration * _Nonnull)presentationConfigurationForScreen:(NSString * _Nonnull)screenId NS_SWIFT_NAME(presentationConfigurationForScreen(_:));; +/** + View for popover presentation style for iPad. A new popover will be presented from this view + Used only for Qonversion.ScreenPresentationStyle == .popover for iPad. + You can omit implementing this delegate function if you do not support iPad or do not use popover presentation style. + */ +- (UIView * _Nullable)viewForPopoverPresentation +NS_SWIFT_NAME(viewForPopoverPresentation()); + @end