feat:set rotation as view's prop

This commit is contained in:
pengfei.zhou 2019-11-29 15:16:15 +08:00
parent 4e596642f2
commit 3a89571f42
7 changed files with 42 additions and 13 deletions

View File

@ -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;
}
}
}
}

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());
mRefreshView.setProgressRotation((float) mRefreshView.getBottom() / (float) mRefreshView.getMeasuredHeight() * 2);
}
}

View File

@ -184,6 +184,17 @@ public abstract class ViewNode<T extends View> 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<T extends View> 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

View File

@ -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),

View File

@ -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];
}
}

View File

@ -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);
}

View File

@ -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 }