* [ios] fix transition filter crash and make some change with NS_Option
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/2985c588 Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/2985c588 Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/2985c588 Branch: refs/heads/0.16-dev Commit: 2985c5887d0a0b63c533d948962eff0789d40e68 Parents: ac1abc9 Author: doumafang <doumaf...@gmail.com> Authored: Fri Sep 22 17:21:59 2017 +0800 Committer: doumafang <doumaf...@gmail.com> Committed: Fri Sep 22 17:21:59 2017 +0800 ---------------------------------------------------------------------- .../Sources/Display/WXComponent+Display.m | 14 +------- ios/sdk/WeexSDK/Sources/Model/WXComponent.m | 38 +++++++++----------- ios/sdk/WeexSDK/Sources/Module/WXTransition.h | 16 +++++++++ ios/sdk/WeexSDK/Sources/Module/WXTransition.m | 24 +++++++++++++ 4 files changed, 57 insertions(+), 35 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2985c588/ios/sdk/WeexSDK/Sources/Display/WXComponent+Display.m ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK/Sources/Display/WXComponent+Display.m b/ios/sdk/WeexSDK/Sources/Display/WXComponent+Display.m index 5d22939..5e8442a 100644 --- a/ios/sdk/WeexSDK/Sources/Display/WXComponent+Display.m +++ b/ios/sdk/WeexSDK/Sources/Display/WXComponent+Display.m @@ -553,25 +553,13 @@ do {\ [self _resetNativeBorderRadius]; _layer.borderWidth = _borderTopWidth; _layer.borderColor = _borderTopColor.CGColor; - if (![self _isTransitionBackgroundColorStyles:styles]) { + if ((_transition.transitionOptions & WXTransitionOptionsBackgroundColor) != WXTransitionOptionsBackgroundColor ) { _layer.backgroundColor = _backgroundColor.CGColor; } } } } -- (BOOL)_isTransitionBackgroundColorStyles:(NSDictionary *)styles -{ - BOOL yesOrNo = false; - NSString *property = self.styles[kWXTransitionProperty]; - if (property) { - if (([property containsString:@"backgroundColor"])) { - yesOrNo = true; - } - } - return yesOrNo; -} - - (BOOL)_bitmapOpaqueWithSize:(CGSize)size { CGRect rect = CGRectMake(0, 0, size.width, size.height); http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2985c588/ios/sdk/WeexSDK/Sources/Model/WXComponent.m ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK/Sources/Model/WXComponent.m b/ios/sdk/WeexSDK/Sources/Model/WXComponent.m index 0992b49..13affb8 100644 --- a/ios/sdk/WeexSDK/Sources/Model/WXComponent.m +++ b/ios/sdk/WeexSDK/Sources/Model/WXComponent.m @@ -85,7 +85,6 @@ _attributes = attributes ? [NSMutableDictionary dictionaryWithDictionary:attributes] : [NSMutableDictionary dictionary]; _events = events ? [NSMutableArray arrayWithArray:events] : [NSMutableArray array]; _subcomponents = [NSMutableArray array]; - _absolutePosition = CGPointMake(NAN, NAN); _isNeedJoinLayoutSystem = YES; @@ -96,6 +95,7 @@ _accessibilityHintContent = nil; _async = NO; + _transition = [[WXTransition alloc]initWithStyles:styles]; //TODO set indicator style if ([type isEqualToString:@"indicator"]) { @@ -168,7 +168,7 @@ { NSDictionary *styles; pthread_mutex_lock(&_propertyMutex); - styles = [_styles copy]; + styles = _styles; pthread_mutex_unlock(&_propertyMutex); return styles; } @@ -344,7 +344,6 @@ if (WX_MONITOR_INSTANCE_PERF_IS_RECORDED(WXPTFirstScreenRender, self.weexInstance)) { return; } - CGPoint absolutePosition = [self.supercomponent.view convertPoint:_view.frame.origin toView:_weexInstance.rootView]; if (absolutePosition.y + _view.frame.size.height > self.weexInstance.rootView.frame.size.height + 1) { WX_MONITOR_INSTANCE_PERF_END(WXPTFirstScreenRender, self.weexInstance); @@ -460,9 +459,6 @@ - (void)_updateStylesOnComponentThread:(NSDictionary *)styles resetStyles:(NSMutableArray *)resetStyles isUpdateStyles:(BOOL)isUpdateStyles { if ([self _isPropertyTransitionStyles:styles]) { - if (!_transition) { - _transition = [WXTransition new]; - } [_transition _handleTransitionWithStyles:styles withTarget:self]; } else { styles = [self parseStyles:styles]; @@ -478,17 +474,16 @@ - (BOOL)_isPropertyTransitionStyles:(NSDictionary *)styles { BOOL yesOrNo = false; - NSString *property = self.styles[kWXTransitionProperty]; - if (property) { - if (([property containsString:@"width"]&&styles[@"width"]) - ||([property containsString:@"height"]&&styles[@"height"]) - ||([property containsString:@"right"]&&styles[@"right"]) - ||([property containsString:@"left"]&&styles[@"left"]) - ||([property containsString:@"bottom"]&&styles[@"bottom"]) - ||([property containsString:@"top"]&&styles[@"top"]) - ||([property containsString:@"backgroundColor"]&&styles[@"backgroundColor"]) - ||([property containsString:@"transform"]&&styles[@"transform"]) - ||([property containsString:@"opacity"]&&styles[@"opacity"])) { + if (_transition.transitionOptions != WXTransitionOptionsNone) { + if ((_transition.transitionOptions & WXTransitionOptionsWidth &&styles[@"width"]) + ||(_transition.transitionOptions & WXTransitionOptionsHeight &&styles[@"height"]) + ||(_transition.transitionOptions & WXTransitionOptionsRight &&styles[@"right"]) + ||(_transition.transitionOptions & WXTransitionOptionsLeft &&styles[@"left"]) + ||(_transition.transitionOptions & WXTransitionOptionsBottom &&styles[@"bottom"]) + ||(_transition.transitionOptions & WXTransitionOptionsTop &&styles[@"top"]) + ||(_transition.transitionOptions & WXTransitionOptionsBackgroundColor &&styles[@"backgroundColor"]) + ||(_transition.transitionOptions & WXTransitionOptionsTransform &&styles[@"transform"]) + ||(_transition.transitionOptions & WXTransitionOptionsOpacity &&styles[@"opacity"])) { yesOrNo = true; } } @@ -498,11 +493,10 @@ - (BOOL)_isPropertyAnimationStyles:(NSDictionary *)styles { BOOL yesOrNo = false; - NSString *property = self.styles[kWXTransitionProperty]; - if (property) { - if (([property containsString:@"backgroundColor"]&&styles[@"backgroundColor"]) - ||([property containsString:@"transform"]&&styles[@"transform"]) - ||([property containsString:@"opacity"]&&styles[@"opacity"])) { + if (_transition.transitionOptions != WXTransitionOptionsNone) { + if ((_transition.transitionOptions & WXTransitionOptionsBackgroundColor &&styles[@"backgroundColor"]) + ||(_transition.transitionOptions & WXTransitionOptionsTransform &&styles[@"transform"]) + ||(_transition.transitionOptions & WXTransitionOptionsOpacity &&styles[@"opacity"])) { yesOrNo = true; } } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2985c588/ios/sdk/WeexSDK/Sources/Module/WXTransition.h ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK/Sources/Module/WXTransition.h b/ios/sdk/WeexSDK/Sources/Module/WXTransition.h index 777b5bd..bb33067 100644 --- a/ios/sdk/WeexSDK/Sources/Module/WXTransition.h +++ b/ios/sdk/WeexSDK/Sources/Module/WXTransition.h @@ -24,6 +24,20 @@ #define kWXTransitionDelay @"transitionDelay" #define kWXTransitionTimingFunction @"transitionTimingFunction" +typedef NS_OPTIONS(NSUInteger, WXTransitionOptions) { + WXTransitionOptionsNone = 0, + WXTransitionOptionsWidth = 1 << 0, + WXTransitionOptionsHeight = 1 << 1, + WXTransitionOptionsRight = 1 << 2, + WXTransitionOptionsLeft = 1 << 3, + WXTransitionOptionsBottom = 1 << 4, + WXTransitionOptionsTop = 1 << 5, + WXTransitionOptionsBackgroundColor = 1 << 6, + WXTransitionOptionsTransform = 1 << 7, + WXTransitionOptionsOpacity = 1 << 8 +}; + + @interface WXLayoutAnimationInfo : NSObject @property (nonatomic, strong) id fromValue; @property (nonatomic, strong) id toValue; @@ -35,6 +49,8 @@ @property(nonatomic,strong) NSMutableDictionary *fromStyles; @property(nonatomic,strong) NSMutableDictionary *addStyles; @property(nonatomic,strong) NSMutableArray *propertyArray; +@property(nonatomic,assign) WXTransitionOptions transitionOptions; +- (instancetype) initWithStyles:(NSDictionary *)styles; - (void)_handleTransitionWithStyles:(NSDictionary *)styles withTarget:(WXComponent *)targetComponent; @end http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2985c588/ios/sdk/WeexSDK/Sources/Module/WXTransition.m ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK/Sources/Module/WXTransition.m b/ios/sdk/WeexSDK/Sources/Module/WXTransition.m index be963ae..2994c1a 100644 --- a/ios/sdk/WeexSDK/Sources/Module/WXTransition.m +++ b/ios/sdk/WeexSDK/Sources/Module/WXTransition.m @@ -63,6 +63,30 @@ @implementation WXTransition + +- (instancetype) initWithStyles:(NSDictionary *)styles +{ + if (self = [super init]) { + NSString *property = styles[kWXTransitionProperty]; + if (property) { + self.transitionOptions |= [property containsString:@"width"]? WXTransitionOptionsWidth:0; + self.transitionOptions |= [property containsString:@"height"]? WXTransitionOptionsHeight:0; + self.transitionOptions |= [property containsString:@"right"]? WXTransitionOptionsRight:0; + self.transitionOptions |= [property containsString:@"left"]? WXTransitionOptionsLeft:0; + self.transitionOptions |= [property containsString:@"bottom"]? WXTransitionOptionsBottom:0; + self.transitionOptions |= [property containsString:@"top"]? WXTransitionOptionsTop:0; + self.transitionOptions |= [property containsString:@"backgroundColor"]? WXTransitionOptionsBackgroundColor:0; + self.transitionOptions |= [property containsString:@"transform"]? WXTransitionOptionsTransform:0; + self.transitionOptions |= [property containsString:@"opacity"]? WXTransitionOptionsOpacity:0; + } + else + { + return self; + } + } + return self; +} + #pragma mark - HandleStyle - (void)_handleTransitionWithStyles:(NSDictionary *)styles withTarget:(WXComponent *)targetComponent {