Skip to content

Commit

Permalink
Merge pull request #5946 from salachi/TIMOB-17260
Browse files Browse the repository at this point in the history
TIMOB-17260-If there is layout pending, queue up new request to animate
  • Loading branch information
hieupham007 committed Sep 4, 2014
2 parents 43b556d + f90afcd commit 76d2ff3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public abstract class TiViewProxy extends KrollProxy implements Handler.Callback

// TODO: Deprecated since Release 3.0.0
@Deprecated private AtomicBoolean layoutStarted = new AtomicBoolean();

/**
* Constructs a new TiViewProxy instance.
* @module.api
Expand Down Expand Up @@ -828,8 +828,10 @@ protected void handleAnimate()
// immediately upon window opening and the first
// layout hasn't happened yet. In this case,
// queue up a new request to animate.
// Also do the same if layout properties
// are changed and layout hasn't completed.
View view = tiv.getNativeView();
if (view == null || (view.getWidth() == 0 && view.getHeight() == 0)) {
if (view == null || (view.getWidth() == 0 && view.getHeight() == 0) || tiv.isLayoutPending()) {
getMainHandler().sendEmptyMessage(MSG_QUEUED_ANIMATE);
return;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;

import org.appcelerator.kroll.KrollDict;
Expand Down Expand Up @@ -131,6 +132,8 @@ public abstract class TiUIView
private int visibility = View.VISIBLE;

protected GestureDetector detector = null;

private AtomicBoolean bLayoutPending = new AtomicBoolean();


/**
Expand Down Expand Up @@ -550,6 +553,12 @@ protected void layoutNativeView()
}
}


public boolean isLayoutPending()
{
return bLayoutPending.get();
}

protected void layoutNativeView(boolean informParent)
{
if (nativeView != null) {
Expand All @@ -566,6 +575,30 @@ protected void layoutNativeView(boolean informParent)
}
}
}
final View v = getOuterView();
if (v != null) {
bLayoutPending.set(true);
OnGlobalLayoutListener layoutListener = new OnGlobalLayoutListener()
{
public void onGlobalLayout()
{
bLayoutPending.set(false);
try {
if (Build.VERSION.SDK_INT < TiC.API_LEVEL_JELLY_BEAN) {
v.getViewTreeObserver().removeGlobalOnLayoutListener(this);
} else {
v.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
} catch (IllegalStateException e) {
if (Log.isDebugModeEnabled()) {
Log.w(TAG, "Unable to remove the OnGlobalLayoutListener.", e.getMessage());
}
}
}
};
v.getViewTreeObserver().addOnGlobalLayoutListener(layoutListener);
}

nativeView.requestLayout();
}
}
Expand Down

0 comments on commit 76d2ff3

Please sign in to comment.