add perspective for rotattionX and rotationY

This commit is contained in:
pengfei.zhou
2020-06-03 14:53:32 +08:00
committed by osborn
parent c14ec1954e
commit 9b181830fc
17 changed files with 449 additions and 26 deletions

View File

@@ -41,6 +41,9 @@ - (instancetype)initWithContext:(DoricContext *)context callbackId:(NSString *)c
- (void)resolve:(id)result {
__weak typeof(self) __self = self;
if (self.context == nil) {
return;
}
[[self.context.driver invokeDoricMethod:DORIC_BRIDGE_RESOLVE
argumentsArray:result
? @[self.context.contextId, self.callbackId, result]

View File

@@ -108,6 +108,7 @@ @interface DoricViewNode ()
@property(nonatomic, copy) NSNumber *pivotY;
@property(nonatomic, strong) NSDictionary *gradientProps;
@property(nonatomic, assign) CGSize gradientSize;
@property(nonatomic, assign) CGFloat perspective;
@end
@implementation DoricViewNode
@@ -115,6 +116,7 @@ @implementation DoricViewNode
- (instancetype)initWithContext:(DoricContext *)doricContext {
if (self = [super initWithContext:doricContext]) {
_callbackIds = [[NSMutableDictionary alloc] init];
_perspective = 200;
}
return self;
}
@@ -163,8 +165,7 @@ - (void)transformProperties {
if (self.rotationX || self.rotationY) {
CATransform3D transform3D = CATransform3DMakeAffineTransform(transform);
transform3D.m34 = -1.0 / 500;
transform3D.m34 = -1.0 / self.perspective;
if (self.rotationX) {
transform3D = CATransform3DRotate(transform3D, (self.rotationX.floatValue ?: 0) * M_PI, 1, 0, 0);
}
@@ -274,6 +275,8 @@ - (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop
self.rotationX = prop;
} else if ([name isEqualToString:@"rotationY"]) {
self.rotationY = prop;
} else if ([name isEqualToString:@"perspective"]) {
self.perspective = [prop floatValue];
} else if ([name isEqualToString:@"padding"]) {
view.doricLayout.paddingLeft = 0;
view.doricLayout.paddingRight = 0;
@@ -733,6 +736,12 @@ - (NSNumber *)getAnimatedValue:(NSString *)key {
if ([@"rotation" isEqualToString:key]) {
return self.rotation;
}
if ([@"rotationX" isEqualToString:key]) {
return self.rotationX;
}
if ([@"rotationY" isEqualToString:key]) {
return self.rotationY;
}
return nil;
}
@@ -747,6 +756,10 @@ - (void)setAnimatedValue:(NSString *)key value:(NSNumber *)value {
self.scaleY = value;
} else if ([@"rotation" isEqualToString:key]) {
self.rotation = value;
} else if ([@"rotationX" isEqualToString:key]) {
self.rotationX = value;
} else if ([@"rotationY" isEqualToString:key]) {
self.rotationY = value;
}
}
@@ -765,6 +778,14 @@ - (CABasicAnimation *)parseChangeable:(NSDictionary *)params fillMode:(NSNumber
animation.keyPath = @"transform.rotation.z";
animation.fromValue = @([params[@"fromValue"] floatValue] * M_PI);
animation.toValue = @([params[@"toValue"] floatValue] * M_PI);
} else if ([@"rotationX" isEqualToString:key]) {
animation.keyPath = @"transform.rotation.x";
animation.fromValue = @([params[@"fromValue"] floatValue] * M_PI);
animation.toValue = @([params[@"toValue"] floatValue] * M_PI);
} else if ([@"rotationY" isEqualToString:key]) {
animation.keyPath = @"transform.rotation.y";
animation.fromValue = @([params[@"fromValue"] floatValue] * M_PI);
animation.toValue = @([params[@"toValue"] floatValue] * M_PI);
} else if ([@"backgroundColor" isEqualToString:key]) {
animation.keyPath = @"backgroundColor";
animation.fromValue = params[@"fromValue"];