Skip to content

Commit

Permalink
Merge pull request #4272 from vishalduggal/timob-13237-31X
Browse files Browse the repository at this point in the history
[TIMOB-13237] (3_1_X) Wait for layout to finish before animting
  • Loading branch information
srahim committed May 15, 2013
2 parents e139fb0 + fc96ee8 commit 224a65d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
3 changes: 2 additions & 1 deletion iphone/Classes/TiLayoutQueue.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#import <pthread.h>

#define LAYOUT_TIMER_INTERVAL 0.05
#define LAYOUT_START_INTERVAL 0.01


NSMutableArray * layoutArray = nil;
Expand Down Expand Up @@ -91,7 +92,7 @@ +(void)addViewProxy:(TiViewProxy*)newViewProxy
if (layoutTimer == NULL)
{
layoutTimer = CFRunLoopTimerCreate(NULL,
CFAbsoluteTimeGetCurrent()+LAYOUT_TIMER_INTERVAL,
CFAbsoluteTimeGetCurrent()+LAYOUT_START_INTERVAL,
LAYOUT_TIMER_INTERVAL,
0, 0, performLayoutRefresh, NULL);
CFRunLoopAddTimer(CFRunLoopGetMain(), layoutTimer, kCFRunLoopCommonModes);
Expand Down
1 change: 1 addition & 0 deletions iphone/Classes/TiUIView.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ void ModifyScrollViewForKeyboardHeightAndContentHeightWithResponderRect(UIScroll
BOOL touchEnabled;

unsigned int animationDelayGuard;
unsigned int animationDelayGuardForLayout;

// Touch detection
BOOL changedInteraction;
Expand Down
13 changes: 13 additions & 0 deletions iphone/Classes/TiUIView.m
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,19 @@ -(void)animate:(TiAnimation *)newAnimation
}

animationDelayGuard = 0;
//TIMOB-13237. Wait for layout to finish before animating.
//TODO. This is a hack. When we implement the polynomial layout for iOS we will be able to do
//a full layout of this view and associated views in the animation block.
if ([self.proxy isKindOfClass:[TiViewProxy class]] && [(TiViewProxy*)self.proxy willBeRelaying]) {
DebugLog(@"[DEBUG] Ti.View.animate() called while view waiting to relayout: Will re-attempt", self);
if (animationDelayGuardForLayout++ > 2) {
DebugLog(@"[DEBUG] Animation guard triggered, exceeded timeout for layout to occur. Continuing.");
} else {
[self performSelector:@selector(animate:) withObject:newAnimation afterDelay:0.02];
return;
}
}
animationDelayGuardForLayout = 0;

if (newAnimation != nil)
{
Expand Down
6 changes: 4 additions & 2 deletions iphone/Classes/TiViewProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -565,8 +565,10 @@ enum
-(void)relayout;

-(void)reposition; //Todo: Replace

-(BOOL)willBeRelaying; //Todo: Replace
/**
Tells if the view is enqueued in the LayoutQueue
*/
-(BOOL)willBeRelaying;

-(BOOL) widthIsAutoFill;
-(BOOL) widthIsAutoSize;
Expand Down
4 changes: 2 additions & 2 deletions iphone/Classes/TiViewProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,6 @@ -(void)animate:(id)arg
TiAnimation * newAnimation = [TiAnimation animationFromArg:arg context:[self executionContext] create:NO];
[self rememberProxy:newAnimation];
TiThreadPerformOnMainThread(^{
[parent contentsWillChange];
if ([view superview]==nil)
{
VerboseLog(@"Entering animation without a superview Parent is %@, props are %@",parent,dynprops);
Expand Down Expand Up @@ -2286,7 +2285,8 @@ -(void)layoutChildrenIfNeeded

-(BOOL)willBeRelaying
{
return dirtyflags != 0;
DebugLog(@"DIRTY FLAGS %d WILLBERELAYING %d",dirtyflags, (*((char*)&dirtyflags) & (1 << (7 - TiRefreshViewEnqueued))));
return ((*((char*)&dirtyflags) & (1 << (7 - TiRefreshViewEnqueued))) != 0);
}

-(void)childWillResize:(TiViewProxy *)child
Expand Down

0 comments on commit 224a65d

Please sign in to comment.