package androidx.core.view;

import android.view.View;

import androidx.viewpager.widget.ViewPager;

import java.lang.reflect.Field;

public class ViewPagerUtils {

    public static View getCurrentView(ViewPager viewPager) {
        final int currentItem = viewPager.getCurrentItem();
        for (int i = 0; i < viewPager.getChildCount(); i++) {
            final View child = viewPager.getChildAt(i);
            final ViewPager.LayoutParams layoutParams = (ViewPager.LayoutParams) child.getLayoutParams();
            try {
                Field f = layoutParams.getClass().getDeclaredField("position");
                f.setAccessible(true);
                int position = (Integer) f.get(layoutParams);
                if (!layoutParams.isDecor && currentItem == position) {
                    return child;
                }
            } catch (NoSuchFieldException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }

        }
        return null;
    }

}
