package com.anythink.reactnative.banner;

import android.content.Context;
import android.view.View;
import android.widget.FrameLayout;

/**
* Banner container (shared, common to old and new architectures): RN will not do measure/layout for "sub-views of addView on the native side",
* Therefore, when requestLayout is used, measure + layout is forced on itself and the child view (banner loading content will trigger requestLayout).
 */
public class ATBannerContainer extends FrameLayout {
    public ATBannerContainer(Context context) {
        super(context);
    }

    private final Runnable mMeasureAndLayout = new Runnable() {
        @Override
        public void run() {
            measure(
                    View.MeasureSpec.makeMeasureSpec(getWidth(), View.MeasureSpec.EXACTLY),
                    View.MeasureSpec.makeMeasureSpec(getHeight(), View.MeasureSpec.EXACTLY));
            layout(getLeft(), getTop(), getRight(), getBottom());
        }
    };

    @Override
    public void requestLayout() {
        super.requestLayout();
        post(mMeasureAndLayout);
    }
}
