summaryrefslogtreecommitdiff
path: root/StoneIsland/plugins/cordova-plugin-splashscreen/src/ios
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2016-11-08 12:37:03 -0500
committerJules Laplace <jules@okfoc.us>2016-11-08 12:37:03 -0500
commitef4f212fc1482136dba1e690ec589b315b4a377f (patch)
tree0b7e16d72567fafcfd3e08d7c5c591ad07a63458 /StoneIsland/plugins/cordova-plugin-splashscreen/src/ios
parent5fa81da81260d65113f57a293b6256d334fe8e2d (diff)
build 0.7.0
Diffstat (limited to 'StoneIsland/plugins/cordova-plugin-splashscreen/src/ios')
-rw-r--r--StoneIsland/plugins/cordova-plugin-splashscreen/src/ios/CDVSplashScreen.h2
-rw-r--r--StoneIsland/plugins/cordova-plugin-splashscreen/src/ios/CDVSplashScreen.m181
-rw-r--r--StoneIsland/plugins/cordova-plugin-splashscreen/src/ios/CDVViewController+SplashScreen.m7
3 files changed, 153 insertions, 37 deletions
diff --git a/StoneIsland/plugins/cordova-plugin-splashscreen/src/ios/CDVSplashScreen.h b/StoneIsland/plugins/cordova-plugin-splashscreen/src/ios/CDVSplashScreen.h
index 0d6ae397..ec5d6022 100644
--- a/StoneIsland/plugins/cordova-plugin-splashscreen/src/ios/CDVSplashScreen.h
+++ b/StoneIsland/plugins/cordova-plugin-splashscreen/src/ios/CDVSplashScreen.h
@@ -23,6 +23,7 @@
typedef struct {
BOOL iPhone;
BOOL iPad;
+ BOOL iPhone4;
BOOL iPhone5;
BOOL iPhone6;
BOOL iPhone6Plus;
@@ -35,6 +36,7 @@ typedef struct {
UIImageView* _imageView;
NSString* _curImageName;
BOOL _visible;
+ BOOL _destroyed;
}
- (void)show:(CDVInvokedUrlCommand*)command;
diff --git a/StoneIsland/plugins/cordova-plugin-splashscreen/src/ios/CDVSplashScreen.m b/StoneIsland/plugins/cordova-plugin-splashscreen/src/ios/CDVSplashScreen.m
index a1add304..8ad8116b 100644
--- a/StoneIsland/plugins/cordova-plugin-splashscreen/src/ios/CDVSplashScreen.m
+++ b/StoneIsland/plugins/cordova-plugin-splashscreen/src/ios/CDVSplashScreen.m
@@ -23,6 +23,7 @@
#import "CDVViewController+SplashScreen.h"
#define kSplashScreenDurationDefault 3000.0f
+#define kFadeDurationDefault 500.0f
@implementation CDVSplashScreen
@@ -41,7 +42,7 @@
- (void)hide:(CDVInvokedUrlCommand*)command
{
- [self setVisible:NO];
+ [self setVisible:NO andForce:YES];
}
- (void)pageDidLoad
@@ -76,7 +77,7 @@
BOOL autorotateValue = (device.iPad || device.iPhone6Plus) ?
[(CDVViewController *)self.viewController shouldAutorotateDefaultValue] :
NO;
-
+
[(CDVViewController *)self.viewController setEnabledAutorotation:autorotateValue];
NSString* topActivityIndicator = [self.commandDelegate.settings objectForKey:[@"TopActivityIndicator" lowercaseString]];
@@ -120,6 +121,7 @@
[parentView addObserver:self forKeyPath:@"bounds" options:0 context:nil];
[self updateImage];
+ _destroyed = NO;
}
- (void)hideViews
@@ -130,6 +132,7 @@
- (void)destroyViews
{
+ _destroyed = YES;
[(CDVViewController *)self.viewController setEnabledAutorotation:[(CDVViewController *)self.viewController shouldAutorotateDefaultValue]];
[_imageView removeFromSuperview];
@@ -139,30 +142,39 @@
_curImageName = nil;
self.viewController.view.userInteractionEnabled = YES; // re-enable user interaction upon completion
- [self.viewController.view removeObserver:self forKeyPath:@"frame"];
- [self.viewController.view removeObserver:self forKeyPath:@"bounds"];
+ @try {
+ [self.viewController.view removeObserver:self forKeyPath:@"frame"];
+ [self.viewController.view removeObserver:self forKeyPath:@"bounds"];
+ }
+ @catch (NSException *exception) {
+ // When reloading the page from a remotely connected Safari, there
+ // are no observers, so the removeObserver method throws an exception,
+ // that we can safely ignore.
+ // Alternatively we can check whether there are observers before calling removeObserver
+ }
}
- (CDV_iOSDevice) getCurrentDevice
{
CDV_iOSDevice device;
-
+
UIScreen* mainScreen = [UIScreen mainScreen];
CGFloat mainScreenHeight = mainScreen.bounds.size.height;
CGFloat mainScreenWidth = mainScreen.bounds.size.width;
-
+
int limit = MAX(mainScreenHeight,mainScreenWidth);
-
+
device.iPad = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad);
device.iPhone = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone);
device.retina = ([mainScreen scale] == 2.0);
+ device.iPhone4 = (device.iPhone && limit == 480.0);
device.iPhone5 = (device.iPhone && limit == 568.0);
// note these below is not a true device detect, for example if you are on an
// iPhone 6/6+ but the app is scaled it will prob set iPhone5 as true, but
// this is appropriate for detecting the runtime screen environment
device.iPhone6 = (device.iPhone && limit == 667.0);
device.iPhone6Plus = (device.iPhone && limit == 736.0);
-
+
return device;
}
@@ -170,15 +182,15 @@
{
// Use UILaunchImageFile if specified in plist. Otherwise, use Default.
NSString* imageName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UILaunchImageFile"];
-
+
NSUInteger supportedOrientations = [orientationDelegate supportedInterfaceOrientations];
-
+
// Checks to see if the developer has locked the orientation to use only one of Portrait or Landscape
BOOL supportsLandscape = (supportedOrientations & UIInterfaceOrientationMaskLandscape);
BOOL supportsPortrait = (supportedOrientations & UIInterfaceOrientationMaskPortrait || supportedOrientations & UIInterfaceOrientationMaskPortraitUpsideDown);
// this means there are no mixed orientations in there
BOOL isOrientationLocked = !(supportsPortrait && supportsLandscape);
-
+
if (imageName)
{
imageName = [imageName stringByDeletingPathExtension];
@@ -187,7 +199,23 @@
{
imageName = @"Default";
}
-
+
+ // Add Asset Catalog specific prefixes
+ if ([imageName isEqualToString:@"LaunchImage"])
+ {
+ if (device.iPhone4 || device.iPhone5 || device.iPad) {
+ imageName = [imageName stringByAppendingString:@"-700"];
+ } else if(device.iPhone6) {
+ imageName = [imageName stringByAppendingString:@"-800"];
+ } else if(device.iPhone6Plus) {
+ imageName = [imageName stringByAppendingString:@"-800"];
+ if (currentOrientation == UIInterfaceOrientationPortrait || currentOrientation == UIInterfaceOrientationPortraitUpsideDown)
+ {
+ imageName = [imageName stringByAppendingString:@"-Portrait"];
+ }
+ }
+ }
+
if (device.iPhone5)
{ // does not support landscape
imageName = [imageName stringByAppendingString:@"-568h"];
@@ -231,7 +259,7 @@
case UIInterfaceOrientationLandscapeRight:
imageName = [imageName stringByAppendingString:@"-Landscape"];
break;
-
+
case UIInterfaceOrientationPortrait:
case UIInterfaceOrientationPortraitUpsideDown:
default:
@@ -240,14 +268,51 @@
}
}
}
-
+
return imageName;
}
+- (UIInterfaceOrientation)getCurrentOrientation
+{
+ UIInterfaceOrientation iOrientation = [UIApplication sharedApplication].statusBarOrientation;
+ UIDeviceOrientation dOrientation = [UIDevice currentDevice].orientation;
+
+ bool landscape;
+
+ if (dOrientation == UIDeviceOrientationUnknown || dOrientation == UIDeviceOrientationFaceUp || dOrientation == UIDeviceOrientationFaceDown) {
+ // If the device is laying down, use the UIInterfaceOrientation based on the status bar.
+ landscape = UIInterfaceOrientationIsLandscape(iOrientation);
+ } else {
+ // If the device is not laying down, use UIDeviceOrientation.
+ landscape = UIDeviceOrientationIsLandscape(dOrientation);
+
+ // There's a bug in iOS!!!! http://openradar.appspot.com/7216046
+ // So values needs to be reversed for landscape!
+ if (dOrientation == UIDeviceOrientationLandscapeLeft)
+ {
+ iOrientation = UIInterfaceOrientationLandscapeRight;
+ }
+ else if (dOrientation == UIDeviceOrientationLandscapeRight)
+ {
+ iOrientation = UIInterfaceOrientationLandscapeLeft;
+ }
+ else if (dOrientation == UIDeviceOrientationPortrait)
+ {
+ iOrientation = UIInterfaceOrientationPortrait;
+ }
+ else if (dOrientation == UIDeviceOrientationPortraitUpsideDown)
+ {
+ iOrientation = UIInterfaceOrientationPortraitUpsideDown;
+ }
+ }
+
+ return iOrientation;
+}
+
// Sets the view's frame and image.
- (void)updateImage
{
- NSString* imageName = [self getImageName:[[UIApplication sharedApplication] statusBarOrientation] delegate:(id<CDVScreenOrientationDelegate>)self.viewController device:[self getCurrentDevice]];
+ NSString* imageName = [self getImageName:[self getCurrentOrientation] delegate:(id<CDVScreenOrientationDelegate>)self.viewController device:[self getCurrentDevice]];
if (![imageName isEqualToString:_curImageName])
{
@@ -273,7 +338,7 @@
CGRect imgBounds = (img) ? CGRectMake(0, 0, img.size.width, img.size.height) : CGRectZero;
CGSize screenSize = [self.viewController.view convertRect:[UIScreen mainScreen].bounds fromView:nil].size;
- UIInterfaceOrientation orientation = self.viewController.interfaceOrientation;
+ UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
CGAffineTransform imgTransform = CGAffineTransformIdentity;
/* If and only if an iPhone application is landscape-only as per
@@ -281,8 +346,8 @@
* landscape. In this case the image must be rotated in order to appear
* correctly.
*/
- BOOL isIPad = [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad;
- if (UIInterfaceOrientationIsLandscape(orientation) && !isIPad)
+ CDV_iOSDevice device = [self getCurrentDevice];
+ if (UIInterfaceOrientationIsLandscape(orientation) && !device.iPhone6Plus && !device.iPad)
{
imgTransform = CGAffineTransformMakeRotation(M_PI / 2);
imgBounds.size = CGSizeMake(imgBounds.size.height, imgBounds.size.width);
@@ -322,26 +387,52 @@
- (void)setVisible:(BOOL)visible
{
- if (visible != _visible)
+ [self setVisible:visible andForce:NO];
+}
+
+- (void)setVisible:(BOOL)visible andForce:(BOOL)force
+{
+ if (visible != _visible || force)
{
_visible = visible;
id fadeSplashScreenValue = [self.commandDelegate.settings objectForKey:[@"FadeSplashScreen" lowercaseString]];
id fadeSplashScreenDuration = [self.commandDelegate.settings objectForKey:[@"FadeSplashScreenDuration" lowercaseString]];
- float fadeDuration = fadeSplashScreenDuration == nil ? kSplashScreenDurationDefault : [fadeSplashScreenDuration floatValue];
+ float fadeDuration = fadeSplashScreenDuration == nil ? kFadeDurationDefault : [fadeSplashScreenDuration floatValue];
+
+ id splashDurationString = [self.commandDelegate.settings objectForKey: [@"SplashScreenDelay" lowercaseString]];
+ float splashDuration = splashDurationString == nil ? kSplashScreenDurationDefault : [splashDurationString floatValue];
- if ((fadeSplashScreenValue == nil) || ![fadeSplashScreenValue boolValue])
+ id autoHideSplashScreenValue = [self.commandDelegate.settings objectForKey:[@"AutoHideSplashScreen" lowercaseString]];
+ BOOL autoHideSplashScreen = true;
+
+ if (autoHideSplashScreenValue != nil) {
+ autoHideSplashScreen = [autoHideSplashScreenValue boolValue];
+ }
+
+ if (!autoHideSplashScreen) {
+ // CB-10412 SplashScreenDelay does not make sense if the splashscreen is hidden manually
+ splashDuration = 0;
+ }
+
+
+ if (fadeSplashScreenValue == nil)
+ {
+ fadeSplashScreenValue = @"true";
+ }
+
+ if (![fadeSplashScreenValue boolValue])
{
fadeDuration = 0;
}
- else if(fadeDuration < 30)
+ else if (fadeDuration < 30)
{
// [CB-9750] This value used to be in decimal seconds, so we will assume that if someone specifies 10
// they mean 10 seconds, and not the meaningless 10ms
fadeDuration *= 1000;
}
-
+
if (_visible)
{
if (_imageView == nil)
@@ -349,26 +440,42 @@
[self createViews];
}
}
- else if (fadeDuration == 0)
+ else if (fadeDuration == 0 && splashDuration == 0)
{
[self destroyViews];
}
else
{
__weak __typeof(self) weakSelf = self;
- [UIView transitionWithView:self.viewController.view
- duration:(fadeDuration / 1000)
- options:UIViewAnimationOptionTransitionNone
- animations:^(void) {
- [weakSelf hideViews];
- }
- completion:^(BOOL finished) {
- if (finished) {
- [weakSelf destroyViews];
- // TODO: It might also be nice to have a js event happen here -jm
- }
- }
- ];
+ float effectiveSplashDuration;
+
+ // [CB-10562] AutoHideSplashScreen may be "true" but we should still be able to hide the splashscreen manually.
+ if (!autoHideSplashScreen || force) {
+ effectiveSplashDuration = (fadeDuration) / 1000;
+ } else {
+ effectiveSplashDuration = (splashDuration - fadeDuration) / 1000;
+ }
+
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (uint64_t) effectiveSplashDuration * NSEC_PER_SEC), dispatch_get_main_queue(), CFBridgingRelease(CFBridgingRetain(^(void) {
+ if (!_destroyed) {
+ [UIView transitionWithView:self.viewController.view
+ duration:(fadeDuration / 1000)
+ options:UIViewAnimationOptionTransitionNone
+ animations:^(void) {
+ [weakSelf hideViews];
+ }
+ completion:^(BOOL finished) {
+ // Always destroy views, otherwise you could have an
+ // invisible splashscreen that is overlayed over your active views
+ // which causes that no touch events are passed
+ if (!_destroyed) {
+ [weakSelf destroyViews];
+ // TODO: It might also be nice to have a js event happen here -jm
+ }
+ }
+ ];
+ }
+ })));
}
}
}
diff --git a/StoneIsland/plugins/cordova-plugin-splashscreen/src/ios/CDVViewController+SplashScreen.m b/StoneIsland/plugins/cordova-plugin-splashscreen/src/ios/CDVViewController+SplashScreen.m
index 5736b6f2..e483def6 100644
--- a/StoneIsland/plugins/cordova-plugin-splashscreen/src/ios/CDVViewController+SplashScreen.m
+++ b/StoneIsland/plugins/cordova-plugin-splashscreen/src/ios/CDVViewController+SplashScreen.m
@@ -35,6 +35,13 @@
- (BOOL)enabledAutorotation
{
NSNumber *number = (NSNumber *)objc_getAssociatedObject(self, @selector(enabledAutorotation));
+
+ // Defaulting to YES to correspond parent CDVViewController behavior
+ if (number == nil)
+ {
+ return YES;
+ }
+
return [number boolValue];
}