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-14624] iOS - TransitionAnimation for NavigationWindow and Tab #4791

Merged
merged 6 commits into from
Oct 16, 2013
Merged
Show file tree
Hide file tree
Changes from 5 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
17 changes: 17 additions & 0 deletions iphone/Classes/TiUITabGroup.m
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,23 @@ -(void)removeEditButton:(UINavigationController*)moreController
}
}

#ifdef USE_TI_UIIOSTRANSITIONANIMATION
- (id <UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController
animationControllerForOperation:(UINavigationControllerOperation)operation
fromViewController:(UIViewController *)fromVC
toViewController:(UIViewController *)toVC
{
if([toVC isKindOfClass:[TiViewController class]]) {
TiViewController* toViewController = (TiViewController*)toVC;
if([[toViewController proxy] isKindOfClass:[TiWindowProxy class]]) {
TiWindowProxy *windowProxy = (TiWindowProxy*)[toViewController proxy];
return [windowProxy transitionAnimation];
}
}
return nil;
}
#endif

-(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
NSArray * moreViewControllerStack = [navigationController viewControllers];
Expand Down
17 changes: 17 additions & 0 deletions iphone/Classes/TiUITabProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ -(void)openOnUIThread:(NSArray*)args
return;
}
TiWindowProxy *window = [args objectAtIndex:0];

BOOL animated = ([args count] > 1) ? [TiUtils boolValue:@"animated" properties:[args objectAtIndex:1] def:YES] : YES;
[controllerStack addObject:[window hostingController]];
[[[self rootController] navigationController] pushViewController:[window hostingController] animated:animated];
Expand Down Expand Up @@ -245,6 +246,22 @@ -(void)windowClosing:(TiWindowProxy*)window animated:(BOOL)animated

#pragma mark - UINavigationControllerDelegate

#ifdef USE_TI_UIIOSTRANSITIONANIMATION
- (id <UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole method can be under the ifdef. If they never used a transition animation this is not required.

animationControllerForOperation:(UINavigationControllerOperation)operation
fromViewController:(UIViewController *)fromVC
toViewController:(UIViewController *)toVC
{
if([toVC isKindOfClass:[TiViewController class]]) {
TiViewController* toViewController = (TiViewController*)toVC;
if([[toViewController proxy] isKindOfClass:[TiWindowProxy class]]) {
TiWindowProxy *windowProxy = (TiWindowProxy*)[toViewController proxy];
return [windowProxy transitionAnimation];
}
}
return nil;
}
#endif

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
Expand Down
16 changes: 16 additions & 0 deletions iphone/Classes/TiUIiOSNavWindowProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,22 @@ -(void)windowClosing:(TiWindowProxy*)window animated:(BOOL)animated

#pragma mark - UINavigationControllerDelegate

#ifdef USE_TI_UIIOSTRANSITIONANIMATION
- (id <UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whole method under ifdef

animationControllerForOperation:(UINavigationControllerOperation)operation
fromViewController:(UIViewController *)fromVC
toViewController:(UIViewController *)toVC
{
if([toVC isKindOfClass:[TiViewController class]]) {
TiViewController* toViewController = (TiViewController*)toVC;
if([[toViewController proxy] isKindOfClass:[TiWindowProxy class]]) {
TiWindowProxy *windowProxy = (TiWindowProxy*)[toViewController proxy];
return [windowProxy transitionAnimation];
}
}
return nil;
}
#endif

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
Expand Down
3 changes: 3 additions & 0 deletions iphone/Classes/TiUIiOSProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ typedef enum {
#ifdef USE_TI_UIIOSDYNAMICITEMBEHAVIOR
-(id)createDynamicItemBehavior:(id)args;
#endif
#ifdef USE_TI_UIIOSTRANSITIONANIMATION
-(id)createTransitionAnimation:(id)args;
#endif
#endif
@end

16 changes: 14 additions & 2 deletions iphone/Classes/TiUIiOSProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#import "TiUIiOSProxy.h"
#import "TiUtils.h"
#import "Webcolor.h"

#ifdef USE_TI_UIIOS

#ifdef USE_TI_UIIOSADVIEW
Expand Down Expand Up @@ -59,6 +58,9 @@
#ifdef USE_TI_UIIOSDYNAMICITEMBEHAVIOR
#import "TiDynamicItemBehavior.h"
#endif
#ifdef USE_TI_UIIOSTRANSITIONANIMATION
#import "TiUIiOSTransitionAnimationProxy.h"
#endif

#ifdef USE_TI_UIIOSATTRIBUTEDSTRING
#import "TiUIiOSAttributedStringProxy.h"
Expand Down Expand Up @@ -202,7 +204,17 @@ -(id)createSnapBehavior:(id)args
}
}
#endif

#ifdef USE_TI_UIIOSTRANSITIONANIMATION
-(id)createTransitionAnimation:(id)args;
{
if ([TiUtils isIOS7OrGreater]) {
return [[[TiUIiOSTransitionAnimationProxy alloc] _initWithPageContext:[self executionContext] args:args] autorelease];
} else {
DebugLog(@"[WARN] The Transition Animation Object is only available on iOS7 and above. Returning nil");
return nil;
}
}
#endif
#ifdef USE_TI_UIIOSPUSHBEHAVIOR
-(id)createPushBehavior:(id)args
{
Expand Down
23 changes: 23 additions & 0 deletions iphone/Classes/TiUIiOSTransitionAnimationProxy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2013 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_UIIOSTRANSITIONANIMATION
#import "TiProxy.h"
#import "TiAnimation.h"

@interface TiUIiOSTransitionAnimationProxy : TiProxy<UIViewControllerAnimatedTransitioning, TiAnimationDelegate>
{
id<UIViewControllerContextTransitioning> _transitionContext;
TiAnimation *_transitionTo;
TiAnimation *_transitionFrom;
BOOL _endedTo;
BOOL _endedFrom;
NSNumber *_duration;
}


@end
#endif
202 changes: 202 additions & 0 deletions iphone/Classes/TiUIiOSTransitionAnimationProxy.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2013 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_UIIOSTRANSITIONANIMATION

#import "TiUIiOSTransitionAnimationProxy.h"
#import "TiViewController.h"
#import "TiViewProxy.h"


@implementation TiUIiOSTransitionAnimationProxy

- (id)init
{
self = [super init];
if (self) {
}
return self;
}

- (void)dealloc
{
if(_transitionFrom != nil) {
[self forgetProxy:_transitionFrom];
RELEASE_TO_NIL(_transitionFrom)
}
if(_transitionTo != nil) {
[self forgetProxy:_transitionTo];
RELEASE_TO_NIL(_transitionTo)
}
RELEASE_TO_NIL(_duration)
RELEASE_TO_NIL(_transitionContext)
[super dealloc];
}

-(id)duration
{
return _duration;
}

-(void)setDuration:(id)arg
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ENSURE_SINGLE_ARG missing

ENSURE_SINGLE_ARG(arg, NSNumber)
RELEASE_TO_NIL(_duration)
_duration = [arg retain];
}

-(void)setTransitionTo:(id)args
{
RELEASE_TO_NIL(_transitionTo)
_transitionTo = [TiAnimation animationFromArg:args context:[self executionContext] create:NO];
if([_transitionTo isTransitionAnimation]) {
DebugLog(@"[ERROR] Transition animations are not supported yet");
_transitionTo = nil;
return;
}
[_transitionTo setDelegate:self];
[_transitionTo retain];
[self rememberProxy:_transitionTo];
}

-(void)setTransitionFrom:(id)args
{
RELEASE_TO_NIL(_transitionFrom)
_transitionFrom = [TiAnimation animationFromArg:args context:[self executionContext] create:NO];
if([_transitionFrom isTransitionAnimation]) {
DebugLog(@"[ERROR] Transition animations are not supported yet");
_transitionFrom = nil;
return;
}
[_transitionFrom setDelegate:self];
[_transitionFrom retain];
[self rememberProxy:_transitionFrom];
}

-(TiAnimation*)transitionTo
{
return _transitionTo;
}

-(TiAnimation*)transitionFrom
{
return _transitionFrom;
}

- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{

UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];

TiViewProxy *fromProxy = nil;
TiViewProxy *toProxy = nil;
if([fromViewController isKindOfClass:[TiViewController class]]) {

fromProxy = [(TiViewController*)fromViewController proxy];
}
if([toViewController isKindOfClass:[TiViewController class]]) {

toProxy = [(TiViewController*)toViewController proxy];
}

if([self _hasListeners:@"start"])
{
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
if(toProxy != nil) {
[dict setObject:toProxy forKey:@"toWindow"];
}
if(fromProxy != nil) {
[dict setObject:fromProxy forKey:@"fromWindow"];
}
[self fireEvent:@"start" withObject:dict propagate:NO reportSuccess:NO errorCode:0 message:nil];
}

_endedFrom = (_transitionFrom == nil) || (fromProxy == nil) ;
_endedTo = (_transitionTo == nil) || (toProxy == nil);

_transitionContext = [transitionContext retain];

[fromProxy setParentVisible:YES];
[toProxy setParentVisible:YES];

UIView *container = [transitionContext containerView];
[container setUserInteractionEnabled:NO];

[container addSubview:[fromViewController view]];
[container addSubview:[toViewController view]];

if(_transitionFrom != nil && fromProxy != nil) {
[fromProxy animate: _transitionFrom];
}
if (_transitionTo != nil && toProxy != nil) {
[toProxy animate: _transitionTo];
}

if(_endedFrom && _endedTo)
{
[_transitionContext completeTransition:YES];
}
}

-(void)animationDidComplete:(TiAnimation *)animation;
{
if(animation == _transitionFrom) {
_endedFrom = YES;
}
if(animation == _transitionTo) {
_endedTo = YES;
}
if(_endedTo && _endedFrom) {
[_transitionContext completeTransition:YES];
}
}

- (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext
{
if(_transitionTo == nil && _transitionFrom == nil) {
return 0;
}
if(_duration == nil) {
return MAX(
[TiUtils floatValue:[_transitionTo duration] def:0],
[TiUtils floatValue:[_transitionFrom duration] def:0]
) / 1000;
}
return [TiUtils floatValue:_duration def:0] / 1000;
}

- (void)animationEnded:(BOOL) transitionCompleted;
{
if([self _hasListeners:@"end"]) {

UIViewController *fromViewController = [_transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIViewController *toViewController = [_transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];

TiViewProxy *fromProxy = nil;
TiViewProxy *toProxy = nil;

if([fromViewController isKindOfClass:[TiViewController class]]) {
fromProxy = [(TiViewController*)fromViewController proxy];
}
if([toViewController isKindOfClass:[TiViewController class]]) {
toProxy = [(TiViewController*)toViewController proxy];
}

NSMutableDictionary *dict = [NSMutableDictionary dictionary];
if(toProxy != nil) {
[dict setObject:toProxy forKey:@"toWindow"];
}
if(fromProxy != nil) {
[dict setObject:fromProxy forKey:@"fromWindow"];
}
[self fireEvent:@"end" withObject:dict propagate:NO reportSuccess:NO errorCode:0 message:nil];
}
RELEASE_TO_NIL(_transitionContext)
}

@end
#endif
12 changes: 12 additions & 0 deletions iphone/Classes/TiWindowProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#import "TiTab.h"
#import "TiViewController.h"

#ifdef USE_TI_UIIOSTRANSITIONANIMATION
#import "TiUIiOSTransitionAnimationProxy.h"
#endif

@interface TiWindowProxy : TiViewProxy<TiWindowProtocol, TiAnimationDelegate> {
@protected
TiViewController* controller;
Expand All @@ -24,8 +28,16 @@
TiAnimation * openAnimation;
TiAnimation * closeAnimation;
UIView* animatedOver;
#ifdef USE_TI_UIIOSTRANSITIONANIMATION
TiUIiOSTransitionAnimationProxy* transitionProxy;
#endif

}

@property (nonatomic, readwrite, assign) TiViewProxy<TiTab> *tab;
@property (nonatomic, readonly) TiProxy* tabGroup;

#ifdef USE_TI_UIIOSTRANSITIONANIMATION
-(TiUIiOSTransitionAnimationProxy*) transitionAnimation;
#endif
@end