diff --git a/Android/doric/src/main/java/pub/doric/plugin/ShaderPlugin.java b/Android/doric/src/main/java/pub/doric/plugin/ShaderPlugin.java index 0dc81e23..ec48ebd8 100644 --- a/Android/doric/src/main/java/pub/doric/plugin/ShaderPlugin.java +++ b/Android/doric/src/main/java/pub/doric/plugin/ShaderPlugin.java @@ -174,7 +174,11 @@ public class ShaderPlugin extends DoricJavaPlugin { if (clz == DoricPromise.class) { return doricPromise; } else { - return jsValue; + try { + return DoricUtils.toJavaObject(clz, jsValue); + } catch (Exception e) { + return jsValue; + } } } } diff --git a/Android/doric/src/main/java/pub/doric/refresh/DoricSwipeLayout.java b/Android/doric/src/main/java/pub/doric/refresh/DoricSwipeLayout.java index 411f13ef..03840f27 100644 --- a/Android/doric/src/main/java/pub/doric/refresh/DoricSwipeLayout.java +++ b/Android/doric/src/main/java/pub/doric/refresh/DoricSwipeLayout.java @@ -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()); + mRefreshView.setProgressRotation((float) mRefreshView.getBottom() / (float) mRefreshView.getMeasuredHeight() * 2); } } diff --git a/Android/doric/src/main/java/pub/doric/shader/ViewNode.java b/Android/doric/src/main/java/pub/doric/shader/ViewNode.java index 8cbc1ce3..b3a27341 100644 --- a/Android/doric/src/main/java/pub/doric/shader/ViewNode.java +++ b/Android/doric/src/main/java/pub/doric/shader/ViewNode.java @@ -184,6 +184,17 @@ public abstract class ViewNode extends DoricContextHolder { setBgColor(prop.asNumber().toInt()); } break; + case "rotation": + if (isAnimating()) { + addAnimator(ObjectAnimator.ofFloat( + this, + name, + getRotation(), + prop.asNumber().toFloat())); + } else { + setRotation(prop.asNumber().toFloat()); + } + break; case "onClick": final String functionId = prop.asString().value(); view.setOnClickListener(new View.OnClickListener() { @@ -374,20 +385,19 @@ public abstract class ViewNode extends DoricContextHolder { } @DoricMethod - public void setRotation(JSValue jsValue) { - float rotation = jsValue.asNumber().toFloat(); - while (rotation > 1) { - rotation = rotation - 1; + public void setRotation(float rotation) { + while (rotation > 2) { + rotation = rotation - 2; } - while (rotation < -1) { - rotation = rotation + 1; + while (rotation < -2) { + rotation = rotation + 2; } - getNodeView().setRotation(rotation * 360); + getNodeView().setRotation(rotation * 180); } @DoricMethod public float getRotation() { - return getNodeView().getRotation() / 360; + return getNodeView().getRotation() / 180; } @DoricMethod diff --git a/demo/src/AnimatorDemo.ts b/demo/src/AnimatorDemo.ts index c908c0a7..edc3acc8 100644 --- a/demo/src/AnimatorDemo.ts +++ b/demo/src/AnimatorDemo.ts @@ -71,6 +71,16 @@ class AnimatorDemo extends Panel { }); } }), + thisLabel('Rotation').apply({ + onClick: () => { + animate(this)({ + animations: () => { + view.rotation = view.rotation || 0 + 0.5 + }, + duration: 3000, + }); + } + }), ]).apply({ space: 10 } as IHLayout), ] ).apply({ space: 10 } as IVLayout), diff --git a/iOS/Pod/Classes/Refresh/DoricSwipeRefreshLayout.m b/iOS/Pod/Classes/Refresh/DoricSwipeRefreshLayout.m index 42809bbe..fcc5eb4d 100644 --- a/iOS/Pod/Classes/Refresh/DoricSwipeRefreshLayout.m +++ b/iOS/Pod/Classes/Refresh/DoricSwipeRefreshLayout.m @@ -109,7 +109,7 @@ - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL - (void)scrollViewDidScroll:(UIScrollView *)scrollView { if (scrollView.contentOffset.y <= 0) { - [self.swipePullingDelegate setProgressRotation:-scrollView.contentOffset.y / self.headerView.height]; + [self.swipePullingDelegate setProgressRotation:-scrollView.contentOffset.y / self.headerView.height * 2]; } } diff --git a/iOS/Pod/Classes/Shader/DoricViewNode.m b/iOS/Pod/Classes/Shader/DoricViewNode.m index db7f3140..d3d28881 100644 --- a/iOS/Pod/Classes/Shader/DoricViewNode.m +++ b/iOS/Pod/Classes/Shader/DoricViewNode.m @@ -123,6 +123,8 @@ - (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop view.y = [(NSNumber *) prop floatValue]; } else if ([name isEqualToString:@"bgColor"]) { view.backgroundColor = DoricColor(prop); + } else if ([name isEqualToString:@"rotation"]) { + [self setRotation:prop]; } else if ([name isEqualToString:@"layoutConfig"]) { if (self.superNode && [prop isKindOfClass:[NSDictionary class]]) { [self.superNode blendSubNode:self layoutConfig:prop]; @@ -238,13 +240,13 @@ - (void)setRotation:(NSNumber *)rotation { if (rotation.floatValue == 0) { self.view.transform = CGAffineTransformIdentity; } else { - self.view.transform = CGAffineTransformMakeRotation(M_PI * rotation.floatValue * 2); + self.view.transform = CGAffineTransformMakeRotation(M_PI * rotation.floatValue); } } - (NSNumber *)getRotation { float radius = atan2f((float) self.view.transform.b, (float) self.view.transform.a); - float degree = (float) (radius / M_PI / 2); + float degree = (float) (radius / M_PI); return @(degree); } diff --git a/js-framework/src/ui/view.ts b/js-framework/src/ui/view.ts index 899ff3a7..0281d84c 100644 --- a/js-framework/src/ui/view.ts +++ b/js-framework/src/ui/view.ts @@ -61,6 +61,9 @@ export abstract class View implements Modeling, IView { @Property bgColor?: Color | GradientColor + @Property + rotation?: number + @Property corners?: number | { leftTop?: number; rightTop?: number; leftBottom?: number; rightBottom?: number }