http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b0e072a4/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..52af2ba 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/b0e072a4/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 c2db44a..cc9373b 100644 --- a/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m +++ b/ios/sdk/WeexSDK/Sources/Engine/WXSDKEngine.m @@ -28,7 +28,6 @@ #import "WXResourceRequestHandlerDefaultImpl.h" #import "WXNavigationDefaultImpl.h" #import "WXURLRewriteDefaultImpl.h" -#import "WXWebSocketDefaultImpl.h" #import "WXSDKManager.h" #import "WXSDKError.h" @@ -168,9 +167,6 @@ [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/b0e072a4/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 d3dceb0..8eb799b 100644 --- a/ios/sdk/WeexSDK/Sources/Events/WXComponent+Events.m +++ b/ios/sdk/WeexSDK/Sources/Events/WXComponent+Events.m @@ -271,9 +271,12 @@ if ([removeEventName isEqualToString:@#eventName]) {\ { if (_tapGesture) { _tapGesture.delegate = nil; - if ([self.view.gestureRecognizers containsObject:_tapGesture]) { - [self.view removeGestureRecognizer:_tapGesture]; + if ([self isViewLoaded]) { + if ([self.view.gestureRecognizers containsObject:_tapGesture]) { + [self.view removeGestureRecognizer:_tapGesture]; + } } + [_tapGesture removeTarget:self action:@selector(onClick:)]; _tapGesture = nil; } } @@ -345,9 +348,12 @@ if ([removeEventName isEqualToString:@#eventName]) {\ for (UISwipeGestureRecognizer *recognizer in _swipeGestures) { recognizer.delegate = nil; - if ([[self.view gestureRecognizers] containsObject:recognizer]) { - [self.view removeGestureRecognizer:recognizer]; + if([self isViewLoaded]) { + if ([[self.view gestureRecognizers] containsObject:recognizer]) { + [self.view removeGestureRecognizer:recognizer]; + } } + [recognizer removeTarget:self action:@selector(onSwipe:)]; } _swipeGestures = nil; } @@ -400,10 +406,12 @@ if ([removeEventName isEqualToString:@#eventName]) {\ { if (_longPressGesture) { _longPressGesture.delegate = nil; - - if([[self.view gestureRecognizers] containsObject:_longPressGesture]) { - [self.view removeGestureRecognizer:_longPressGesture]; + if ([self isViewLoaded]) { + if([[self.view gestureRecognizers] containsObject:_longPressGesture]) { + [self.view removeGestureRecognizer:_longPressGesture]; + } } + [_longPressGesture removeTarget:self action:@selector(onLongPress:)]; _longPressGesture = nil; } } @@ -550,11 +558,14 @@ if ([removeEventName isEqualToString:@#eventName]) {\ && !_listenHorizontalPan && !_listenVerticalPan ) { - if ([[self.view gestureRecognizers] containsObject:_panGesture]) { - [self.view removeGestureRecognizer:_panGesture]; + if ([self isViewLoaded]) { + if ([[self.view gestureRecognizers] containsObject:_panGesture]) { + [self.view removeGestureRecognizer:_panGesture]; + } } _panGesture.delegate = nil; + [_panGesture removeTarget:self action:@selector(onPan:)]; _panGesture = nil; } } @@ -620,8 +631,10 @@ if ([removeEventName isEqualToString:@#eventName]) {\ { if (_touchGesture && !_touchGesture.listenTouchStart && !_touchGesture.listenTouchMove && !_touchGesture.listenTouchEnd && !_touchGesture.listenTouchCancel && !_touchGesture.listenPseudoTouch) { _touchGesture.delegate = nil; - if ([[self.view gestureRecognizers] containsObject:_touchGesture]) { - [self.view removeGestureRecognizer:_touchGesture]; + if ([self isViewLoaded]) { + if ([[self.view gestureRecognizers] containsObject:_touchGesture]) { + [self.view removeGestureRecognizer:_touchGesture]; + } } _touchGesture = nil; } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b0e072a4/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 147dae9..c53d5f1 100644 --- a/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.m +++ b/ios/sdk/WeexSDK/Sources/Manager/WXComponentManager.m @@ -436,12 +436,11 @@ 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 resetStyles:resetStyles]; + [component _updateStylesOnMainThread:[normalStyles copy] resetStyles:resetStyles]; [component readyToRender]; WXPerformBlockOnComponentThread(^{ - [component _updateStylesOnComponentThread:normalStyles resetStyles:resetStyles isUpdateStyles:isUpdateStyles]; + [component _updateStylesOnComponentThread:[normalStyles copy] resetStyles:resetStyles isUpdateStyles:isUpdateStyles]; }); } @@ -595,9 +594,7 @@ static css_node_t * rootNodeGetChild(void *context, int i) WXComponent *component; while ((component = [enumerator nextObject])) { dispatch_async(dispatch_get_main_queue(), ^{ - if ([self isValid]) { - [component _unloadViewWithReusing:NO]; - } + [component _unloadViewWithReusing:NO]; }); } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b0e072a4/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 18e7d7c..0992b49 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,6 +140,16 @@ 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); @@ -158,9 +168,8 @@ { NSDictionary *styles; pthread_mutex_lock(&_propertyMutex); - styles = _styles; + styles = [_styles copy]; pthread_mutex_unlock(&_propertyMutex); - return styles; } @@ -258,8 +267,8 @@ _view.wx_ref = self.ref; _layer.wx_component = self; - if (_role) { - _view.accessibilityTraits |= _role; + if (_roles) { + [_view setAccessibilityTraits:[self _parseAccessibilityTraitsWithTraits:self.view.accessibilityTraits roles:_roles]]; } if (_testId) { @@ -610,10 +619,9 @@ - (void)_configWXComponentA11yWithAttributes:(NSDictionary *)attributes { WX_CHECK_COMPONENT_TYPE(self.componentType) - - if (attributes[@"role"]) { - _role = [WXConvert WXUIAccessibilityTraits:attributes[@"role"]]; - self.view.accessibilityTraits = _role; + if (attributes[@"role"]){ + _roles = attributes[@"role"]; + [self.view setAccessibilityTraits:[self _parseAccessibilityTraitsWithTraits:self.view.accessibilityTraits roles:_roles]]; } if (attributes[@"ariaHidden"]) { _ariaHidden = [WXConvert NSString:attributes[@"ariaHidden"]]; http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b0e072a4/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 824431d..962763b 100644 --- a/ios/sdk/WeexSDK/Sources/Module/WXAnimationModule.m +++ b/ios/sdk/WeexSDK/Sources/Module/WXAnimationModule.m @@ -43,7 +43,6 @@ - (id)copyWithZone:(NSZone *)zone { WXAnimationInfo *info = [[WXAnimationInfo allocWithZone:zone] init]; - info.target = self.target; info.propertyName = self.propertyName; info.fromValue = self.fromValue; @@ -51,7 +50,6 @@ info.duration = self.duration; info.delay = self.delay; info.timingFunction = self.timingFunction; - return info; } @@ -138,6 +136,7 @@ @property (nonatomic,assign) BOOL needLayout; @property (nonatomic, strong) WXTransition *transition; +@property (nonatomic, assign) BOOL isAnimationedSuccess; @end @@ -150,11 +149,14 @@ 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) { - callback([NSString stringWithFormat:@"No component find for ref:%@", nodeRef]); + NSDictionary *message = @{@"result":@"Fail", + @"message":[NSString stringWithFormat:@"No component find for ref:%@", nodeRef]}; + callback(message); } return; } @@ -164,6 +166,7 @@ WX_EXPORT_METHOD(@selector(transition:args:callback:)) }); } + - (NSArray<WXAnimationInfo *> *)animationInfoArrayFromArgs:(NSDictionary *)args target:(WXComponent *)target { UIView *view = target.view; @@ -296,7 +299,6 @@ WX_EXPORT_METHOD(@selector(transition:args:callback:)) } } } - return infos; } @@ -338,7 +340,17 @@ WX_EXPORT_METHOD(@selector(transition:args:callback:)) [CATransaction setAnimationTimingFunction:[WXConvert CAMediaTimingFunction:args[@"timingFunction"]]]; [CATransaction setCompletionBlock:^{ if (callback) { - callback(@"SUCCESS"); + NSDictionary *message; + if (_isAnimationedSuccess) { + message = @{@"result":@"Success", + @"message":@"Success"}; + } + else + { + message = @{@"result":@"Fail", + @"message":@"Animation did not complete"}; + } + callback(message); } }]; NSArray<WXAnimationInfo *> *infos = [self animationInfoArrayFromArgs:args target:targetComponent]; @@ -366,7 +378,9 @@ 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/b0e072a4/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 0f8445a..d3c547c 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]; - [self showToast:info.toastView superView:info.superView duration:info.duration]; + [weakSelf showToast:info.toastView superView:info.superView duration:info.duration]; } } }]; http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b0e072a4/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 e12a11b..c1c7e57 100644 --- a/ios/sdk/WeexSDK/Sources/Module/WXWebSocketModule.m +++ b/ios/sdk/WeexSDK/Sources/Module/WXWebSocketModule.m @@ -23,7 +23,6 @@ #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/b0e072a4/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 c001690..959631a 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 lowercaseString]; + NSString * role = value; if ([role isEqualToString:@"button"]) { accessibilityTrait = UIAccessibilityTraitButton; } else if ([role isEqualToString:@"link"]) { @@ -821,6 +821,28 @@ 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/b0e072a4/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 5487525..81b2ecd 100644 --- a/ios/sdk/WeexSDK/Sources/Utility/WXUtility.m +++ b/ios/sdk/WeexSDK/Sources/Utility/WXUtility.m @@ -326,6 +326,10 @@ 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/b0e072a4/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 deleted file mode 100644 index 6623319..0000000 --- a/ios/sdk/WeexSDK/Sources/WebSocket/SRWebSocket+Weex.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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/b0e072a4/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 deleted file mode 100644 index afdbcfa..0000000 --- a/ios/sdk/WeexSDK/Sources/WebSocket/SRWebSocket+Weex.m +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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/b0e072a4/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 deleted file mode 100644 index 4eb7631..0000000 --- a/ios/sdk/WeexSDK/Sources/WebSocket/WXWebSocketDefaultImpl.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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/b0e072a4/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 deleted file mode 100644 index c0b554e..0000000 --- a/ios/sdk/WeexSDK/Sources/WebSocket/WXWebSocketDefaultImpl.m +++ /dev/null @@ -1,121 +0,0 @@ -/* - * 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/b0e072a4/ios/sdk/WeexSDK/dependency/SRWebSocket.h ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK/dependency/SRWebSocket.h b/ios/sdk/WeexSDK/dependency/SRWebSocket.h deleted file mode 100644 index 094a39d..0000000 --- a/ios/sdk/WeexSDK/dependency/SRWebSocket.h +++ /dev/null @@ -1,135 +0,0 @@ -// -// 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