feat:set rotation as view's prop
This commit is contained in:
parent
4e596642f2
commit
3a89571f42
@ -174,7 +174,11 @@ public class ShaderPlugin extends DoricJavaPlugin {
|
|||||||
if (clz == DoricPromise.class) {
|
if (clz == DoricPromise.class) {
|
||||||
return doricPromise;
|
return doricPromise;
|
||||||
} else {
|
} else {
|
||||||
return jsValue;
|
try {
|
||||||
|
return DoricUtils.toJavaObject(clz, jsValue);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return jsValue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -912,7 +912,7 @@ public class DoricSwipeLayout extends ViewGroup implements NestedScrollingParent
|
|||||||
ViewCompat.offsetTopAndBottom(mRefreshView, offset);
|
ViewCompat.offsetTopAndBottom(mRefreshView, offset);
|
||||||
mCurrentTargetOffsetTop = mRefreshView.getTop();
|
mCurrentTargetOffsetTop = mRefreshView.getTop();
|
||||||
if (mRefreshView.getMeasuredHeight() > 0) {
|
if (mRefreshView.getMeasuredHeight() > 0) {
|
||||||
mRefreshView.setProgressRotation((float) mRefreshView.getBottom() / (float) mRefreshView.getMeasuredHeight());
|
mRefreshView.setProgressRotation((float) mRefreshView.getBottom() / (float) mRefreshView.getMeasuredHeight() * 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,6 +184,17 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
|
|||||||
setBgColor(prop.asNumber().toInt());
|
setBgColor(prop.asNumber().toInt());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case "rotation":
|
||||||
|
if (isAnimating()) {
|
||||||
|
addAnimator(ObjectAnimator.ofFloat(
|
||||||
|
this,
|
||||||
|
name,
|
||||||
|
getRotation(),
|
||||||
|
prop.asNumber().toFloat()));
|
||||||
|
} else {
|
||||||
|
setRotation(prop.asNumber().toFloat());
|
||||||
|
}
|
||||||
|
break;
|
||||||
case "onClick":
|
case "onClick":
|
||||||
final String functionId = prop.asString().value();
|
final String functionId = prop.asString().value();
|
||||||
view.setOnClickListener(new View.OnClickListener() {
|
view.setOnClickListener(new View.OnClickListener() {
|
||||||
@ -374,20 +385,19 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@DoricMethod
|
@DoricMethod
|
||||||
public void setRotation(JSValue jsValue) {
|
public void setRotation(float rotation) {
|
||||||
float rotation = jsValue.asNumber().toFloat();
|
while (rotation > 2) {
|
||||||
while (rotation > 1) {
|
rotation = rotation - 2;
|
||||||
rotation = rotation - 1;
|
|
||||||
}
|
}
|
||||||
while (rotation < -1) {
|
while (rotation < -2) {
|
||||||
rotation = rotation + 1;
|
rotation = rotation + 2;
|
||||||
}
|
}
|
||||||
getNodeView().setRotation(rotation * 360);
|
getNodeView().setRotation(rotation * 180);
|
||||||
}
|
}
|
||||||
|
|
||||||
@DoricMethod
|
@DoricMethod
|
||||||
public float getRotation() {
|
public float getRotation() {
|
||||||
return getNodeView().getRotation() / 360;
|
return getNodeView().getRotation() / 180;
|
||||||
}
|
}
|
||||||
|
|
||||||
@DoricMethod
|
@DoricMethod
|
||||||
|
@ -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 IHLayout),
|
||||||
]
|
]
|
||||||
).apply({ space: 10 } as IVLayout),
|
).apply({ space: 10 } as IVLayout),
|
||||||
|
@ -109,7 +109,7 @@ - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL
|
|||||||
|
|
||||||
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
|
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
|
||||||
if (scrollView.contentOffset.y <= 0) {
|
if (scrollView.contentOffset.y <= 0) {
|
||||||
[self.swipePullingDelegate setProgressRotation:-scrollView.contentOffset.y / self.headerView.height];
|
[self.swipePullingDelegate setProgressRotation:-scrollView.contentOffset.y / self.headerView.height * 2];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,6 +123,8 @@ - (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop
|
|||||||
view.y = [(NSNumber *) prop floatValue];
|
view.y = [(NSNumber *) prop floatValue];
|
||||||
} else if ([name isEqualToString:@"bgColor"]) {
|
} else if ([name isEqualToString:@"bgColor"]) {
|
||||||
view.backgroundColor = DoricColor(prop);
|
view.backgroundColor = DoricColor(prop);
|
||||||
|
} else if ([name isEqualToString:@"rotation"]) {
|
||||||
|
[self setRotation:prop];
|
||||||
} else if ([name isEqualToString:@"layoutConfig"]) {
|
} else if ([name isEqualToString:@"layoutConfig"]) {
|
||||||
if (self.superNode && [prop isKindOfClass:[NSDictionary class]]) {
|
if (self.superNode && [prop isKindOfClass:[NSDictionary class]]) {
|
||||||
[self.superNode blendSubNode:self layoutConfig:prop];
|
[self.superNode blendSubNode:self layoutConfig:prop];
|
||||||
@ -238,13 +240,13 @@ - (void)setRotation:(NSNumber *)rotation {
|
|||||||
if (rotation.floatValue == 0) {
|
if (rotation.floatValue == 0) {
|
||||||
self.view.transform = CGAffineTransformIdentity;
|
self.view.transform = CGAffineTransformIdentity;
|
||||||
} else {
|
} else {
|
||||||
self.view.transform = CGAffineTransformMakeRotation(M_PI * rotation.floatValue * 2);
|
self.view.transform = CGAffineTransformMakeRotation(M_PI * rotation.floatValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSNumber *)getRotation {
|
- (NSNumber *)getRotation {
|
||||||
float radius = atan2f((float) self.view.transform.b, (float) self.view.transform.a);
|
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);
|
return @(degree);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,6 +61,9 @@ export abstract class View implements Modeling, IView {
|
|||||||
@Property
|
@Property
|
||||||
bgColor?: Color | GradientColor
|
bgColor?: Color | GradientColor
|
||||||
|
|
||||||
|
@Property
|
||||||
|
rotation?: number
|
||||||
|
|
||||||
@Property
|
@Property
|
||||||
corners?: number | { leftTop?: number; rightTop?: number; leftBottom?: number; rightBottom?: number }
|
corners?: number | { leftTop?: number; rightTop?: number; leftBottom?: number; rightBottom?: number }
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user