From 56b7dfe27b748b7dcfb917bd0168cce2d389986e Mon Sep 17 00:00:00 2001 From: wwwcg Date: Tue, 19 Nov 2024 15:06:51 +0800 Subject: [PATCH] refactor(ios): update transform converter and animation demo add protect when handling buffer --- .../src/modules/Animation/index.jsx | 6 ++--- framework/ios/base/bridge/HippyBridge.mm | 3 +-- .../ios/utils/HippyConvert+NativeRender.m | 26 ++++++++++++------- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/driver/js/examples/hippy-react-demo/src/modules/Animation/index.jsx b/driver/js/examples/hippy-react-demo/src/modules/Animation/index.jsx index 866eed69e7b..0dd70d3a9c5 100644 --- a/driver/js/examples/hippy-react-demo/src/modules/Animation/index.jsx +++ b/driver/js/examples/hippy-react-demo/src/modules/Animation/index.jsx @@ -234,7 +234,6 @@ export default class AnimationExample extends React.Component { ], repeatCount: 'loop', }); - // TODO iOS暂不支持文字颜色渐变动画 this.txtColorAnimationSet = new AnimationSet({ children: [ { @@ -565,7 +564,7 @@ export default class AnimationExample extends React.Component { }]} /> - 颜色渐变动画(文字渐变仅Android支持) + 颜色渐变动画 { this.textColorRef = ref; }} style={[styles.colorText, { - // TODO iOS暂不支持文字颜色渐变动画 - color: Platform.OS === 'android' ? this.txtColorAnimationSet : 'white', + color: this.txtColorAnimationSet, }]}>颜色渐变背景和文字 diff --git a/framework/ios/base/bridge/HippyBridge.mm b/framework/ios/base/bridge/HippyBridge.mm index af83b0a4d70..79e2748bc5d 100644 --- a/framework/ios/base/bridge/HippyBridge.mm +++ b/framework/ios/base/bridge/HippyBridge.mm @@ -880,8 +880,7 @@ - (void)batchDidComplete { - (void)handleBuffer:(NSArray *)buffer { NSArray *requestsArray = [HippyConvert NSArray:buffer]; - - if (HIPPY_DEBUG && requestsArray.count <= HippyBridgeFieldParams) { + if (requestsArray.count <= HippyBridgeFieldParams) { HippyLogError(@"Buffer should contain at least %tu sub-arrays. Only found %tu", HippyBridgeFieldParams + 1, requestsArray.count); return; } diff --git a/renderer/native/ios/utils/HippyConvert+NativeRender.m b/renderer/native/ios/utils/HippyConvert+NativeRender.m index e5168f0c1d4..80804de7fac 100644 --- a/renderer/native/ios/utils/HippyConvert+NativeRender.m +++ b/renderer/native/ios/utils/HippyConvert+NativeRender.m @@ -76,13 +76,14 @@ + (CATransform3D)CATransform3D:(id)json { } // legacy matrix support if ([(NSArray *)json count] == kMatrixArrayLength && [json[0] isKindOfClass:[NSNumber class]]) { - HippyLogWarn( - @"[HippyConvert CATransform3D:] has deprecated a matrix as input. Pass an array of configs (which can contain a matrix key) instead."); + HippyLogWarn(@"[HippyConvert CATransform3D:] has deprecated a matrix as input. \ + Pass an array of configs (which can contain a matrix key) instead."); return [self CATransform3DFromMatrix:json]; } CGFloat zeroScaleThreshold = FLT_EPSILON; + CATransform3D next; for (NSDictionary *transformConfig in (NSArray *)json) { if (transformConfig.count != 1) { HippyLogError(@"[%@], a CATransform3D. You must specify exactly one property per transform object.", json); @@ -91,10 +92,13 @@ + (CATransform3D)CATransform3D:(id)json { NSString *property = transformConfig.allKeys[0]; id value = HippyNilIfNull(transformConfig[property]); if ([property isEqualToString:@"matrix"]) { - transform = [self CATransform3DFromMatrix:value]; + next = [self CATransform3DFromMatrix:value]; + transform = CATransform3DConcat(next, transform); } else if ([property isEqualToString:@"perspective"]) { - transform.m34 = -1 / [value floatValue]; + next = CATransform3DIdentity; + next.m34 = -1 / [value floatValue]; + transform = CATransform3DConcat(next, transform); } else if ([property isEqualToString:@"rotateX"]) { CGFloat rotate = [self convertToRadians:value]; @@ -111,18 +115,16 @@ + (CATransform3D)CATransform3D:(id)json { } else if ([property isEqualToString:@"scale"]) { CGFloat scale = [value floatValue]; scale = ABS(scale) < zeroScaleThreshold ? zeroScaleThreshold : scale; - transform.m34 = 0.f; - transform = CATransform3DScale(transform, scale, scale, scale); + transform = CATransform3DScale(transform, scale, scale, 1); + } else if ([property isEqualToString:@"scaleX"]) { CGFloat scale = [value floatValue]; scale = ABS(scale) < zeroScaleThreshold ? zeroScaleThreshold : scale; - transform.m34 = 0.f; transform = CATransform3DScale(transform, scale, 1, 1); } else if ([property isEqualToString:@"scaleY"]) { CGFloat scale = [value floatValue]; scale = ABS(scale) < zeroScaleThreshold ? zeroScaleThreshold : scale; - transform.m34 = 0.f; transform = CATransform3DScale(transform, 1, scale, 1); } else if ([property isEqualToString:@"translate"]) { @@ -146,11 +148,15 @@ + (CATransform3D)CATransform3D:(id)json { } else if ([property isEqualToString:@"skewX"]) { CGFloat skew = [self convertToRadians:value]; - transform.m21 = tanf(skew); + next = CATransform3DIdentity; + next.m21 = tanf(skew); + transform = CATransform3DConcat(next, transform); } else if ([property isEqualToString:@"skewY"]) { CGFloat skew = [self convertToRadians:value]; - transform.m12 = tanf(skew); + next = CATransform3DIdentity; + next.m12 = tanf(skew); + transform = CATransform3DConcat(next, transform); } else { HippyLogError(@"Unsupported transform type for a CATransform3D: %@.", property);