Skip to content
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

Merged
merged 5 commits into from
Jan 28, 2016
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
71 changes: 71 additions & 0 deletions apidoc/Titanium/UI/iOS/BlurView.yml
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();
2 changes: 1 addition & 1 deletion apidoc/Titanium/UI/iOS/LivePhotoView.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ methods:
summary: An option for how much of the Live Photo's motion and sound content to play.
type: Number
constants: [Titanium.UI.iOS.LIVEPHOTO_PLAYBACK_STYLE_FULL, Titanium.UI.iOS.LIVEPHOTO_PLAYBACK_STYLE_HINT]
default: Titanium.UI.iOS. LIVEPHOTO_PLAYBACK_STYLE_FULL
default: Titanium.UI.iOS.LIVEPHOTO_PLAYBACK_STYLE_FULL

- name: stopPlayback
summary: Ends playback of Live Photo content in the view.
Expand Down
31 changes: 31 additions & 0 deletions apidoc/Titanium/UI/iOS/iOS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,37 @@ properties:
type: Number
permission: read-only

- name: BLUR_EFFECT_STYLE_EXTRA_LIGHT
summary: |
Use with [BlurView.effect](Titanium.UI.iOS.BlurView.effect) to specify a blur effect.
description: |
Creates a blurring effect in the view. The area of the view is lighter in hue than the underlying view.
type: Number
permission: read-only
since: "6.0.0"
osver: {ios: {min: "8.0"}}

- name: BLUR_EFFECT_STYLE_LIGHT
summary: |
Use with [BlurView.effect](Titanium.UI.iOS.BlurView.effect) to specify a blur effect.
description: |
Creates a blurring effect in the view. The area of the view is the same approximate hue
of the underlying view.
type: Number
permission: read-only
since: "6.0.0"
osver: {ios: {min: "8.0"}}

- name: BLUR_EFFECT_STYLE_DARK
summary: |
Use with [BlurView.effect](Titanium.UI.iOS.BlurView.effect) to specify a blur effect.
description: |
Creates a blurring effect in the view. The area of the view is darker in hue than the underlying view.
type: Number
permission: read-only
since: "6.0.0"
osver: {ios: {min: "8.0"}}

- name: AD_SIZE_PORTRAIT
summary: |
Use with [AdView.adSize](Titanium.UI.iOS.AdView.adSize) to specify a banner ad size
Expand Down
20 changes: 20 additions & 0 deletions iphone/Classes/TiUIiOSBlurView.h
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
140 changes: 140 additions & 0 deletions iphone/Classes/TiUIiOSBlurView.m
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;
}
Copy link
Contributor

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.

else {
return UIViewContentModeScaleToFill;
}
}

-(void)frameSizeChanged:(CGRect)frame bounds:(CGRect)bounds
{
for (UIView *child in [self subviews])
Copy link
Contributor

Choose a reason for hiding this comment

The 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)
Copy link
Contributor

Choose a reason for hiding this comment

The 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)
Copy link
Contributor

Choose a reason for hiding this comment

The 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
15 changes: 15 additions & 0 deletions iphone/Classes/TiUIiOSBlurViewProxy.h
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
35 changes: 35 additions & 0 deletions iphone/Classes/TiUIiOSBlurViewProxy.m
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
8 changes: 8 additions & 0 deletions iphone/Classes/TiUIiOSProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,12 @@

@property(nonatomic,readonly) NSString* AD_SIZE_PORTRAIT;
@property(nonatomic,readonly) NSString* AD_SIZE_LANDSCAPE;
#endif

#ifdef USE_TI_UIIOSBLURVIEW
@property(nonatomic,readonly) NSNumber* BLUR_EFFECT_STYLE_EXTRA_LIGHT;
@property(nonatomic,readonly) NSNumber* BLUR_EFFECT_STYLE_LIGHT;
@property(nonatomic,readonly) NSNumber* BLUR_EFFECT_STYLE_DARK;
#endif

/**
Expand Down Expand Up @@ -162,6 +167,9 @@
#ifdef USE_TI_UIIOSMENUPOPUP
-(id)createMenuPopup:(id)args;
#endif
#ifdef USE_TI_UIIOSBLURVIEW
-(id)createBlurView:(id)args;
#endif
#endif

#if IS_XCODE_7
Expand Down