feat:add RefreshableDemo
This commit is contained in:
parent
c90547a1f0
commit
9a9482eeb5
@ -2,6 +2,7 @@ package pub.doric.pullable;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@ -17,10 +18,12 @@ import androidx.annotation.Nullable;
|
|||||||
* @Author: pengfei.zhou
|
* @Author: pengfei.zhou
|
||||||
* @CreateDate: 2019-11-25
|
* @CreateDate: 2019-11-25
|
||||||
*/
|
*/
|
||||||
public class DoricRefreshView extends FrameLayout implements IPullable {
|
public class DoricRefreshView extends FrameLayout implements PullingListener {
|
||||||
private View content;
|
private View content;
|
||||||
private Animation.AnimationListener mListener;
|
private Animation.AnimationListener mListener;
|
||||||
|
|
||||||
|
private PullingListener mPullingListenr;
|
||||||
|
|
||||||
public DoricRefreshView(@NonNull Context context) {
|
public DoricRefreshView(@NonNull Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
}
|
}
|
||||||
@ -50,33 +53,29 @@ public class DoricRefreshView extends FrameLayout implements IPullable {
|
|||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setPullingListenr(PullingListener listenr) {
|
||||||
|
this.mPullingListenr = listenr;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startAnimation() {
|
public void startAnimation() {
|
||||||
if (content != null && content instanceof IPullable) {
|
if (mPullingListenr != null) {
|
||||||
((IPullable) content).startAnimation();
|
mPullingListenr.startAnimation();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stopAnimation() {
|
public void stopAnimation() {
|
||||||
if (content != null && content instanceof IPullable) {
|
if (mPullingListenr != null) {
|
||||||
((IPullable) content).stopAnimation();
|
mPullingListenr.stopAnimation();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int successAnimation() {
|
|
||||||
if (content != null && content instanceof IPullable) {
|
|
||||||
return ((IPullable) content).successAnimation();
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setProgressRotation(float rotation) {
|
public void setProgressRotation(float rotation) {
|
||||||
if (content != null && content instanceof IPullable) {
|
if (mPullingListenr != null) {
|
||||||
((IPullable) content).setProgressRotation(rotation);
|
mPullingListenr.setProgressRotation(rotation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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);
|
|
||||||
}
|
|
@ -5,7 +5,7 @@ package pub.doric.pullable;
|
|||||||
* @Author: pengfei.zhou
|
* @Author: pengfei.zhou
|
||||||
* @CreateDate: 2019-11-25
|
* @CreateDate: 2019-11-25
|
||||||
*/
|
*/
|
||||||
public interface IPullable {
|
public interface PullingListener {
|
||||||
|
|
||||||
void startAnimation();
|
void startAnimation();
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package pub.doric.pullable;
|
package pub.doric.pullable;
|
||||||
|
|
||||||
|
import android.view.animation.Animation;
|
||||||
|
|
||||||
import com.github.pengfeizhou.jscore.JSObject;
|
import com.github.pengfeizhou.jscore.JSObject;
|
||||||
import com.github.pengfeizhou.jscore.JSValue;
|
import com.github.pengfeizhou.jscore.JSValue;
|
||||||
import com.github.pengfeizhou.jscore.JavaValue;
|
import com.github.pengfeizhou.jscore.JavaValue;
|
||||||
@ -17,7 +19,7 @@ import pub.doric.shader.ViewNode;
|
|||||||
* @CreateDate: 2019-11-26
|
* @CreateDate: 2019-11-26
|
||||||
*/
|
*/
|
||||||
@DoricPlugin(name = "Refreshable")
|
@DoricPlugin(name = "Refreshable")
|
||||||
public class RefreshableNode extends SuperNode<DoricSwipeLayout> {
|
public class RefreshableNode extends SuperNode<DoricSwipeLayout> implements PullingListener {
|
||||||
|
|
||||||
private String mContentViewId;
|
private String mContentViewId;
|
||||||
private ViewNode mContentNode;
|
private ViewNode mContentNode;
|
||||||
@ -32,7 +34,9 @@ public class RefreshableNode extends SuperNode<DoricSwipeLayout> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected DoricSwipeLayout build() {
|
protected DoricSwipeLayout build() {
|
||||||
return new DoricSwipeLayout(getContext());
|
DoricSwipeLayout doricSwipeLayout = new DoricSwipeLayout(getContext());
|
||||||
|
doricSwipeLayout.getRefreshView().setPullingListenr(this);
|
||||||
|
return doricSwipeLayout;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -162,4 +166,25 @@ public class RefreshableNode extends SuperNode<DoricSwipeLayout> {
|
|||||||
public void isRefreshing(DoricPromise doricPromise) {
|
public void isRefreshing(DoricPromise doricPromise) {
|
||||||
doricPromise.resolve(new JavaValue(this.mView.isRefreshing()));
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -257,4 +257,16 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
|
|||||||
public int getHeight() {
|
public int getHeight() {
|
||||||
return mView.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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,6 +60,18 @@ class RefreshableDemo extends Panel {
|
|||||||
refreshView.setRefreshable(context, false)
|
refreshView.setRefreshable(context, false)
|
||||||
}
|
}
|
||||||
} as IText),
|
} as IText),
|
||||||
|
label('Rotate self').apply({
|
||||||
|
width: 300,
|
||||||
|
height: 50,
|
||||||
|
bgColor: colors[0],
|
||||||
|
textSize: 30,
|
||||||
|
textColor: Color.WHITE,
|
||||||
|
layoutConfig: layoutConfig().exactly(),
|
||||||
|
} as IText).also(v => {
|
||||||
|
v.onClick = () => {
|
||||||
|
v.nativeChannel(context, "setRotation")(0.25)
|
||||||
|
}
|
||||||
|
}),
|
||||||
]).apply({
|
]).apply({
|
||||||
layoutConfig: layoutConfig().atmost().h(LayoutSpec.WRAP_CONTENT),
|
layoutConfig: layoutConfig().atmost().h(LayoutSpec.WRAP_CONTENT),
|
||||||
gravity: gravity().center(),
|
gravity: gravity().center(),
|
||||||
|
File diff suppressed because one or more lines are too long
@ -3,6 +3,7 @@ import { List } from "./list";
|
|||||||
import { Scroller } from "./scroller";
|
import { Scroller } from "./scroller";
|
||||||
import { BridgeContext } from "../runtime/global";
|
import { BridgeContext } from "../runtime/global";
|
||||||
import { layoutConfig } from "./declarative";
|
import { layoutConfig } from "./declarative";
|
||||||
|
import { Image } from "./widgets";
|
||||||
|
|
||||||
export interface IRefreshable extends IView {
|
export interface IRefreshable extends IView {
|
||||||
content: List | Scroller
|
content: List | Scroller
|
||||||
@ -58,3 +59,13 @@ export function refreshable(config: IRefreshable) {
|
|||||||
}
|
}
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface IPullable {
|
||||||
|
startAnimation(): void
|
||||||
|
stopAnimation(): void
|
||||||
|
setProgressRotation(rotation: number): void
|
||||||
|
}
|
||||||
|
|
||||||
|
export class PullableView extends Image {
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user