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去进行重绘
网友评论