feat:Pullable return pulling distance

This commit is contained in:
pengfei.zhou
2019-12-02 21:01:34 +08:00
parent 35fe6c41d5
commit 2e96912a99
12 changed files with 83 additions and 58 deletions

View File

@@ -21,7 +21,7 @@ public class DoricRefreshView extends FrameLayout implements PullingListener {
private View content;
private Animation.AnimationListener mListener;
private PullingListener mPullingListenr;
private PullingListener mPullingListener;
public DoricRefreshView(@NonNull Context context) {
super(context);
@@ -38,12 +38,15 @@ public class DoricRefreshView extends FrameLayout implements PullingListener {
public void setContent(View v) {
removeAllViews();
content = v;
if (v.getLayoutParams() instanceof FrameLayout.LayoutParams) {
((LayoutParams) v.getLayoutParams()).gravity = Gravity.BOTTOM;
ViewGroup.LayoutParams params = v.getLayoutParams();
if (params instanceof LayoutParams) {
((LayoutParams) params).gravity = Gravity.BOTTOM;
} else {
LayoutParams params = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.gravity = Gravity.CENTER;
v.setLayoutParams(params);
LayoutParams layoutParams = new LayoutParams(
params == null ? ViewGroup.LayoutParams.WRAP_CONTENT : params.width,
params == null ? ViewGroup.LayoutParams.WRAP_CONTENT : params.height);
layoutParams.gravity = Gravity.CENTER;
v.setLayoutParams(layoutParams);
}
addView(v);
}
@@ -53,28 +56,28 @@ public class DoricRefreshView extends FrameLayout implements PullingListener {
}
public void setPullingListenr(PullingListener listenr) {
this.mPullingListenr = listenr;
public void setPullingListener(PullingListener listener) {
this.mPullingListener = listener;
}
@Override
public void startAnimation() {
if (mPullingListenr != null) {
mPullingListenr.startAnimation();
if (mPullingListener != null) {
mPullingListener.startAnimation();
}
}
@Override
public void stopAnimation() {
if (mPullingListenr != null) {
mPullingListenr.stopAnimation();
if (mPullingListener != null) {
mPullingListener.stopAnimation();
}
}
@Override
public void setProgressRotation(float rotation) {
if (mPullingListenr != null) {
mPullingListenr.setProgressRotation(rotation);
public void setPullingDistance(float distance) {
if (mPullingListener != null) {
mPullingListener.setPullingDistance(distance);
}
}

View File

@@ -912,7 +912,7 @@ public class DoricSwipeLayout extends ViewGroup implements NestedScrollingParent
ViewCompat.offsetTopAndBottom(mRefreshView, offset);
mCurrentTargetOffsetTop = mRefreshView.getTop();
if (mRefreshView.getMeasuredHeight() > 0) {
mRefreshView.setProgressRotation((float) mRefreshView.getBottom() / (float) mRefreshView.getMeasuredHeight() * 2);
mRefreshView.setPullingDistance((float) mRefreshView.getBottom());
}
}

View File

@@ -16,5 +16,5 @@ public interface PullingListener {
*
* @param rotation Rotation is from [0..2]
*/
void setProgressRotation(float rotation);
void setPullingDistance(float rotation);
}

View File

@@ -33,7 +33,7 @@ public class RefreshableNode extends SuperNode<DoricSwipeLayout> implements Pull
@Override
protected DoricSwipeLayout build() {
DoricSwipeLayout doricSwipeLayout = new DoricSwipeLayout(getContext());
doricSwipeLayout.getRefreshView().setPullingListenr(this);
doricSwipeLayout.getRefreshView().setPullingListener(this);
return doricSwipeLayout;
}
@@ -188,9 +188,9 @@ public class RefreshableNode extends SuperNode<DoricSwipeLayout> implements Pull
}
@Override
public void setProgressRotation(float rotation) {
public void setPullingDistance(float rotation) {
if (mHeaderNode != null) {
mHeaderNode.callJSResponse("setProgressRotation", rotation);
mHeaderNode.callJSResponse("setPullingDistance", rotation);
}
}
}