Repository: incubator-weex Updated Branches: refs/heads/master 547da26af -> c7880b346
[WEEX-350][iOS] fix anim crash caused by problem that [WXConvert CGFloat:] return nan when unsupported input Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/c7880b34 Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/c7880b34 Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/c7880b34 Branch: refs/heads/master Commit: c7880b346b5af741d6c2113efdb22141d28c170b Parents: 547da26 Author: zouming.zm <zouming...@alibaba-inc.com> Authored: Thu May 10 17:40:15 2018 +0800 Committer: zouming.zm <zouming...@alibaba-inc.com> Committed: Thu May 10 17:43:47 2018 +0800 ---------------------------------------------------------------------- .../Sources/Layout/WXComponent+Layout.mm | 2 +- ios/sdk/WeexSDK/Sources/Utility/WXConvert.h | 16 +++++++++++ ios/sdk/WeexSDK/Sources/Utility/WXConvert.m | 30 +++++++++++++++++++- 3 files changed, 46 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/c7880b34/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.mm ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.mm b/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.mm index 2f8368d..01c36ec 100644 --- a/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.mm +++ b/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.mm @@ -540,7 +540,7 @@ do {\ } -(CGFloat)judgePropValuePropValue:(NSString *)propValue defaultValue:(CGFloat)defaultValue{ - CGFloat convertValue = (CGFloat)[WXConvert WXPixelType:propValue scaleFactor:self.weexInstance.pixelScaleFactor]; + CGFloat convertValue = (CGFloat)[WXConvert WXFlexPixelType:propValue scaleFactor:self.weexInstance.pixelScaleFactor]; if (!isnan(convertValue)) { return convertValue; } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/c7880b34/ios/sdk/WeexSDK/Sources/Utility/WXConvert.h ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK/Sources/Utility/WXConvert.h b/ios/sdk/WeexSDK/Sources/Utility/WXConvert.h index 775fa05..12c3a1c 100644 --- a/ios/sdk/WeexSDK/Sources/Utility/WXConvert.h +++ b/ios/sdk/WeexSDK/Sources/Utility/WXConvert.h @@ -28,7 +28,21 @@ @interface WXConvert : NSObject + (BOOL)BOOL:(id)value; + +/** + * @abstract convert value to CGFloat value + * @param value value + * @return CGFloat value + */ + (CGFloat)CGFloat:(id)value; + +/** + * @abstract convert value to CGFloat value, notice that it will return nan if input value is unsupported + * @param value value + * @return CGFloat value or nan(unsupported input) + */ ++ (CGFloat)flexCGFloat:(id)value; + + (NSUInteger)NSUInteger:(id)value; + (NSInteger)NSInteger:(id)value; + (NSString *)NSString:(id)value; @@ -39,6 +53,8 @@ typedef CGFloat WXPixelType; // @parameter scaleFactor: please use weexInstance's pixelScaleFactor property + (WXPixelType)WXPixelType:(id)value scaleFactor:(CGFloat)scaleFactor; +// WXPixelType that use flexCGFloat to convert ++ (WXPixelType)WXFlexPixelType:(id)value scaleFactor:(CGFloat)scaleFactor; + (css_direction_t)css_direction_t:(id)value; + (css_flex_direction_t)css_flex_direction_t:(id)value; http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/c7880b34/ios/sdk/WeexSDK/Sources/Utility/WXConvert.m ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK/Sources/Utility/WXConvert.m b/ios/sdk/WeexSDK/Sources/Utility/WXConvert.m index a303ddb..0fb2813 100644 --- a/ios/sdk/WeexSDK/Sources/Utility/WXConvert.m +++ b/ios/sdk/WeexSDK/Sources/Utility/WXConvert.m @@ -63,6 +63,25 @@ WX_NUMBER_CONVERT(NSUInteger, unsignedIntegerValue) { if ([value isKindOfClass:[NSString class]]) { NSString *valueString = (NSString *)value; + if ([valueString hasSuffix:@"px"] || [valueString hasSuffix:@"wx"]) { + valueString = [valueString substringToIndex:(valueString.length - 2)]; + } + if ([value hasPrefix:@"env(safe-area-inset-"] &&[value hasSuffix:@")"]){ + NSUInteger start = [value rangeOfString:@"env(safe-area-inset-"].location +@"env(safe-area-inset-".length; + NSUInteger end = [value rangeOfString:@")" options:NSBackwardsSearch].location; + value = [value substringWithRange:NSMakeRange(start, end-start)]; + return [self safeAreaInset:value]; + } + return [valueString doubleValue]; + } + + return [self double:value]; +} + ++ (CGFloat)flexCGFloat:(id)value +{ + if ([value isKindOfClass:[NSString class]]) { + NSString *valueString = (NSString *)value; if (valueString.length <=0) { return NAN; } @@ -81,7 +100,6 @@ WX_NUMBER_CONVERT(NSUInteger, unsignedIntegerValue) } return [valueString doubleValue]; } - return [self double:value]; } @@ -167,6 +185,16 @@ WX_NUMBER_CONVERT(NSUInteger, unsignedIntegerValue) return pixel * scaleFactor; } ++ (WXPixelType)WXFlexPixelType:(id)value scaleFactor:(CGFloat)scaleFactor +{ + CGFloat pixel = [self flexCGFloat:value]; + + if ([value isKindOfClass:[NSString class]] && ([value hasSuffix:@"wx"]|| [value hasPrefix:@"env(safe-area-inset-"])) { + return pixel; + } + return pixel * scaleFactor; +} + #pragma mark CSS Layout + (css_direction_t)css_direction_t:(id)value