Skip to content

Commit

Permalink
Improve layout
Browse files Browse the repository at this point in the history
  • Loading branch information
hansemannn committed Jan 30, 2017
1 parent 40d092e commit 71349e3
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 110 deletions.
7 changes: 7 additions & 0 deletions iphone/Classes/CBZSplashView/CBZRasterSplashView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 0 additions & 5 deletions iphone/Classes/TiSplashviewSplashView.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@

@interface TiSplashviewSplashView : TiUIView {
CBZSplashView *splashView;

TiDimension width;
TiDimension height;
CGFloat autoHeight;
CGFloat autoWidth;
}

- (CBZSplashView *)splashView;
Expand Down
97 changes: 13 additions & 84 deletions iphone/Classes/TiSplashviewSplashView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

Expand All @@ -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]) {
Expand All @@ -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
6 changes: 3 additions & 3 deletions iphone/Classes/TiSplashviewSplashViewProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
46 changes: 28 additions & 18 deletions iphone/Classes/TiSplashviewSplashViewProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 71349e3

Please sign in to comment.