diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/viewpager/ReactViewPager.java b/ReactAndroid/src/main/java/com/facebook/react/views/viewpager/ReactViewPager.java index 77e93269b..48b5f1a61 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/viewpager/ReactViewPager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/viewpager/ReactViewPager.java @@ -210,6 +210,26 @@ public class ReactViewPager extends ViewPager { mScrollEnabled = scrollEnabled; } + + @Override + protected void onAttachedToWindow() { + super.onAttachedToWindow(); + // The viewpager reset an internal flag on this method so we need to run another layout pass + // after attaching to window. + this.requestLayout(); + post(measureAndLayout); + } + + private final Runnable measureAndLayout = new Runnable() { + @Override + public void run() { + measure( + MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.EXACTLY), + MeasureSpec.makeMeasureSpec(getHeight(), MeasureSpec.EXACTLY)); + layout(getLeft(), getTop(), getRight(), getBottom()); + } + }; + /*package*/ void addViewToAdapter(View child, int index) { getAdapter().addView(child, index); }