From 71349e3b2649aea69c345ee1629f248e12892a90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans=20Kn=C3=B6chel?= Date: Mon, 30 Jan 2017 15:19:51 +0100 Subject: [PATCH] Improve layout --- .../CBZSplashView/CBZRasterSplashView.m | 7 ++ iphone/Classes/TiSplashviewSplashView.h | 5 - iphone/Classes/TiSplashviewSplashView.m | 97 +++---------------- iphone/Classes/TiSplashviewSplashViewProxy.h | 6 +- iphone/Classes/TiSplashviewSplashViewProxy.m | 46 +++++---- 5 files changed, 51 insertions(+), 110 deletions(-) diff --git a/iphone/Classes/CBZSplashView/CBZRasterSplashView.m b/iphone/Classes/CBZSplashView/CBZRasterSplashView.m index be1553f..468e48a 100755 --- a/iphone/Classes/CBZSplashView/CBZRasterSplashView.m +++ b/iphone/Classes/CBZSplashView/CBZRasterSplashView.m @@ -37,6 +37,13 @@ - (instancetype)initWithIconImage:(UIImage *)icon backgroundColor:(UIColor *)col return self; } +- (void)setIconStartSize:(CGSize)iconStartSize +{ + [super setIconStartSize:iconStartSize]; + self.iconImageView.frame = CGRectMake(0, 0, iconStartSize.width, iconStartSize.height); + self.iconImageView.center = self.center; +} + - (void)startAnimationWithCompletionHandler:(void (^)())completionHandler { __block __weak CBZRasterSplashView *weakSelf = self; diff --git a/iphone/Classes/TiSplashviewSplashView.h b/iphone/Classes/TiSplashviewSplashView.h index c714501..b467838 100644 --- a/iphone/Classes/TiSplashviewSplashView.h +++ b/iphone/Classes/TiSplashviewSplashView.h @@ -9,11 +9,6 @@ @interface TiSplashviewSplashView : TiUIView { CBZSplashView *splashView; - - TiDimension width; - TiDimension height; - CGFloat autoHeight; - CGFloat autoWidth; } - (CBZSplashView *)splashView; diff --git a/iphone/Classes/TiSplashviewSplashView.m b/iphone/Classes/TiSplashviewSplashView.m index 45fb17a..bdecf0a 100644 --- a/iphone/Classes/TiSplashviewSplashView.m +++ b/iphone/Classes/TiSplashviewSplashView.m @@ -14,19 +14,25 @@ - (CBZSplashView *)splashView { if (splashView == nil) { id image = [[self proxy] valueForKey:@"image"]; - id backgroundColor = [[self proxy] valueForKey:@"backgroundColor"]; - id iconStartSize = [[self proxy] valueForKey:@"iconStartSize"]; + id path = [[self proxy] valueForKey:@"path"]; + id fillColor = [[self proxy] valueForKey:@"fillColor"]; ENSURE_TYPE(image, NSString); - ENSURE_TYPE(backgroundColor, NSString); - ENSURE_TYPE_OR_NIL(iconStartSize, NSDictionary); + ENSURE_TYPE(fillColor, NSString); - splashView = [CBZSplashView splashViewWithIcon:[TiUtils image:image proxy:self.proxy] backgroundColor:[[TiUtils colorValue:backgroundColor] _color]]; + if ((image && path) || (!image && !path)) { + NSLog(@"[ERROR] Ti.SplashView: Use either a path or an image"); + return; + } - if (iconStartSize) { - [splashView setIconStartSize:CGSizeMake(300,300)]; + if (image) { + splashView = [CBZSplashView splashViewWithIcon:[TiUtils toImage:image proxy:self.proxy] backgroundColor:[[TiUtils colorValue:fillColor] _color]]; + } else if (path) { + NSLog(@"[ERROR] Ti.SplashView: The path serialization is not implemented, yet!"); } + [splashView setAutoresizingMask:UIViewAutoresizingNone]; + [self addSubview:splashView]; } @@ -45,39 +51,8 @@ - (void)initializeTiLayoutView } #endif -#pragma mark Public APIs - -- (void)setWidth_:(id)width_ -{ - width = TiDimensionFromObject(width_); - [self updateContentMode]; -} - -- (void)setHeight_:(id)height_ -{ - height = TiDimensionFromObject(height_); - [self updateContentMode]; -} - #pragma mark Layout helper -- (void)updateContentMode -{ - if (self != nil) { - [self setContentMode:[self contentModeForFluidView]]; - } -} - -- (UIViewContentMode)contentModeForFluidView -{ - if (TiDimensionIsAuto(width) || TiDimensionIsAutoSize(width) || TiDimensionIsUndefined(width) || - TiDimensionIsAuto(height) || TiDimensionIsAutoSize(height) || TiDimensionIsUndefined(height)) { - return UIViewContentModeScaleAspectFit; - } else { - return UIViewContentModeScaleToFill; - } -} - - (void)frameSizeChanged:(CGRect)frame bounds:(CGRect)bounds { for (UIView *child in [[self splashView] subviews]) { @@ -87,50 +62,4 @@ - (void)frameSizeChanged:(CGRect)frame bounds:(CGRect)bounds [super frameSizeChanged:frame bounds:bounds]; } -- (CGFloat)contentWidthForWidth:(CGFloat)suggestedWidth -{ - if (autoWidth > 0) { - //If height is DIP returned a scaled autowidth to maintain aspect ratio - if (TiDimensionIsDip(height) && autoHeight > 0) { - return roundf(autoWidth*height.value/autoHeight); - } - return autoWidth; - } - - CGFloat calculatedWidth = TiDimensionCalculateValue(width, autoWidth); - if (calculatedWidth > 0) { - return calculatedWidth; - } - - return 0; -} - -- (CGFloat)contentHeightForWidth:(CGFloat)width_ -{ - if (width_ != autoWidth && autoWidth>0 && autoHeight > 0) { - return (width_*autoHeight/autoWidth); - } - - if (autoHeight > 0) { - return autoHeight; - } - - CGFloat calculatedHeight = TiDimensionCalculateValue(height, autoHeight); - if (calculatedHeight > 0) { - return calculatedHeight; - } - - return 0; -} - -- (UIViewContentMode)contentMode -{ - if (TiDimensionIsAuto(width) || TiDimensionIsAutoSize(width) || TiDimensionIsUndefined(width) || - TiDimensionIsAuto(height) || TiDimensionIsAutoSize(height) || TiDimensionIsUndefined(height)) { - return UIViewContentModeScaleAspectFit; - } else { - return UIViewContentModeScaleToFill; - } -} - @end diff --git a/iphone/Classes/TiSplashviewSplashViewProxy.h b/iphone/Classes/TiSplashviewSplashViewProxy.h index 0bf2506..1499ac0 100644 --- a/iphone/Classes/TiSplashviewSplashViewProxy.h +++ b/iphone/Classes/TiSplashviewSplashViewProxy.h @@ -10,10 +10,10 @@ } -- (void)startAnimation:(id)unused; +- (void)startAnimation:(id)args; -- (void)setIconColor:(id)value; +- (void)setAnimationDuration:(id)value; -- (void)setIconStartSize:(id)value; +- (void)setIconColor:(id)value; @end diff --git a/iphone/Classes/TiSplashviewSplashViewProxy.m b/iphone/Classes/TiSplashviewSplashViewProxy.m index e0be000..e486d3c 100644 --- a/iphone/Classes/TiSplashviewSplashViewProxy.m +++ b/iphone/Classes/TiSplashviewSplashViewProxy.m @@ -13,31 +13,41 @@ @implementation TiSplashviewSplashViewProxy #pragma mark Public API's -- (void)startAnimation:(id)unused +- (void)startAnimation:(id)args { - [[[self splashView] splashView] startAnimation]; + ENSURE_UI_THREAD(startAnimation, args); + + if ([args count] == 1) { + KrollCallback *callback = nil; + ENSURE_ARG_AT_INDEX(callback, args, 0, KrollCallback); + + [[[self splashView] splashView] startAnimationWithCompletionHandler:^{ + NSDictionary *propertiesDict = @{@"finished": NUMBOOL(YES)}; + NSArray *invocationArray = [[NSArray alloc] initWithObjects:&propertiesDict count:1]; + + [callback call:invocationArray thisObject:self]; + }]; + } else if ([args count] == 0) { + [[[self splashView] splashView] startAnimation]; + } else { + NSLog(@"[ERROR] Ti.SplashView: Either provide a callback to startAnimation or use it without arguments."); + } } -- (void)setIconColor:(id)value +- (void)setAnimationDuration:(id)value { - ENSURE_TYPE_OR_NIL(value, NSString); - [[[self splashView] splashView] setIconColor:[[TiUtils colorValue:value] _color]]; + ENSURE_TYPE(value, NSNumber); + ENSURE_UI_THREAD(setAnimationDuration, value); + + [[[self splashView] splashView] setAnimationDuration:[TiUtils floatValue:value]]; } - -#pragma mark Helper - -USE_VIEW_FOR_CONTENT_WIDTH - -USE_VIEW_FOR_CONTENT_HEIGHT - -- (TiDimension)defaultAutoWidthBehavior:(id)unused + +- (void)setIconColor:(id)value { - return TiDimensionAutoFill; -} + ENSURE_TYPE_OR_NIL(value, NSString); + ENSURE_UI_THREAD(setIconColor, value); -- (TiDimension)defaultAutoHeightBehavior:(id)unused -{ - return TiDimensionAutoFill; + [[[self splashView] splashView] setIconColor:[[TiUtils colorValue:value] _color]]; } - (TiSplashviewSplashView *)splashView