美文网首页React Native
react-native加载原生Fragment不刷新的问题

react-native加载原生Fragment不刷新的问题

作者: xiaotimel | 来源:发表于2019-12-10 18:25 被阅读0次
public class RNRefreshLayout extends RelativeLayout {

    public RNRefreshLayout (Context context) {

        super(context);

    }

    public RNRefreshLayout (Context context, AttributeSet attrs) {

        super(context, attrs);

    }

    public RNRefreshLayout (Context context, AttributeSet attrs, int defStyleAttr) {

        super(context, attrs, defStyleAttr);

    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)

    public RNRefreshLayout (Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {

        super(context, attrs, defStyleAttr, defStyleRes);

    }

    @Override

    public void requestLayout() {

        super.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());

        }

    };

}

react-native 为了提升性能,将 requestLayout拦截统一由UIManagerModule实现,所以要重写 requestLayout去进行重绘

原文链接

相关文章

网友评论

    本文标题:react-native加载原生Fragment不刷新的问题

    本文链接:https://www.haomeiwen.com/subject/hogggctx.html