From 436732c1deb1f251ad14dcba78f53d792abb70c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20L=C3=A9vy?= Date: Thu, 16 May 2019 22:17:59 +0200 Subject: [PATCH] Update RNPrint.m --- ios/RNPrint/RNPrint.m | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/ios/RNPrint/RNPrint.m b/ios/RNPrint/RNPrint.m index 403096f..c57e8b9 100644 --- a/ios/RNPrint/RNPrint.m +++ b/ios/RNPrint/RNPrint.m @@ -1,5 +1,5 @@ -// Created by Christopher Dro on 9/4/15. +// Created by Alex Levy on 16 May 19. #import "RNPrint.h" #import @@ -92,8 +92,12 @@ - (dispatch_queue_t)methodQueue if (_pickedPrinter) { [printInteractionController printToPrinter:_pickedPrinter completionHandler:completionHandler]; } else if([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) { // iPad - UIView *view = [[UIApplication sharedApplication] keyWindow].rootViewController.view; - [printInteractionController presentFromRect:view.frame inView:view animated:YES completionHandler:completionHandler]; + UIViewController *rootViewController = UIApplication.sharedApplication.delegate.window.rootViewController; + while (rootViewController.presentedViewController != nil) { + rootViewController = rootViewController.presentedViewController; + } + CGRect rect = CGRectMake(rootViewController.view.bounds.size.width/2, rootViewController.view.bounds.size.height/2, 1, 1); + [printInteractionController presentFromRect:rect inView:rootViewController.view animated:YES completionHandler:completionHandler]; } else { // iPhone [printInteractionController presentAnimated:YES completionHandler:completionHandler]; } @@ -126,8 +130,17 @@ - (dispatch_queue_t)methodQueue }; if([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) { // iPad - UIView *view = [[UIApplication sharedApplication] keyWindow].rootViewController.view; - [printPicker presentFromRect:view.frame inView:view animated:YES completionHandler:completionHandler]; + UIViewController *rootViewController = UIApplication.sharedApplication.delegate.window.rootViewController; + while (rootViewController.presentedViewController != nil) { + rootViewController = rootViewController.presentedViewController; + } + CGRect rect = CGRectMake(rootViewController.view.bounds.size.width/2, rootViewController.view.bounds.size.height/2, 1, 1); + [printPicker + presentFromRect:rect + inView:rootViewController.view + animated:YES + completionHandler:completionHandler + ]; } else { // iPhone [printPicker presentAnimated:YES completionHandler:completionHandler]; } @@ -141,6 +154,13 @@ -(UIViewController*)printInteractionControllerParentViewController:(UIPrintInter result = result.presentedViewController; } return result; + //TODO We may need it : +// UIViewController *rootViewController = UIApplication.sharedApplication.delegate.window.rootViewController; +// while (rootViewController.presentedViewController != nil) { +// rootViewController = rootViewController.presentedViewController; +// } +// return rootViewController; + } -(void)printInteractionControllerWillDismissPrinterOptions:(UIPrintInteractionController*)printInteractionController {}