Skip to content

Commit

Permalink
#88 curl and flip didn't behave well with wkwebview (iOS)
Browse files Browse the repository at this point in the history
  • Loading branch information
EddyVerbruggen committed Mar 6, 2016
1 parent 860e2f6 commit 611528b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 64 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.6.2",
"version": "0.6.3",
"name": "com.telerik.plugins.nativepagetransitions",
"cordova_name": "Native Page Transitions",
"description": "Slide out the current page to reveal the next one. By a native transitions.",
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
id="com.telerik.plugins.nativepagetransitions"
version="0.6.2">
version="0.6.3">

<name>Native Page Transitions</name>

Expand Down
90 changes: 28 additions & 62 deletions src/ios/NativePageTransitions.m
Original file line number Diff line number Diff line change
Expand Up @@ -87,23 +87,9 @@ - (void) slide:(CDVInvokedUrlCommand*)command {
height = temp;
}

screenshotRect.size.height -= _webViewPushedDownPixels == 40 ? 20 : 0;

CGSize viewSize = self.viewController.view.bounds.size;

UIGraphicsBeginImageContextWithOptions(viewSize, YES, 0.0f);
// Since drawViewHierarchyInRect is slower than renderInContext we should only
// use it to overcome the bug in WKWebView
if (self.wkWebView != nil) {
[self.viewController.view drawViewHierarchyInRect:self.viewController.view.bounds afterScreenUpdates:NO];
} else {
[self.viewController.view.layer renderInContext:UIGraphicsGetCurrentContext()];
}

// Read the UIImage object
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

UIImage *image =[self grabScreenshot];
screenshotRect.size.height -= _webViewPushedDownPixels == 40 ? 20 : 0;
_screenShotImageView = [[UIImageView alloc]initWithFrame:screenshotRect];
[_screenShotImageView setImage:image];
CGFloat retinaFactor = DISPLAY_SCALE;
Expand Down Expand Up @@ -315,18 +301,8 @@ - (void) performSlideTransition {

- (void) flip:(CDVInvokedUrlCommand*)command {
_command = command;
NSMutableDictionary *args = [command.arguments objectAtIndex:0];

// overlay the webview with a screenshot to prevent the user from seeing changes in the webview before the flip kicks in
CGSize viewSize = self.viewController.view.bounds.size;

UIGraphicsBeginImageContextWithOptions(viewSize, YES, 0.0f);
[self.viewController.view.layer renderInContext:UIGraphicsGetCurrentContext()];

// Read the UIImage object
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

UIImage *image =[self grabScreenshot];
CGFloat width = self.viewController.view.frame.size.width;
CGFloat height = self.viewController.view.frame.size.height;
[_screenShotImageView setFrame:CGRectMake(0, 0, width, height)];
Expand All @@ -335,6 +311,7 @@ - (void) flip:(CDVInvokedUrlCommand*)command {
[_screenShotImageView setImage:image];
[self.transitionView.superview insertSubview:_screenShotImageView aboveSubview:self.transitionView];

NSMutableDictionary *args = [command.arguments objectAtIndex:0];
if ([self loadHrefIfPassed:[args objectForKey:@"href"]]) {
// pass in -1 for manual (requires you to call executePendingTransition)
NSTimeInterval delay = [[args objectForKey:@"iosdelay"] doubleValue];
Expand Down Expand Up @@ -433,6 +410,9 @@ - (void) performFlipTransition {

- (void) drawer:(CDVInvokedUrlCommand*)command {
_command = command;

UIImage *image =[self grabScreenshot];

NSMutableDictionary *args = [command.arguments objectAtIndex:0];
NSString *action = [args objectForKey:@"action"];
NSTimeInterval duration = [[args objectForKey:@"duration"] doubleValue];
Expand All @@ -453,18 +433,6 @@ - (void) drawer:(CDVInvokedUrlCommand*)command {
height = temp;
}

CGSize viewSize = self.viewController.view.bounds.size;
UIGraphicsBeginImageContextWithOptions(viewSize, YES, 0.0f);
if (self.wkWebView != nil) {
[self.viewController.view drawViewHierarchyInRect:self.viewController.view.bounds afterScreenUpdates:NO];
} else {
[self.viewController.view.layer renderInContext:UIGraphicsGetCurrentContext()];
}

// Read the UIImage object
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

[_screenShotImageView setFrame:screenshotRect];
if ([action isEqualToString:@"open"]) {
_screenShotImageView = [[UIImageView alloc]initWithFrame:screenshotRect];
Expand Down Expand Up @@ -588,21 +556,10 @@ - (void) performDrawerTransition {

- (void) fade:(CDVInvokedUrlCommand*)command {
_command = command;
NSMutableDictionary *args = [command.arguments objectAtIndex:0];

// overlay the webview with a screenshot to prevent the user from seeing changes in the webview before the fade kicks in
CGSize viewSize = self.viewController.view.bounds.size;

UIGraphicsBeginImageContextWithOptions(viewSize, YES, 0.0f);
if (self.wkWebView != nil) {
[self.viewController.view drawViewHierarchyInRect:self.viewController.view.bounds afterScreenUpdates:NO];
} else {
[self.viewController.view.layer renderInContext:UIGraphicsGetCurrentContext()];
}
UIImage *image =[self grabScreenshot];

// Read the UIImage object
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSMutableDictionary *args = [command.arguments objectAtIndex:0];

CGFloat width = self.viewController.view.frame.size.width;
CGFloat height = self.viewController.view.frame.size.height;
Expand Down Expand Up @@ -658,22 +615,15 @@ - (void) performFadeTransition {

- (void) curl:(CDVInvokedUrlCommand*)command {
_command = command;

UIImage *image =[self grabScreenshot];

NSMutableDictionary *args = [command.arguments objectAtIndex:0];
NSTimeInterval duration = [[args objectForKey:@"duration"] doubleValue];

// duration is passed in ms, but needs to be in sec here
duration = duration / 1000;

// overlay the webview with a screenshot to prevent the user from seeing changes in the webview before the flip kicks in
CGSize viewSize = self.viewController.view.bounds.size;

UIGraphicsBeginImageContextWithOptions(viewSize, YES, 0.0f);
[self.viewController.view.layer renderInContext:UIGraphicsGetCurrentContext()];

// Read the UIImage object
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

CGFloat width = self.viewController.view.frame.size.width;
CGFloat height = self.viewController.view.frame.size.height;
[_screenShotImageView setFrame:CGRectMake(0, 0, width, height)];
Expand Down Expand Up @@ -736,6 +686,22 @@ - (void) performCurlTransition {
});
}

- (UIImage*) grabScreenshot {
UIGraphicsBeginImageContextWithOptions(self.viewController.view.bounds.size, YES, 0.0f);

// Since drawViewHierarchyInRect is slower than renderInContext we should only use it to overcome the bug in WKWebView
if (self.wkWebView != nil) {
[self.viewController.view drawViewHierarchyInRect:self.viewController.view.bounds afterScreenUpdates:NO];
} else {
[self.viewController.view.layer renderInContext:UIGraphicsGetCurrentContext()];
}

// Read the UIImage object
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}

- (BOOL) loadHrefIfPassed:(NSString*) href {
UIWebView *uiwebview = nil;
if ([self.webView isKindOfClass:[UIWebView class]]) {
Expand Down

0 comments on commit 611528b

Please sign in to comment.