From c87c4d052f9a450c37ef94875fed170d0a58dc50 Mon Sep 17 00:00:00 2001 From: Sokovikov Date: Fri, 24 Mar 2017 18:07:12 -0700 Subject: [PATCH] Fixed previously broken support for negative `scale` (`transform` style property) Summary: closes #13081 UIExplorer, TransformExample Closes https://github.com/facebook/react-native/pull/13083 Reviewed By: mmmulani Differential Revision: D4758237 Pulled By: shergin fbshipit-source-id: 58385a4cde7a739b6657c293c381644a92918265 --- React/Views/RCTConvert+Transform.m | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/React/Views/RCTConvert+Transform.m b/React/Views/RCTConvert+Transform.m index 32a1abfb5..1625a4917 100644 --- a/React/Views/RCTConvert+Transform.m +++ b/React/Views/RCTConvert+Transform.m @@ -63,6 +63,9 @@ static const NSUInteger kMatrixArrayLength = 4 * 4; RCTLogWarn(@"[RCTConvert 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; + for (NSDictionary *transformConfig in (NSArray *)json) { if (transformConfig.count != 1) { RCTLogConvertError(json, @"a CATransform3D. You must specify exactly one property per transform object."); @@ -90,15 +93,18 @@ static const NSUInteger kMatrixArrayLength = 4 * 4; transform = CATransform3DRotate(transform, rotate, 0, 0, 1); } else if ([property isEqualToString:@"scale"]) { - CGFloat scale = MAX([value floatValue], FLT_EPSILON); + CGFloat scale = [value floatValue]; + scale = ABS(scale) < zeroScaleThreshold ? zeroScaleThreshold : scale; transform = CATransform3DScale(transform, scale, scale, 1); } else if ([property isEqualToString:@"scaleX"]) { - CGFloat scale = MAX([value floatValue], FLT_EPSILON); + CGFloat scale = [value floatValue]; + scale = ABS(scale) < zeroScaleThreshold ? zeroScaleThreshold : scale; transform = CATransform3DScale(transform, scale, 1, 1); } else if ([property isEqualToString:@"scaleY"]) { - CGFloat scale = MAX([value floatValue], FLT_EPSILON); + CGFloat scale = [value floatValue]; + scale = ABS(scale) < zeroScaleThreshold ? zeroScaleThreshold : scale; transform = CATransform3DScale(transform, 1, scale, 1); } else if ([property isEqualToString:@"translate"]) {