feat:add RefreshableDemo

This commit is contained in:
pengfei.zhou
2019-11-26 11:34:02 +08:00
parent c90547a1f0
commit 9a9482eeb5
8 changed files with 80 additions and 46 deletions

View File

@@ -2,6 +2,7 @@ package pub.doric.pullable;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
@@ -17,10 +18,12 @@ import androidx.annotation.Nullable;
* @Author: pengfei.zhou
* @CreateDate: 2019-11-25
*/
public class DoricRefreshView extends FrameLayout implements IPullable {
public class DoricRefreshView extends FrameLayout implements PullingListener {
private View content;
private Animation.AnimationListener mListener;
private PullingListener mPullingListenr;
public DoricRefreshView(@NonNull Context context) {
super(context);
}
@@ -50,33 +53,29 @@ public class DoricRefreshView extends FrameLayout implements IPullable {
return content;
}
public void setPullingListenr(PullingListener listenr) {
this.mPullingListenr = listenr;
}
@Override
public void startAnimation() {
if (content != null && content instanceof IPullable) {
((IPullable) content).startAnimation();
if (mPullingListenr != null) {
mPullingListenr.startAnimation();
}
}
@Override
public void stopAnimation() {
if (content != null && content instanceof IPullable) {
((IPullable) content).stopAnimation();
}
}
@Override
public int successAnimation() {
if (content != null && content instanceof IPullable) {
return ((IPullable) content).successAnimation();
} else {
return 0;
if (mPullingListenr != null) {
mPullingListenr.stopAnimation();
}
}
@Override
public void setProgressRotation(float rotation) {
if (content != null && content instanceof IPullable) {
((IPullable) content).setProgressRotation(rotation);
if (mPullingListenr != null) {
mPullingListenr.setProgressRotation(rotation);
}
}

View File

@@ -1,27 +0,0 @@
package pub.doric.pullable;
/**
* @Description: pub.doric.pullable
* @Author: pengfei.zhou
* @CreateDate: 2019-11-25
*/
public interface IPullable {
void startAnimation();
void stopAnimation();
/**
* run the animation after pull request success and before stop animation
*
* @return the duration of success animation or 0 if no success animation
*/
int successAnimation();
/**
* Set the amount of rotation to apply to the progress spinner.
*
* @param rotation Rotation is from [0..1]
*/
void setProgressRotation(float rotation);
}

View File

@@ -5,7 +5,7 @@ package pub.doric.pullable;
* @Author: pengfei.zhou
* @CreateDate: 2019-11-25
*/
public interface IPullable {
public interface PullingListener {
void startAnimation();

View File

@@ -1,5 +1,7 @@
package pub.doric.pullable;
import android.view.animation.Animation;
import com.github.pengfeizhou.jscore.JSObject;
import com.github.pengfeizhou.jscore.JSValue;
import com.github.pengfeizhou.jscore.JavaValue;
@@ -17,7 +19,7 @@ import pub.doric.shader.ViewNode;
* @CreateDate: 2019-11-26
*/
@DoricPlugin(name = "Refreshable")
public class RefreshableNode extends SuperNode<DoricSwipeLayout> {
public class RefreshableNode extends SuperNode<DoricSwipeLayout> implements PullingListener {
private String mContentViewId;
private ViewNode mContentNode;
@@ -32,7 +34,9 @@ public class RefreshableNode extends SuperNode<DoricSwipeLayout> {
@Override
protected DoricSwipeLayout build() {
return new DoricSwipeLayout(getContext());
DoricSwipeLayout doricSwipeLayout = new DoricSwipeLayout(getContext());
doricSwipeLayout.getRefreshView().setPullingListenr(this);
return doricSwipeLayout;
}
@Override
@@ -162,4 +166,25 @@ public class RefreshableNode extends SuperNode<DoricSwipeLayout> {
public void isRefreshing(DoricPromise doricPromise) {
doricPromise.resolve(new JavaValue(this.mView.isRefreshing()));
}
@Override
public void startAnimation() {
if (mHeaderNode != null) {
mHeaderNode.callJSResponse("startAnimation");
}
}
@Override
public void stopAnimation() {
if (mHeaderNode != null) {
mHeaderNode.callJSResponse("stopAnimation");
}
}
@Override
public void setProgressRotation(float rotation) {
if (mHeaderNode != null) {
mHeaderNode.callJSResponse("setProgressRotation", rotation);
}
}
}

View File

@@ -257,4 +257,16 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
public int getHeight() {
return mView.getHeight();
}
@DoricMethod
public void setRotation(JSValue jsValue) {
float rotation = jsValue.asNumber().toFloat();
while (rotation > 1) {
rotation = rotation - 1;
}
while (rotation < -1) {
rotation = rotation + 1;
}
doricLayer.setRotation(rotation * 360);
}
}