feat:fix shaking when drag
This commit is contained in:
		@@ -34,6 +34,7 @@ import java.util.List;
 | 
			
		||||
 | 
			
		||||
import pub.doric.DoricActivity;
 | 
			
		||||
import pub.doric.devkit.ui.DemoDebugActivity;
 | 
			
		||||
import pub.doric.pullable.DoricSwipeLayout;
 | 
			
		||||
import pub.doric.utils.DoricUtils;
 | 
			
		||||
 | 
			
		||||
public class MainActivity extends AppCompatActivity {
 | 
			
		||||
@@ -43,6 +44,13 @@ public class MainActivity extends AppCompatActivity {
 | 
			
		||||
        super.onCreate(savedInstanceState);
 | 
			
		||||
 | 
			
		||||
        setContentView(R.layout.activity_main);
 | 
			
		||||
        final DoricSwipeLayout swipeLayout = findViewById(R.id.swipe_layout);
 | 
			
		||||
        swipeLayout.setOnRefreshListener(new DoricSwipeLayout.OnRefreshListener() {
 | 
			
		||||
            @Override
 | 
			
		||||
            public void onRefresh() {
 | 
			
		||||
                swipeLayout.setRefreshing(false);
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
        RecyclerView recyclerView = findViewById(R.id.root);
 | 
			
		||||
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
 | 
			
		||||
        try {
 | 
			
		||||
 
 | 
			
		||||
@@ -1,8 +1,13 @@
 | 
			
		||||
<?xml version="1.0" encoding="utf-8"?>
 | 
			
		||||
 | 
			
		||||
<androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
 | 
			
		||||
<pub.doric.pullable.DoricSwipeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 | 
			
		||||
    xmlns:tools="http://schemas.android.com/tools"
 | 
			
		||||
    android:id="@+id/root"
 | 
			
		||||
    android:id="@+id/swipe_layout"
 | 
			
		||||
    android:layout_width="match_parent"
 | 
			
		||||
    android:layout_height="match_parent"
 | 
			
		||||
    tools:context=".MainActivity" />
 | 
			
		||||
    android:layout_height="match_parent">
 | 
			
		||||
 | 
			
		||||
    <androidx.recyclerview.widget.RecyclerView
 | 
			
		||||
        android:id="@+id/root"
 | 
			
		||||
        android:layout_width="match_parent"
 | 
			
		||||
        android:layout_height="match_parent"
 | 
			
		||||
        tools:context=".MainActivity" />
 | 
			
		||||
</pub.doric.pullable.DoricSwipeLayout>
 | 
			
		||||
@@ -26,8 +26,8 @@ import android.graphics.drawable.ShapeDrawable;
 | 
			
		||||
import android.graphics.drawable.shapes.OvalShape;
 | 
			
		||||
import android.view.View;
 | 
			
		||||
import android.view.animation.Animation;
 | 
			
		||||
import android.widget.ImageView;
 | 
			
		||||
 | 
			
		||||
import androidx.appcompat.widget.AppCompatImageView;
 | 
			
		||||
import androidx.core.content.ContextCompat;
 | 
			
		||||
import androidx.core.view.ViewCompat;
 | 
			
		||||
 | 
			
		||||
@@ -36,7 +36,7 @@ import androidx.core.view.ViewCompat;
 | 
			
		||||
 * called before the animation is actually complete and support shadows on older
 | 
			
		||||
 * platforms.
 | 
			
		||||
 */
 | 
			
		||||
class CircleImageView extends ImageView {
 | 
			
		||||
class CircleImageView extends AppCompatImageView {
 | 
			
		||||
 | 
			
		||||
    private static final int KEY_SHADOW_COLOR = 0x1E000000;
 | 
			
		||||
    private static final int FILL_SHADOW_COLOR = 0x3D000000;
 | 
			
		||||
 
 | 
			
		||||
@@ -51,7 +51,7 @@ public class DoricSwipeLayout extends ViewGroup implements NestedScrollingParent
 | 
			
		||||
    @VisibleForTesting
 | 
			
		||||
    static final int CIRCLE_DIAMETER_LARGE = 56;
 | 
			
		||||
 | 
			
		||||
    private static final String LOG_TAG = androidx.swiperefreshlayout.widget.SwipeRefreshLayout.class.getSimpleName();
 | 
			
		||||
    private static final String LOG_TAG = DoricSwipeLayout.class.getSimpleName();
 | 
			
		||||
 | 
			
		||||
    private static final int MAX_ALPHA = 255;
 | 
			
		||||
    private static final int STARTING_PROGRESS_ALPHA = (int) (.3f * MAX_ALPHA);
 | 
			
		||||
@@ -587,16 +587,19 @@ public class DoricSwipeLayout extends ViewGroup implements NestedScrollingParent
 | 
			
		||||
        if (mTarget == null) {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        int circleWidth = mCircleView.getMeasuredWidth();
 | 
			
		||||
        int circleHeight = mCircleView.getMeasuredHeight();
 | 
			
		||||
 | 
			
		||||
        mCircleView.layout((width / 2 - circleWidth / 2), mCurrentTargetOffsetTop,
 | 
			
		||||
                (width / 2 + circleWidth / 2), mCurrentTargetOffsetTop + circleHeight);
 | 
			
		||||
 | 
			
		||||
        final View child = mTarget;
 | 
			
		||||
        final int childLeft = getPaddingLeft();
 | 
			
		||||
        final int childTop = getPaddingTop();
 | 
			
		||||
        final int childTop = getPaddingTop() + mCircleView.getBottom();
 | 
			
		||||
        final int childWidth = width - getPaddingLeft() - getPaddingRight();
 | 
			
		||||
        final int childHeight = height - getPaddingTop() - getPaddingBottom();
 | 
			
		||||
        child.layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight);
 | 
			
		||||
        int circleWidth = mCircleView.getMeasuredWidth();
 | 
			
		||||
        int circleHeight = mCircleView.getMeasuredHeight();
 | 
			
		||||
        mCircleView.layout((width / 2 - circleWidth / 2), mCurrentTargetOffsetTop,
 | 
			
		||||
                (width / 2 + circleWidth / 2), mCurrentTargetOffsetTop + circleHeight);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
@@ -756,8 +759,10 @@ public class DoricSwipeLayout extends ViewGroup implements NestedScrollingParent
 | 
			
		||||
                consumed[1] = dy - (int) mTotalUnconsumed;
 | 
			
		||||
                mTotalUnconsumed = 0;
 | 
			
		||||
            } else {
 | 
			
		||||
                mTotalUnconsumed -= dy;
 | 
			
		||||
                consumed[1] = dy;
 | 
			
		||||
                if (dy > 3) {
 | 
			
		||||
                    mTotalUnconsumed -= dy;
 | 
			
		||||
                    consumed[1] = dy;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            moveSpinner(mTotalUnconsumed);
 | 
			
		||||
        }
 | 
			
		||||
@@ -1179,4 +1184,6 @@ public class DoricSwipeLayout extends ViewGroup implements NestedScrollingParent
 | 
			
		||||
         */
 | 
			
		||||
        boolean canChildScrollUp(@NonNull DoricSwipeLayout parent, @Nullable View child);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user