mirror of
https://github.com/Tencent/QMUI_Android.git
synced 2026-10-16 20:21:25 +08:00
bugfix: requestLayout invoked frequently.
This commit is contained in:
@@ -29,6 +29,7 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.view.WindowInsetsCompat;
|
||||
|
||||
import com.qmuiteam.qmui.QMUILog;
|
||||
import com.qmuiteam.qmui.arch.scheme.ActivitySchemeRefreshable;
|
||||
import com.qmuiteam.qmui.util.QMUIDisplayHelper;
|
||||
import com.qmuiteam.qmui.util.QMUIStatusBarHelper;
|
||||
@@ -127,6 +128,11 @@ public class QMUIActivity extends InnerBaseActivity implements ActivitySchemeRef
|
||||
|
||||
return QMUIActivity.this.getDragDirection(swipeBackLayout,moveAction,downX, downY, dx, dy, touchSlop);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reportFrequentlyRequestLayout(int count, long duration) {
|
||||
QMUIActivity.this.reportFrequentlyRequestLayout(count, duration);
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
@@ -200,6 +206,10 @@ public class QMUIActivity extends InnerBaseActivity implements ActivitySchemeRef
|
||||
super.onBackPressed();
|
||||
}
|
||||
|
||||
protected void reportFrequentlyRequestLayout(int count, long duration){
|
||||
QMUILog.w(TAG, "requestLayout is too frequent(requestLayout " + count + "times within " + duration + "ms");
|
||||
}
|
||||
|
||||
public boolean isInSwipeBack() {
|
||||
return mIsInSwipeBack;
|
||||
}
|
||||
|
||||
@@ -597,6 +597,11 @@ public abstract class QMUIFragment extends Fragment implements
|
||||
return QMUIFragment.this.getDragDirection(
|
||||
swipeBackLayout, viewMoveAction, downX, downY, dx, dy, touchSlop);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reportFrequentlyRequestLayout(int count, long duration) {
|
||||
QMUIFragment.this.reportFrequentlyRequestLayout(count, duration);
|
||||
}
|
||||
});
|
||||
initSwipeBackLayout(swipeBackLayout);
|
||||
if(getParentFragment() != null){
|
||||
@@ -1011,6 +1016,10 @@ public abstract class QMUIFragment extends Fragment implements
|
||||
onNormalBackPressed();
|
||||
}
|
||||
|
||||
protected void reportFrequentlyRequestLayout(int count, long duration){
|
||||
QMUILog.w(TAG, "requestLayout is too frequent(requestLayout " + count + "times within " + duration + "ms");
|
||||
}
|
||||
|
||||
protected void onHandleSpecLastFragmentFinish(FragmentActivity fragmentActivity,
|
||||
QMUIFragment.TransitionConfig transitionConfig,
|
||||
Object toExec) {
|
||||
|
||||
@@ -20,6 +20,7 @@ import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.SystemClock;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
@@ -115,6 +116,9 @@ public class SwipeBackLayout extends FrameLayout {
|
||||
private boolean mIsScrollOverValid = true;
|
||||
private boolean mEnableSwipeBack = true;
|
||||
|
||||
private int mRequestLayoutCount = 0;
|
||||
private long mRequestLayoutCheckStartTime = -1;
|
||||
|
||||
|
||||
public SwipeBackLayout(Context context) {
|
||||
this(context, null);
|
||||
@@ -338,6 +342,32 @@ public class SwipeBackLayout extends FrameLayout {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void requestLayout() {
|
||||
super.requestLayout();
|
||||
mRequestLayoutCount++;
|
||||
if(mRequestLayoutCheckStartTime == -1){
|
||||
mRequestLayoutCheckStartTime = SystemClock.elapsedRealtime();
|
||||
}
|
||||
if(mRequestLayoutCount >= 100){
|
||||
long duration = SystemClock.elapsedRealtime() - mRequestLayoutCheckStartTime;
|
||||
if(duration < 4000){
|
||||
if(mCallback != null){
|
||||
mCallback.reportFrequentlyRequestLayout(mRequestLayoutCount, duration);
|
||||
}
|
||||
}
|
||||
mRequestLayoutCount = 0;
|
||||
mRequestLayoutCheckStartTime = -1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow();
|
||||
mRequestLayoutCount=0;
|
||||
mRequestLayoutCheckStartTime = -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
||||
if(!mEnableSwipeBack){
|
||||
@@ -861,6 +891,8 @@ public class SwipeBackLayout extends FrameLayout {
|
||||
public interface Callback {
|
||||
int getDragDirection(SwipeBackLayout swipeBackLayout, ViewMoveAction moveAction,
|
||||
float downX, float downY, float dx, float dy, float touchSlop);
|
||||
|
||||
void reportFrequentlyRequestLayout(int count, long duration);
|
||||
}
|
||||
|
||||
public interface ViewMoveAction {
|
||||
|
||||
+8
-4
@@ -85,11 +85,15 @@ public class QMUIContinuousNestedBottomRecyclerView extends RecyclerView
|
||||
@Override
|
||||
public void consumeScroll(int yUnconsumed) {
|
||||
if (yUnconsumed == Integer.MIN_VALUE) {
|
||||
scrollToPosition(0);
|
||||
if(canScrollVertically(-1)){
|
||||
scrollToPosition(0);
|
||||
}
|
||||
} else if (yUnconsumed == Integer.MAX_VALUE) {
|
||||
Adapter adapter = getAdapter();
|
||||
if (adapter != null) {
|
||||
scrollToPosition(adapter.getItemCount() - 1);
|
||||
if(canScrollVertically(1)) {
|
||||
Adapter adapter = getAdapter();
|
||||
if (adapter != null) {
|
||||
scrollToPosition(adapter.getItemCount() - 1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
boolean reStartNestedScroll = false;
|
||||
|
||||
+8
-4
@@ -56,12 +56,16 @@ public class QMUIContinuousNestedTopRecyclerView extends RecyclerView implements
|
||||
@Override
|
||||
public int consumeScroll(int dyUnconsumed) {
|
||||
if (dyUnconsumed == Integer.MIN_VALUE) {
|
||||
scrollToPosition(0);
|
||||
if(canScrollVertically(-1)){
|
||||
scrollToPosition(0);
|
||||
}
|
||||
return Integer.MIN_VALUE;
|
||||
} else if (dyUnconsumed == Integer.MAX_VALUE) {
|
||||
Adapter adapter = getAdapter();
|
||||
if (adapter != null) {
|
||||
scrollToPosition(adapter.getItemCount() - 1);
|
||||
if(canScrollVertically(1)){
|
||||
Adapter adapter = getAdapter();
|
||||
if (adapter != null) {
|
||||
scrollToPosition(adapter.getItemCount() - 1);
|
||||
}
|
||||
}
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user