Skip to content

Commit

Permalink
Merge pull request #555 from qonversion/popoverFix
Browse files Browse the repository at this point in the history
Updated screens presentation logic and added new function to the delegate
  • Loading branch information
suriksarkisyan authored Nov 1, 2024
2 parents 2d558d1 + 67f3f41 commit 7992908
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions Sources/Qonversion/Public/QONScreenCustomizationDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#import "QONScreenPresentationConfiguration.h"

@class UIView;

/**
The delegate is responsible for customizing screens representation
*/
Expand All @@ -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

0 comments on commit 7992908

Please sign in to comment.