-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TIMOB-20176] iOS: Support UIVisualEffectView #7599
Changes from 4 commits
64a3219
f817082
8b5c025
e0279ce
3881a7b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
--- | ||
name: Titanium.UI.iOS.BlurView | ||
summary: | | ||
A <Titanium.UI.iOS.BlurView> object gives you an easy way implement some complex visual effects. | ||
Depending on the desired effect, the effect may affect content layered behind the view or | ||
content added to the visual effect view's contentView. | ||
|
||
For more infos on BlurView's, refer to the official [Apple documentation](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIVisualEffectView/). | ||
|
||
extends: Titanium.UI.View | ||
platforms: [iphone,ipad] | ||
since: "6.0.0" | ||
osver: {ios:{min: "8.0"}} | ||
|
||
properties: | ||
- name: effect | ||
summary: The effect you provide for the view. | ||
type: Number | ||
constants: [Titanium.UI.iOS.BLUR_EFFECT_STYLE_EXTRA_LIGHT,Titanium.UI.iOS.BLUR_EFFECT_STYLE_LIGHT,Titanium.UI.iOS.BLUR_EFFECT_STYLE_DARK] | ||
default: undefined (no effect is applied) | ||
|
||
examples: | ||
- title: Basic Blur View | ||
example: | | ||
The following example shows how to create a simple Ti.UI.iOS.BlurView: | ||
|
||
var win = Ti.UI.createWindow({ | ||
backgroundColor: "#fff" | ||
}); | ||
|
||
/* | ||
* Reference Image | ||
*/ | ||
var img = Ti.UI.createImageView({ | ||
image: "/default_app_logo.png", | ||
top: 100, | ||
width: 300, | ||
height: 300 | ||
}); | ||
|
||
/* | ||
* Blur View | ||
*/ | ||
var blur = Ti.UI.iOS.createBlurView({ | ||
width: Ti.UI.FILL, | ||
height: Ti.UI.FILL | ||
}); | ||
|
||
img.add(blur); | ||
|
||
/* | ||
* Effect Controls | ||
*/ | ||
var tabs = Ti.UI.iOS.createTabbedBar({ | ||
labels: ["Extra light", "Light", "Dark"], | ||
bottom: 100 | ||
}); | ||
|
||
var effects = [ | ||
Ti.UI.iOS.BLUR_EFFECT_STYLE_EXTRA_LIGHT, | ||
Ti.UI.iOS.BLUR_EFFECT_STYLE_LIGHT, | ||
Ti.UI.iOS.BLUR_EFFECT_STYLE_DARK, | ||
]; | ||
|
||
tabs.addEventListener("click", function(e) { | ||
blur.setEffect(effects[e.index]); | ||
}); | ||
|
||
win.add(tabs); | ||
win.add(img); | ||
win.open(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* Appcelerator Titanium Mobile | ||
* Copyright (c) 2009-2015 by Appcelerator, Inc. All Rights Reserved. | ||
* Licensed under the terms of the Apache Public License | ||
* Please see the LICENSE included with this distribution for details. | ||
*/ | ||
#ifdef USE_TI_UIIOSBLURVIEW | ||
#import "TiUIView.h" | ||
|
||
@interface TiUIiOSBlurView : TiUIView { | ||
UIVisualEffectView *blurView; | ||
|
||
TiDimension width; | ||
TiDimension height; | ||
CGFloat autoHeight; | ||
CGFloat autoWidth; | ||
} | ||
|
||
@end | ||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
/** | ||
* Appcelerator Titanium Mobile | ||
* Copyright (c) 2009-2015 by Appcelerator, Inc. All Rights Reserved. | ||
* Licensed under the terms of the Apache Public License | ||
* Please see the LICENSE included with this distribution for details. | ||
*/ | ||
|
||
#ifdef USE_TI_UIIOSBLURVIEW | ||
#import "TiUIiOSBlurView.h" | ||
#import "TiUIiOSBlurViewProxy.h" | ||
|
||
@implementation TiUIiOSBlurView | ||
|
||
-(UIVisualEffectView*)blurView | ||
{ | ||
if (blurView == nil) { | ||
|
||
blurView = [[UIVisualEffectView alloc] initWithFrame:[self frame]]; | ||
|
||
[blurView setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight]; | ||
[blurView setContentMode:[self contentModeForBlurView]]; | ||
|
||
[self addSubview:blurView]; | ||
} | ||
|
||
return blurView; | ||
} | ||
|
||
#pragma mark Cleanup | ||
|
||
-(void)dealloc | ||
{ | ||
RELEASE_TO_NIL(blurView); | ||
[super dealloc]; | ||
} | ||
|
||
#pragma mark Public APIs | ||
|
||
-(void)setEffect_:(id)value | ||
{ | ||
ENSURE_TYPE(value, NSNumber); | ||
[[self blurView] setEffect:[UIBlurEffect effectWithStyle:[TiUtils intValue:value def:UIBlurEffectStyleLight]]]; | ||
|
||
[[self proxy] replaceValue:value forKey:@"effect" notification:NO]; | ||
} | ||
|
||
-(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 blurView] != nil) { | ||
[[self blurView] setContentMode:[self contentModeForBlurView]]; | ||
} | ||
} | ||
|
||
-(UIViewContentMode)contentModeForBlurView | ||
{ | ||
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 subviews]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use trailing { to be in consistent with rest of code. |
||
{ | ||
[TiUtils setView:child positionRect: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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use trailing { to be in consistent with rest of code. |
||
{ | ||
return calculatedWidth; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
-(CGFloat)contentHeightForWidth:(CGFloat)width_ | ||
{ | ||
if (width_ != autoWidth && autoWidth>0 && autoHeight > 0) { | ||
return (width_*autoHeight/autoWidth); | ||
} | ||
|
||
if (autoHeight > 0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here as well. |
||
{ | ||
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 | ||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* Appcelerator Titanium Mobile | ||
* Copyright (c) 2009-2015 by Appcelerator, Inc. All Rights Reserved. | ||
* Licensed under the terms of the Apache Public License | ||
* Please see the LICENSE included with this distribution for details. | ||
*/ | ||
#ifdef USE_TI_UIIOSBLURVIEW | ||
#import "TiViewProxy.h" | ||
|
||
@interface TiUIiOSBlurViewProxy : TiViewProxy { | ||
|
||
} | ||
|
||
@end | ||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* Appcelerator Titanium Mobile | ||
* Copyright (c) 2009-2015 by Appcelerator, Inc. All Rights Reserved. | ||
* Licensed under the terms of the Apache Public License | ||
* Please see the LICENSE included with this distribution for details. | ||
*/ | ||
|
||
#ifdef USE_TI_UIIOSBLURVIEW | ||
#import "TiUIiOSBlurViewProxy.h" | ||
#import "TiUIiOSBlurView.h" | ||
#import "TiUtils.h" | ||
|
||
@implementation TiUIiOSBlurViewProxy | ||
|
||
#pragma mark Proxy lifecycle | ||
|
||
-(NSString*)apiName | ||
{ | ||
return @"Ti.UI.iOS.BlurView"; | ||
} | ||
|
||
-(void)dealloc | ||
{ | ||
[super dealloc]; | ||
} | ||
|
||
#pragma mark Public APIs | ||
|
||
- (TiUIiOSBlurView *)blurView | ||
{ | ||
return (TiUIiOSBlurView *)self.view; | ||
} | ||
|
||
@end | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} else {...}
Use trailing { to be in consistent with rest of code.