http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/7b2150a5/ios/sdk/WeexSDK/Sources/Component/WXImageComponent.m ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK/Sources/Component/WXImageComponent.m b/ios/sdk/WeexSDK/Sources/Component/WXImageComponent.m index bd31e97..b7027b1 100644 --- a/ios/sdk/WeexSDK/Sources/Component/WXImageComponent.m +++ b/ios/sdk/WeexSDK/Sources/Component/WXImageComponent.m @@ -29,7 +29,6 @@ #import "UIBezierPath+Weex.h" #import "WXSDKEngine.h" #import "WXUtility.h" -#import <pthread/pthread.h> @interface WXImageView : UIImageView @@ -47,12 +46,8 @@ static dispatch_queue_t WXImageUpdateQueue; @interface WXImageComponent () -{ - NSString * _imageSrc; - pthread_mutex_t _imageSrcMutex; - pthread_mutexattr_t _propertMutexAttr; -} +@property (nonatomic, strong) NSString *imageSrc; @property (nonatomic, strong) NSString *placeholdSrc; @property (nonatomic, assign) CGFloat blurRadius; @property (nonatomic, assign) UIViewContentMode resizeMode; @@ -77,15 +72,8 @@ WX_EXPORT_METHOD(@selector(save:)) if (!WXImageUpdateQueue) { WXImageUpdateQueue = dispatch_queue_create("com.taobao.weex.ImageUpdateQueue", DISPATCH_QUEUE_SERIAL); } - - pthread_mutexattr_init(&(_propertMutexAttr)); - pthread_mutexattr_settype(&(_propertMutexAttr), PTHREAD_MUTEX_RECURSIVE); - pthread_mutex_init(&(_imageSrcMutex), &(_propertMutexAttr)); - if (attributes[@"src"]) { - pthread_mutex_lock(&(_imageSrcMutex)); _imageSrc = [[WXConvert NSString:attributes[@"src"]] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; - pthread_mutex_unlock(&(_imageSrcMutex)); } else { WXLogWarning(@"image src is nil"); } @@ -235,14 +223,13 @@ WX_EXPORT_METHOD(@selector(save:)) - (void)dealloc { [self cancelImage]; - pthread_mutex_destroy(&(_imageSrcMutex)); - pthread_mutexattr_destroy(&_propertMutexAttr); } - (void)updateAttributes:(NSDictionary *)attributes { if (attributes[@"src"]) { - [self setImageSrc:[[WXConvert NSString:attributes[@"src"]] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]]; + _imageSrc = [[WXConvert NSString:attributes[@"src"]] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; + [self updateImage]; } if (attributes[@"quality"]) { _imageQuality = [WXConvert WXImageQuality:attributes[@"quality"]]; @@ -321,24 +308,13 @@ WX_EXPORT_METHOD(@selector(save:)) } } -- (NSString *)imageSrc -{ - pthread_mutex_lock(&(_imageSrcMutex)); - NSString * imageSrcCpy = [_imageSrc copy]; - pthread_mutex_unlock(&(_imageSrcMutex)); - - return imageSrcCpy; -} - - (void)setImageSrc:(NSString*)src { - pthread_mutex_lock(&(_imageSrcMutex)); if (![src isEqualToString:_imageSrc]) { _imageSrc = src; _imageDownloadFinish = NO; [self updateImage]; } - pthread_mutex_unlock(&(_imageSrcMutex)); } - (void)updateImage @@ -372,6 +348,7 @@ WX_EXPORT_METHOD(@selector(save:)) NSString *placeholderSrc = self.placeholdSrc; if ([WXUtility isBlankString:placeholderSrc]) { +// WXLogError(@"image placeholder src is empty"); return; } @@ -410,7 +387,8 @@ WX_EXPORT_METHOD(@selector(save:)) - (void)updateContentImageWithFailedBlock:(void(^)(NSString *, NSError *))downloadFailedBlock { - NSString *imageSrc = [NSString stringWithFormat:@"%@", self.imageSrc?:@""]; + NSString *imageSrc = self.imageSrc; + if ([WXUtility isBlankString:imageSrc]) { WXLogError(@"image src is empty"); return;
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/7b2150a5/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m b/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m index 7556074..664b0e8 100644 --- a/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m +++ b/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m @@ -362,14 +362,12 @@ do {\ - (NSAttributedString *)ctAttributedString { - NSAttributedString * attributedString = nil; pthread_mutex_lock(&(_ctAttributedStringMutex)); if (!_ctAttributedString) { - _ctAttributedString = [self buildCTAttributeString]; + _ctAttributedString = [[self buildCTAttributeString] copy]; } - attributedString = [_ctAttributedString copy]; pthread_mutex_unlock(&(_ctAttributedStringMutex)); - return attributedString; + return [_ctAttributedString copy]; } - (void)repaintText:(NSNotification *)notification http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/7b2150a5/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 52af2ba..5d22939 100644 --- a/ios/sdk/WeexSDK/Sources/Display/WXComponent+Display.m +++ b/ios/sdk/WeexSDK/Sources/Display/WXComponent+Display.m @@ -331,13 +331,13 @@ WXRadii *radii = borderRect.radii; CGFloat topLeft = radii.topLeft, topRight = radii.topRight, bottomLeft = radii.bottomLeft, bottomRight = radii.bottomRight; - CGContextSetAlpha(context, _opacity); // fill background color if (_backgroundColor && CGColorGetAlpha(_backgroundColor.CGColor) > 0) { CGContextSetFillColorWithColor(context, _backgroundColor.CGColor); UIBezierPath *bezierPath = [UIBezierPath wx_bezierPathWithRoundedRect:rect topLeft:topLeft topRight:topRight bottomLeft:bottomLeft bottomRight:bottomRight]; [bezierPath fill]; } + // Top if (_borderTopWidth > 0) { if(_borderTopStyle == WXBorderStyleDashed || _borderTopStyle == WXBorderStyleDotted){ http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/7b2150a5/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m b/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m index cc9373b..c2db44a 100644 --- a/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m +++ b/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m @@ -28,6 +28,7 @@ #import "WXResourceRequestHandlerDefaultImpl.h" #import "WXNavigationDefaultImpl.h" #import "WXURLRewriteDefaultImpl.h" +#import "WXWebSocketDefaultImpl.h" #import "WXSDKManager.h" #import "WXSDKError.h" @@ -167,6 +168,9 @@ [self registerHandler:[WXResourceRequestHandlerDefaultImpl new] withProtocol:@protocol(WXResourceRequestHandler)]; [self registerHandler:[WXNavigationDefaultImpl new] withProtocol:@protocol(WXNavigationProtocol)]; [self registerHandler:[WXURLRewriteDefaultImpl new] withProtocol:@protocol(WXURLRewriteProtocol)]; + if (NSClassFromString(@"WXWebSocketDefaultImpl")) { + [self registerHandler:[NSClassFromString(@"WXWebSocketDefaultImpl") new] withProtocol:NSProtocolFromString(@"WXWebSocketHandler")]; + } } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/7b2150a5/ios/sdk/WeexSDK/Sources/Events/WXComponent+Events.m ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK/Sources/Events/WXComponent+Events.m b/ios/sdk/WeexSDK/Sources/Events/WXComponent+Events.m index 8eb799b..d3dceb0 100644 --- a/ios/sdk/WeexSDK/Sources/Events/WXComponent+Events.m +++ b/ios/sdk/WeexSDK/Sources/Events/WXComponent+Events.m @@ -271,12 +271,9 @@ if ([removeEventName isEqualToString:@#eventName]) {\ { if (_tapGesture) { _tapGesture.delegate = nil; - if ([self isViewLoaded]) { - if ([self.view.gestureRecognizers containsObject:_tapGesture]) { - [self.view removeGestureRecognizer:_tapGesture]; - } + if ([self.view.gestureRecognizers containsObject:_tapGesture]) { + [self.view removeGestureRecognizer:_tapGesture]; } - [_tapGesture removeTarget:self action:@selector(onClick:)]; _tapGesture = nil; } } @@ -348,12 +345,9 @@ if ([removeEventName isEqualToString:@#eventName]) {\ for (UISwipeGestureRecognizer *recognizer in _swipeGestures) { recognizer.delegate = nil; - if([self isViewLoaded]) { - if ([[self.view gestureRecognizers] containsObject:recognizer]) { - [self.view removeGestureRecognizer:recognizer]; - } + if ([[self.view gestureRecognizers] containsObject:recognizer]) { + [self.view removeGestureRecognizer:recognizer]; } - [recognizer removeTarget:self action:@selector(onSwipe:)]; } _swipeGestures = nil; } @@ -406,12 +400,10 @@ if ([removeEventName isEqualToString:@#eventName]) {\ { if (_longPressGesture) { _longPressGesture.delegate = nil; - if ([self isViewLoaded]) { - if([[self.view gestureRecognizers] containsObject:_longPressGesture]) { - [self.view removeGestureRecognizer:_longPressGesture]; - } + + if([[self.view gestureRecognizers] containsObject:_longPressGesture]) { + [self.view removeGestureRecognizer:_longPressGesture]; } - [_longPressGesture removeTarget:self action:@selector(onLongPress:)]; _longPressGesture = nil; } } @@ -558,14 +550,11 @@ if ([removeEventName isEqualToString:@#eventName]) {\ && !_listenHorizontalPan && !_listenVerticalPan ) { - if ([self isViewLoaded]) { - if ([[self.view gestureRecognizers] containsObject:_panGesture]) { - [self.view removeGestureRecognizer:_panGesture]; - } + if ([[self.view gestureRecognizers] containsObject:_panGesture]) { + [self.view removeGestureRecognizer:_panGesture]; } _panGesture.delegate = nil; - [_panGesture removeTarget:self action:@selector(onPan:)]; _panGesture = nil; } } @@ -631,10 +620,8 @@ if ([removeEventName isEqualToString:@#eventName]) {\ { if (_touchGesture && !_touchGesture.listenTouchStart && !_touchGesture.listenTouchMove && !_touchGesture.listenTouchEnd && !_touchGesture.listenTouchCancel && !_touchGesture.listenPseudoTouch) { _touchGesture.delegate = nil; - if ([self isViewLoaded]) { - if ([[self.view gestureRecognizers] containsObject:_touchGesture]) { - [self.view removeGestureRecognizer:_touchGesture]; - } + if ([[self.view gestureRecognizers] containsObject:_touchGesture]) { + [self.view removeGestureRecognizer:_touchGesture]; } _touchGesture = nil; } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/7b2150a5/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.m ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.m b/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.m index c53d5f1..147dae9 100644 --- a/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.m +++ b/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.m @@ -436,11 +436,12 @@ static css_node_t * rootNodeGetChild(void *context, int i) NSMutableDictionary *normalStyles = [NSMutableDictionary new]; NSMutableArray *resetStyles = [NSMutableArray new]; [self filterStyles:styles normalStyles:normalStyles resetStyles:resetStyles]; - [component _updateStylesOnMainThread:[normalStyles copy] resetStyles:resetStyles]; + + [component _updateStylesOnMainThread:normalStyles resetStyles:resetStyles]; [component readyToRender]; WXPerformBlockOnComponentThread(^{ - [component _updateStylesOnComponentThread:[normalStyles copy] resetStyles:resetStyles isUpdateStyles:isUpdateStyles]; + [component _updateStylesOnComponentThread:normalStyles resetStyles:resetStyles isUpdateStyles:isUpdateStyles]; }); } @@ -594,7 +595,9 @@ static css_node_t * rootNodeGetChild(void *context, int i) WXComponent *component; while ((component = [enumerator nextObject])) { dispatch_async(dispatch_get_main_queue(), ^{ - [component _unloadViewWithReusing:NO]; + if ([self isValid]) { + [component _unloadViewWithReusing:NO]; + } }); } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/7b2150a5/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..18e7d7c 100644 --- a/ios/sdk/WeexSDK/Sources/Model/WXComponent.m +++ b/ios/sdk/WeexSDK/Sources/Model/WXComponent.m @@ -108,13 +108,13 @@ } } + if (attributes[@"role"]){ + _role = [WXConvert WXUIAccessibilityTraits:attributes[@"role"]]; + } if (attributes[@"ariaHidden"]) { _ariaHidden = [WXConvert NSString:attributes[@"ariaHidden"]]; } - if (attributes[@"role"]) { - _roles = attributes[@"role"]; - } if (attributes[@"ariaLabel"]) { _ariaLabel = [WXConvert NSString:attributes[@"ariaLabel"]]; } @@ -140,16 +140,6 @@ return self; } -- (UIAccessibilityTraits)_parseAccessibilityTraitsWithTraits:(UIAccessibilityTraits)trait roles:(NSString*)roleStr -{ - UIAccessibilityTraits newTrait = trait; - for (NSString * role in [roleStr componentsSeparatedByString:@" "]) { - newTrait |= [WXConvert WXUIAccessibilityTraits: role]; - } - - return newTrait; -} - - (void)dealloc { free_css_node(_cssNode); @@ -168,8 +158,9 @@ { NSDictionary *styles; pthread_mutex_lock(&_propertyMutex); - styles = [_styles copy]; + styles = _styles; pthread_mutex_unlock(&_propertyMutex); + return styles; } @@ -267,8 +258,8 @@ _view.wx_ref = self.ref; _layer.wx_component = self; - if (_roles) { - [_view setAccessibilityTraits:[self _parseAccessibilityTraitsWithTraits:self.view.accessibilityTraits roles:_roles]]; + if (_role) { + _view.accessibilityTraits |= _role; } if (_testId) { @@ -619,9 +610,10 @@ - (void)_configWXComponentA11yWithAttributes:(NSDictionary *)attributes { WX_CHECK_COMPONENT_TYPE(self.componentType) - if (attributes[@"role"]){ - _roles = attributes[@"role"]; - [self.view setAccessibilityTraits:[self _parseAccessibilityTraitsWithTraits:self.view.accessibilityTraits roles:_roles]]; + + if (attributes[@"role"]) { + _role = [WXConvert WXUIAccessibilityTraits:attributes[@"role"]]; + self.view.accessibilityTraits = _role; } if (attributes[@"ariaHidden"]) { _ariaHidden = [WXConvert NSString:attributes[@"ariaHidden"]]; http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/7b2150a5/ios/sdk/WeexSDK/Sources/Module/WXAnimationModule.m ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK/Sources/Module/WXAnimationModule.m b/ios/sdk/WeexSDK/Sources/Module/WXAnimationModule.m index 962763b..824431d 100644 --- a/ios/sdk/WeexSDK/Sources/Module/WXAnimationModule.m +++ b/ios/sdk/WeexSDK/Sources/Module/WXAnimationModule.m @@ -43,6 +43,7 @@ - (id)copyWithZone:(NSZone *)zone { WXAnimationInfo *info = [[WXAnimationInfo allocWithZone:zone] init]; + info.target = self.target; info.propertyName = self.propertyName; info.fromValue = self.fromValue; @@ -50,6 +51,7 @@ info.duration = self.duration; info.delay = self.delay; info.timingFunction = self.timingFunction; + return info; } @@ -136,7 +138,6 @@ @property (nonatomic,assign) BOOL needLayout; @property (nonatomic, strong) WXTransition *transition; -@property (nonatomic, assign) BOOL isAnimationedSuccess; @end @@ -149,14 +150,11 @@ WX_EXPORT_METHOD(@selector(transition:args:callback:)) - (void)transition:(NSString *)nodeRef args:(NSDictionary *)args callback:(WXModuleCallback)callback { _needLayout = NO; - _isAnimationedSuccess = YES; WXPerformBlockOnComponentThread(^{ WXComponent *targetComponent = [self.weexInstance componentForRef:nodeRef]; if (!targetComponent) { if (callback) { - NSDictionary *message = @{@"result":@"Fail", - @"message":[NSString stringWithFormat:@"No component find for ref:%@", nodeRef]}; - callback(message); + callback([NSString stringWithFormat:@"No component find for ref:%@", nodeRef]); } return; } @@ -166,7 +164,6 @@ WX_EXPORT_METHOD(@selector(transition:args:callback:)) }); } - - (NSArray<WXAnimationInfo *> *)animationInfoArrayFromArgs:(NSDictionary *)args target:(WXComponent *)target { UIView *view = target.view; @@ -299,6 +296,7 @@ WX_EXPORT_METHOD(@selector(transition:args:callback:)) } } } + return infos; } @@ -340,17 +338,7 @@ WX_EXPORT_METHOD(@selector(transition:args:callback:)) [CATransaction setAnimationTimingFunction:[WXConvert CAMediaTimingFunction:args[@"timingFunction"]]]; [CATransaction setCompletionBlock:^{ if (callback) { - NSDictionary *message; - if (_isAnimationedSuccess) { - message = @{@"result":@"Success", - @"message":@"Success"}; - } - else - { - message = @{@"result":@"Fail", - @"message":@"Animation did not complete"}; - } - callback(message); + callback(@"SUCCESS"); } }]; NSArray<WXAnimationInfo *> *infos = [self animationInfoArrayFromArgs:args target:targetComponent]; @@ -378,9 +366,7 @@ WX_EXPORT_METHOD(@selector(transition:args:callback:)) animation.fillMode = kCAFillModeForwards; WXAnimationDelegate *delegate = [[WXAnimationDelegate alloc] initWithAnimationInfo:info finishBlock:^(BOOL isFinish) { - if (!isFinish) { - _isAnimationedSuccess = isFinish; - } + }]; animation.delegate = delegate; http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/7b2150a5/ios/sdk/WeexSDK/Sources/Module/WXModalUIModule.m ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK/Sources/Module/WXModalUIModule.m b/ios/sdk/WeexSDK/Sources/Module/WXModalUIModule.m index d3c547c..0f8445a 100644 --- a/ios/sdk/WeexSDK/Sources/Module/WXModalUIModule.m +++ b/ios/sdk/WeexSDK/Sources/Module/WXModalUIModule.m @@ -215,7 +215,7 @@ static const CGFloat WXToastDefaultPadding = 30.0; [WXToastManager sharedManager].toastingView = toastView; [superView addSubview:toastView]; - __weak typeof(self) weakSelf = self; + [UIView animateWithDuration:0.2 delay:duration options:UIViewAnimationOptionCurveEaseInOut animations:^{ toastView.transform = CGAffineTransformConcat(toastView.transform, CGAffineTransformMakeScale(0.8, 0.8)) ; } completion:^(BOOL finished) { @@ -230,7 +230,7 @@ static const CGFloat WXToastDefaultPadding = 30.0; [queue removeObjectAtIndex:0]; if (queue.count > 0) { WXToastInfo *info = [queue firstObject]; - [weakSelf showToast:info.toastView superView:info.superView duration:info.duration]; + [self showToast:info.toastView superView:info.superView duration:info.duration]; } } }]; http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/7b2150a5/ios/sdk/WeexSDK/Sources/Module/WXWebSocketModule.m ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK/Sources/Module/WXWebSocketModule.m b/ios/sdk/WeexSDK/Sources/Module/WXWebSocketModule.m index c1c7e57..e12a11b 100644 --- a/ios/sdk/WeexSDK/Sources/Module/WXWebSocketModule.m +++ b/ios/sdk/WeexSDK/Sources/Module/WXWebSocketModule.m @@ -23,6 +23,7 @@ #import "WXHandlerFactory.h" #import "WXWebSocketLoader.h" #import "WXConvert.h" +#import "SRWebSocket.h" @interface WXWebSocketModule() http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/7b2150a5/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 959631a..c001690 100644 --- a/ios/sdk/WeexSDK/Sources/Utility/WXConvert.m +++ b/ios/sdk/WeexSDK/Sources/Utility/WXConvert.m @@ -806,7 +806,7 @@ WX_NUMBER_CONVERT(NSUInteger, unsignedIntegerValue) if (![value isKindOfClass:[NSString class]]) { return accessibilityTrait; } - NSString * role = value; + NSString * role = [value lowercaseString]; if ([role isEqualToString:@"button"]) { accessibilityTrait = UIAccessibilityTraitButton; } else if ([role isEqualToString:@"link"]) { @@ -821,28 +821,6 @@ WX_NUMBER_CONVERT(NSUInteger, unsignedIntegerValue) accessibilityTrait = UIAccessibilityTraitTabBar; } #endif - } else if ([role isEqualToString:@"frequentUpdates"]) { - accessibilityTrait = UIAccessibilityTraitUpdatesFrequently; - } else if ([role isEqualToString:@"startsMedia"]) { - accessibilityTrait = UIAccessibilityTraitStartsMediaSession; - } else if ([role isEqualToString:@"allowsDirectInteraction"]) { - accessibilityTrait = UIAccessibilityTraitAllowsDirectInteraction; - } else if ([role isEqualToString:@"summary"]) { - accessibilityTrait = UIAccessibilityTraitSummaryElement; - } else if ([role isEqualToString:@"header"]) { - accessibilityTrait = UIAccessibilityTraitHeader; - } else if ([role isEqualToString:@"keyboardKey"]) { - accessibilityTrait = UIAccessibilityTraitKeyboardKey; - } else if ([role isEqualToString:@"disabled"]) { - accessibilityTrait = UIAccessibilityTraitNotEnabled; - } else if ([role isEqualToString:@"playSound"]) { - accessibilityTrait = UIAccessibilityTraitPlaysSound; - } else if ([role isEqualToString:@"selected"]) { - accessibilityTrait = UIAccessibilityTraitSelected; - } else if ([role isEqualToString:@"pageTurn"]) { - accessibilityTrait = UIAccessibilityTraitCausesPageTurn; - } else if ([role isEqualToString:@"text"]) { - accessibilityTrait = UIAccessibilityTraitStaticText; } return accessibilityTrait; http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/7b2150a5/ios/sdk/WeexSDK/Sources/Utility/WXUtility.m ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK/Sources/Utility/WXUtility.m b/ios/sdk/WeexSDK/Sources/Utility/WXUtility.m index 81b2ecd..5487525 100644 --- a/ios/sdk/WeexSDK/Sources/Utility/WXUtility.m +++ b/ios/sdk/WeexSDK/Sources/Utility/WXUtility.m @@ -326,10 +326,6 @@ CGFloat WXFloorPixelValue(CGFloat value) } + (BOOL)isBlankString:(NSString *)string { - if (![string isKindOfClass:[NSString class]]) { - WXLogError(@"%@ is not a string", string); - return true; - } if (string == nil || string == NULL || [string isKindOfClass:[NSNull class]]) { return true; } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/7b2150a5/ios/sdk/WeexSDK/Sources/WebSocket/SRWebSocket+Weex.h ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK/Sources/WebSocket/SRWebSocket+Weex.h b/ios/sdk/WeexSDK/Sources/WebSocket/SRWebSocket+Weex.h new file mode 100644 index 0000000..6623319 --- /dev/null +++ b/ios/sdk/WeexSDK/Sources/WebSocket/SRWebSocket+Weex.h @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#import "SRWebSocket.h" +#import "WXWebSocketHandler.h" +#import <objc/runtime.h> + +@interface SRWebSocket (Weex) + +@property (nonatomic, copy) NSString *wx_Identifier; +@property (nonatomic, weak) id<WXWebSocketDelegate> wx_WebSocketDelegate; + +@end http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/7b2150a5/ios/sdk/WeexSDK/Sources/WebSocket/SRWebSocket+Weex.m ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK/Sources/WebSocket/SRWebSocket+Weex.m b/ios/sdk/WeexSDK/Sources/WebSocket/SRWebSocket+Weex.m new file mode 100644 index 0000000..afdbcfa --- /dev/null +++ b/ios/sdk/WeexSDK/Sources/WebSocket/SRWebSocket+Weex.m @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#import "SRWebSocket+Weex.h" +static char wx_IdentifierKey; +static char wx_WebSocketDelegateKey; + + +@implementation SRWebSocket (Weex) + +-(void)setWx_Identifier:(NSString *)wx_Identifier +{ + objc_setAssociatedObject(self, &wx_IdentifierKey, wx_Identifier, OBJC_ASSOCIATION_COPY); +} + +-(NSString *)wx_Identifier +{ + return objc_getAssociatedObject(self, &wx_IdentifierKey); +} + +-(void)setWx_WebSocketDelegate:(id<WXWebSocketDelegate>)wx_WebSocketDelegate +{ + objc_setAssociatedObject(self, &wx_WebSocketDelegateKey, wx_WebSocketDelegate, OBJC_ASSOCIATION_COPY); +} + +-(NSString *)wx_WebSocketDelegate +{ + return objc_getAssociatedObject(self, &wx_WebSocketDelegateKey); +} + +@end http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/7b2150a5/ios/sdk/WeexSDK/Sources/WebSocket/WXWebSocketDefaultImpl.h ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK/Sources/WebSocket/WXWebSocketDefaultImpl.h b/ios/sdk/WeexSDK/Sources/WebSocket/WXWebSocketDefaultImpl.h new file mode 100644 index 0000000..4eb7631 --- /dev/null +++ b/ios/sdk/WeexSDK/Sources/WebSocket/WXWebSocketDefaultImpl.h @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#import <Foundation/Foundation.h> +#import "WXWebSocketHandler.h" + +@interface WXWebSocketDefaultImpl : NSObject<WXWebSocketHandler> + +@end http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/7b2150a5/ios/sdk/WeexSDK/Sources/WebSocket/WXWebSocketDefaultImpl.m ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK/Sources/WebSocket/WXWebSocketDefaultImpl.m b/ios/sdk/WeexSDK/Sources/WebSocket/WXWebSocketDefaultImpl.m new file mode 100644 index 0000000..c0b554e --- /dev/null +++ b/ios/sdk/WeexSDK/Sources/WebSocket/WXWebSocketDefaultImpl.m @@ -0,0 +1,121 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#import "WXWebSocketDefaultImpl.h" +#import "SRWebSocket.h" +#import "WXThreadSafeMutableDictionary.h" +#import "SRWebSocket+Weex.h" + +@interface WXWebSocketDefaultImpl()<SRWebSocketDelegate> + +@end + +@implementation WXWebSocketDefaultImpl +{ + WXThreadSafeMutableDictionary<NSString *, SRWebSocket *> *_webSockets; +} + +#pragma mark - WXWebSocketHandler +- (void)open:(NSString *)url protocol:(NSString *)protocol identifier:(NSString *)identifier withDelegate:(id<WXWebSocketDelegate>)delegate +{ + if(!_webSockets) + { + _webSockets = [WXThreadSafeMutableDictionary new]; + } + if([_webSockets objectForKey:identifier]){ + SRWebSocket *webSocket = [_webSockets objectForKey:identifier]; + webSocket.delegate = nil; + [webSocket close]; + + } + NSArray *protols; + if([protocol length]>0){ + protols = [NSArray arrayWithObject:protocol]; + } + SRWebSocket *webSocket = [[SRWebSocket alloc] initWithURL:[NSURL URLWithString:url] protocols:protols]; + webSocket.delegate = self; + [webSocket open]; + webSocket.wx_Identifier = identifier; + webSocket.wx_WebSocketDelegate = delegate; + [_webSockets setObject:webSocket forKey:identifier]; +} + +- (void)send:(id)identifier data:(NSString *)data +{ + SRWebSocket *webSocket = [_webSockets objectForKey:identifier]; + if(webSocket) { + [webSocket send:data]; + } +} + +- (void)close:(NSString *)identifier +{ + SRWebSocket *webSocket = [_webSockets objectForKey:identifier]; + if(webSocket) { + [webSocket close]; + } +} + +- (void)close:(NSString *)identifier code:(NSInteger)code reason:(NSString *)reason +{ + SRWebSocket *webSocket = [_webSockets objectForKey:identifier]; + if(webSocket) { + [webSocket closeWithCode:code reason:reason]; + } +} + +- (void)clear:(NSString *)identifier +{ + SRWebSocket *webSocket = [_webSockets objectForKey:identifier]; + if(webSocket) { + webSocket.delegate = nil; + [webSocket close]; + [_webSockets removeObjectForKey:identifier]; + } +} + +#pragma mark -SRWebSocketDelegate +- (void)webSocketDidOpen:(SRWebSocket *)webSocket; +{ + if (webSocket.wx_WebSocketDelegate && [webSocket.wx_WebSocketDelegate respondsToSelector:@selector(didOpen)]) { + [webSocket.wx_WebSocketDelegate didOpen]; + } +} + +- (void)webSocket:(SRWebSocket *)webSocket didFailWithError:(NSError *)error; +{ + if (webSocket.wx_WebSocketDelegate && [webSocket.wx_WebSocketDelegate respondsToSelector:@selector(didFailWithError:)]) { + [webSocket.wx_WebSocketDelegate didFailWithError:error]; + } +} + +- (void)webSocket:(SRWebSocket *)webSocket didReceiveMessage:(id)message; +{ + if (webSocket.wx_WebSocketDelegate && [webSocket.wx_WebSocketDelegate respondsToSelector:@selector(didReceiveMessage:)]) { + [webSocket.wx_WebSocketDelegate didReceiveMessage:message]; + } +} + +- (void)webSocket:(SRWebSocket *)webSocket didCloseWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean; +{ + if (webSocket.wx_WebSocketDelegate && [webSocket.wx_WebSocketDelegate respondsToSelector:@selector(didCloseWithCode:reason:wasClean:)]) { + [webSocket.wx_WebSocketDelegate didCloseWithCode:code reason:reason wasClean:wasClean]; + } +} +@end http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/7b2150a5/ios/sdk/WeexSDK/dependency/SRWebSocket.h ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK/dependency/SRWebSocket.h b/ios/sdk/WeexSDK/dependency/SRWebSocket.h new file mode 100644 index 0000000..094a39d --- /dev/null +++ b/ios/sdk/WeexSDK/dependency/SRWebSocket.h @@ -0,0 +1,135 @@ +// +// Copyright 2012 Square Inc. +// Portions Copyright (c) 2016-present, Facebook, Inc. +// +// All rights reserved. +// +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory. +// + +#import <Foundation/Foundation.h> +#import <Security/SecCertificate.h> + +typedef NS_ENUM(NSInteger, SRReadyState) { + SR_CONNECTING = 0, + SR_OPEN = 1, + SR_CLOSING = 2, + SR_CLOSED = 3, +}; + +typedef enum SRStatusCode : NSInteger { + SRStatusCodeNormal = 1000, + SRStatusCodeGoingAway = 1001, + SRStatusCodeProtocolError = 1002, + SRStatusCodeUnhandledType = 1003, + // 1004 reserved. + SRStatusNoStatusReceived = 1005, + // 1004-1006 reserved. + SRStatusCodeInvalidUTF8 = 1007, + SRStatusCodePolicyViolated = 1008, + SRStatusCodeMessageTooBig = 1009, +} SRStatusCode; + +@class SRWebSocket; + +extern NSString *const SRWebSocketErrorDomain; +extern NSString *const SRHTTPResponseErrorKey; + +#pragma mark - SRWebSocketDelegate + +@protocol SRWebSocketDelegate; + +#pragma mark - SRWebSocket + +@interface SRWebSocket : NSObject <NSStreamDelegate> + +@property (nonatomic, weak) id <SRWebSocketDelegate> delegate; + +@property (nonatomic, readonly) SRReadyState readyState; +@property (nonatomic, readonly, retain) NSURL *url; + + +@property (nonatomic, readonly) CFHTTPMessageRef receivedHTTPHeaders; + +// Optional array of cookies (NSHTTPCookie objects) to apply to the connections +@property (nonatomic, readwrite) NSArray * requestCookies; + +// This returns the negotiated protocol. +// It will be nil until after the handshake completes. +@property (nonatomic, readonly, copy) NSString *protocol; + +// Protocols should be an array of strings that turn into Sec-WebSocket-Protocol. +- (id)initWithURLRequest:(NSURLRequest *)request protocols:(NSArray *)protocols allowsUntrustedSSLCertificates:(BOOL)allowsUntrustedSSLCertificates; +- (id)initWithURLRequest:(NSURLRequest *)request protocols:(NSArray *)protocols; +- (id)initWithURLRequest:(NSURLRequest *)request; + +// Some helper constructors. +- (id)initWithURL:(NSURL *)url protocols:(NSArray *)protocols allowsUntrustedSSLCertificates:(BOOL)allowsUntrustedSSLCertificates; +- (id)initWithURL:(NSURL *)url protocols:(NSArray *)protocols; +- (id)initWithURL:(NSURL *)url; + +// Delegate queue will be dispatch_main_queue by default. +// You cannot set both OperationQueue and dispatch_queue. +- (void)setDelegateOperationQueue:(NSOperationQueue*) queue; +- (void)setDelegateDispatchQueue:(dispatch_queue_t) queue; + +// By default, it will schedule itself on +[NSRunLoop SR_networkRunLoop] using defaultModes. +- (void)scheduleInRunLoop:(NSRunLoop *)aRunLoop forMode:(NSString *)mode; +- (void)unscheduleFromRunLoop:(NSRunLoop *)aRunLoop forMode:(NSString *)mode; + +// SRWebSockets are intended for one-time-use only. Open should be called once and only once. +- (void)open; + +- (void)close; +- (void)closeWithCode:(NSInteger)code reason:(NSString *)reason; + +// Send a UTF8 String or Data. +- (void)send:(id)data; + +// Send Data (can be nil) in a ping message. +- (void)sendPing:(NSData *)data; + +@end + +#pragma mark - SRWebSocketDelegate + +@protocol SRWebSocketDelegate <NSObject> + +// message will either be an NSString if the server is using text +// or NSData if the server is using binary. +- (void)webSocket:(SRWebSocket *)webSocket didReceiveMessage:(id)message; + +@optional + +- (void)webSocketDidOpen:(SRWebSocket *)webSocket; +- (void)webSocket:(SRWebSocket *)webSocket didFailWithError:(NSError *)error; +- (void)webSocket:(SRWebSocket *)webSocket didCloseWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean; +- (void)webSocket:(SRWebSocket *)webSocket didReceivePong:(NSData *)pongPayload; + +@end + +#pragma mark - NSURLRequest (CertificateAdditions) + +@interface NSURLRequest (CertificateAdditions) + +@property (nonatomic, retain, readonly) NSArray *SR_SSLPinnedCertificates; + +@end + +#pragma mark - NSMutableURLRequest (CertificateAdditions) + +@interface NSMutableURLRequest (CertificateAdditions) + +@property (nonatomic, retain) NSArray *SR_SSLPinnedCertificates; + +@end + +#pragma mark - NSRunLoop (SRWebSocket) + +@interface NSRunLoop (SRWebSocket) + ++ (NSRunLoop *)SR_networkRunLoop; + +@end