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-25684] iOS: Adds home-screen like parallax effect to views #9748

Merged
merged 14 commits into from
May 15, 2018
Merged
Show file tree
Hide file tree
Changes from 8 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
26 changes: 26 additions & 0 deletions apidoc/Titanium/UI/View.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1322,6 +1322,19 @@ properties:
platforms: [android]
since: 6.1.0

- name: horizontalMotionEffect
summary: Adds a horizontal parallax effect to the view
description: |
Pass an object with the following key-value pairs:

* `min` (Number): Minimum amount it can move horizontally (-10 for example)
* `max` (Number): Maximum amount it can move horizontally (10 for example)

Note that the parallax effect only happens by tilting the device so results can not be seen on Simulator
type: Dictionary
platforms: [iphone, ipad]
since: 7.1.0

- name: left
summary: View's left position, in platform-specific units.
description: |
Expand Down Expand Up @@ -1661,6 +1674,19 @@ properties:
since: "5.0.2"
osver: {android: {min: 5.0}}

- name: verticalMotionEffect
summary: Adds a vertical parallax effect to the view
description: |
Pass an object with the following key-value pairs:

* `min` (Number): Minimum amount it can move vertically (-10 for example)
* `max` (Number): Maximum amount it can move vertically (10 for example)

Note that the parallax effect only happens by tilting the device so results can not be seen on Simulator
type: Dictionary
platforms: [iphone, ipad]
since: 7.1.0

- name: viewShadowRadius
summary: Determines the blur radius used to create the shadow.
type: Number
Expand Down
24 changes: 24 additions & 0 deletions iphone/Classes/TiUIView.m
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,30 @@ - (void)setViewShadowColor_:(id)arg
[self updateClipping];
}

- (void)setHorizontalMotionEffect_:(id)motionEffect
{
CGFloat min = [TiUtils floatValue:[motionEffect objectForKey:@"min"]];
CGFloat max = [TiUtils floatValue:[motionEffect objectForKey:@"max"]];
UIInterpolatingMotionEffect *effect = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.x"
type:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis];
effect.minimumRelativeValue = @(min);
effect.maximumRelativeValue = @(max);

[self addMotionEffect:effect];
}

- (void)setVerticalMotionEffect_:(id)motionEffect
{
CGFloat min = [TiUtils floatValue:[motionEffect objectForKey:@"min"]];
CGFloat max = [TiUtils floatValue:[motionEffect objectForKey:@"max"]];
UIInterpolatingMotionEffect *effect = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.y"
type:UIInterpolatingMotionEffectTypeTiltAlongVerticalAxis];
effect.minimumRelativeValue = @(min);
effect.maximumRelativeValue = @(max);

[self addMotionEffect:effect];
}

- (void)updateViewShadowPath
{
if ([self shadowLayer].shadowOpacity > 0.0f) {
Expand Down
48 changes: 48 additions & 0 deletions tests/Resources/ti.ui.view.addontest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Appcelerator Titanium Mobile
* Copyright (c) 2015-Present 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.
*/
/* eslint-env mocha */
/* global Ti */
/* eslint no-unused-expressions: "off" */
'use strict';
var should = require('./utilities/assertions');

describe('Titanium.UI.View', function() {

it.ios('.horizontalMotionEffect, .verticalMotionEffect', function(finish) {
var win = Ti.UI.createWindow({
backgroundColor: 'blue'
});

var view = Ti.UI.createView({
horizontalMotionEffect: {
min: -50,
max: 50
},
verticalMotionEffect: {
min: -50,
max: 50
}
});

win.addEventListener('open', function() {
// horizontalMotionEffect
should(view.horizontalMotionEffect).be.an.Object;
should(view.horizontalMotionEffect.min).be.a.Number;
should(view.horizontalMotionEffect.max).be.a.Number;

// verticalMotionEffect
should(view.verticalMotionEffect).be.an.Object;
should(view.verticalMotionEffect.min).be.a.Number;
should(view.verticalMotionEffect.max).be.a.Number;

finish();
});

win.add(view);
win.open();
});
});