You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by ji...@apache.org on 2017/02/20 06:40:58 UTC
[09/50] [abbrv] incubator-weex git commit: V0.10.0 stable gitlab
(#178)
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b5123119/ios/sdk/WeexSDK/Sources/Utility/WXUtility.h
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Utility/WXUtility.h b/ios/sdk/WeexSDK/Sources/Utility/WXUtility.h
index 8237d39..4f55e8e 100644
--- a/ios/sdk/WeexSDK/Sources/Utility/WXUtility.h
+++ b/ios/sdk/WeexSDK/Sources/Utility/WXUtility.h
@@ -202,7 +202,7 @@ extern _Nonnull SEL WXSwizzledSelectorForSelector(_Nonnull SEL selector);
*
* @param textSize.
*
- * @param textWeight. The type of WXTextWeight (Normal or Bold).
+ * @param textWeight.
*
* @param textStyle. The type of WXTextStyle (Normal or Italic).
*
@@ -211,7 +211,7 @@ extern _Nonnull SEL WXSwizzledSelectorForSelector(_Nonnull SEL selector);
* @return A font object according to the above params.
*
*/
-+ (UIFont *_Nonnull)fontWithSize:(CGFloat)size textWeight:(WXTextWeight)textWeight textStyle:(WXTextStyle)textStyle fontFamily:(NSString *_Nullable)fontFamily;
++ (UIFont *_Nonnull)fontWithSize:(CGFloat)size textWeight:(CGFloat)textWeight textStyle:(WXTextStyle)textStyle fontFamily:(NSString *_Nullable)fontFamily scaleFactor:(CGFloat)scaleFactor;
/**
* @abstract download remote font from specified url
@@ -221,24 +221,21 @@ extern _Nonnull SEL WXSwizzledSelectorForSelector(_Nonnull SEL selector);
+ (void)getIconfont:(NSURL * _Nonnull)fontURL completion:( void(^ _Nullable )(NSURL * _Nonnull url, NSError * _Nullable error)) completionBlock;
/**
- * @abstract Returns the scale of the main screen.
- *
+ * @abstract Returns the main screen's size when the device is in portrait mode,.
*/
-CGFloat WXScreenScale();
++ (CGSize)portraitScreenSize;
/**
- * @abstract Returns the metrics of the main screen.
- *
+ * @abstract Returns the default pixel scale factor
+ * @discussion If orientation is equal to landscape, the value is caculated as follows: WXScreenSize().height / WXDefaultScreenWidth, otherwise, WXScreenSize().width / WXDefaultScreenWidth.
*/
-CGSize WXScreenSize();
++ (CGFloat)defaultPixelScaleFactor;
/**
- * @abstract Returns the resize radio of the main screen.
- *
- * @discussion If orientation is equal to landscape, the value is caculated as follows: WXScreenSize().height / WXDefaultScreenWidth, otherwise, WXScreenSize().width / WXDefaultScreenWidth.
+ * @abstract Returns the scale of the main screen.
*
*/
-CGFloat WXScreenResizeRadio(void);
+CGFloat WXScreenScale();
/**
* @abstract Returns a Round float coordinates to the main screen pixel.
@@ -259,24 +256,6 @@ CGFloat WXFloorPixelValue(CGFloat value);
CGFloat WXCeilPixelValue(CGFloat value);
/**
- * @abstract Returns a resized pixel which is caculated according to the WXScreenResizeRadio.
- *
- */
-CGFloat WXPixelResize(CGFloat value);
-
-/**
- * @abstract Returns a resized frame which is caculated according to the WXScreenResizeRadio.
- *
- */
-CGRect WXPixelFrameResize(CGRect value);
-
-/**
- * @abstract Returns a resized point which is caculated according to the WXScreenResizeRadio.
- *
- */
-CGPoint WXPixelPointResize(CGPoint value);
-
-/**
* @abstract check whether the file is exist
*
*/
@@ -358,4 +337,22 @@ CGPoint WXPixelPointResize(CGPoint value);
*/
+ (NSString *_Nullable)timeToString:(NSDate *_Nullable)date;
+/**
+ * @abstract get the repeat subtring number of string.
+ *
+ */
++ (NSUInteger)getSubStringNumber:(NSString *_Nullable)string subString:(NSString *_Nullable)subString;
+
+/**
+ * @abstract Returns a resized pixel which is caculated according to the WXScreenResizeRadio.
+ *
+ */
+CGFloat WXPixelScale(CGFloat value, CGFloat scaleFactor);
+
+CGFloat WXScreenResizeRadio(void) DEPRECATED_MSG_ATTRIBUTE("Use [WXUtility defaultPixelScaleFactor] instead");
+CGFloat WXPixelResize(CGFloat value) DEPRECATED_MSG_ATTRIBUTE("Use WXPixelScale Instead");
+CGRect WXPixelFrameResize(CGRect value) DEPRECATED_MSG_ATTRIBUTE("Use WXPixelScale Instead");
+CGPoint WXPixelPointResize(CGPoint value) DEPRECATED_MSG_ATTRIBUTE("Use WXPixelScale Instead");
++ (UIFont * _Nullable )fontWithSize:(CGFloat)size textWeight:(CGFloat)textWeight textStyle:(WXTextStyle)textStyle fontFamily:(NSString * _Nullable)fontFamily DEPRECATED_MSG_ATTRIBUTE("Use +[WXUtility fontWithSize:textWeight:textStyle:fontFamily:scaleFactor:]");
+
@end
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b5123119/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 94f6046..119d7a9 100644
--- a/ios/sdk/WeexSDK/Sources/Utility/WXUtility.m
+++ b/ios/sdk/WeexSDK/Sources/Utility/WXUtility.m
@@ -93,9 +93,9 @@ CGFloat WXScreenScale(void)
return _scale;
}
-CGSize WXScreenSize(void)
+CGFloat WXPixelScale(CGFloat value, CGFloat scaleFactor)
{
- return [UIScreen mainScreen].bounds.size;
+ return WXCeilPixelValue(value * scaleFactor);
}
CGFloat WXRoundPixelValue(CGFloat value)
@@ -116,26 +116,6 @@ CGFloat WXFloorPixelValue(CGFloat value)
return floor(value * scale) / scale;
}
-CGFloat WXPixelResize(CGFloat value)
-{
- return WXCeilPixelValue(value * WXScreenResizeRadio());
-}
-
-CGRect WXPixelFrameResize(CGRect value)
-{
- CGRect new = CGRectMake(value.origin.x * WXScreenResizeRadio(),
- value.origin.y * WXScreenResizeRadio(),
- value.size.width * WXScreenResizeRadio(),
- value.size.height * WXScreenResizeRadio());
- return new;
-}
-
-CGPoint WXPixelPointResize(CGPoint value)
-{
- CGPoint new = CGPointMake(value.x * WXScreenResizeRadio(),
- value.y * WXScreenResizeRadio());
- return new;
-}
static BOOL WXNotStat;
@implementation WXUtility
@@ -168,8 +148,8 @@ static BOOL WXNotStat;
NSString *appVersion = [WXAppConfiguration appVersion] ? : @"";
NSString *appName = [WXAppConfiguration appName] ? : @"";
- CGFloat deviceWidth = [[UIScreen mainScreen] bounds].size.width;
- CGFloat deviceHeight = [[UIScreen mainScreen] bounds].size.height;
+ CGFloat deviceWidth = [self portraitScreenSize].width;
+ CGFloat deviceHeight = [self portraitScreenSize].height;
CGFloat scale = [[UIScreen mainScreen] scale];
NSMutableDictionary *data = [NSMutableDictionary dictionaryWithDictionary:@{
@@ -345,9 +325,14 @@ static BOOL WXNotStat;
return [NSError errorWithDomain:@"WeexErrorDomain" code:code userInfo:@{@"errMsg":message}];
}
-+ (UIFont *)fontWithSize:(CGFloat)size textWeight:(WXTextWeight)textWeight textStyle:(WXTextStyle)textStyle fontFamily:(NSString *)fontFamily
++ (UIFont *)fontWithSize:(CGFloat)size textWeight:(CGFloat)textWeight textStyle:(WXTextStyle)textStyle fontFamily:(NSString *)fontFamily
{
- CGFloat fontSize = (isnan(size) || size == 0) ? WX_TEXT_FONT_SIZE : size;
+ return [self fontWithSize:size textWeight:textWeight textStyle:textStyle fontFamily:fontFamily scaleFactor:[self defaultPixelScaleFactor]];
+}
+
++ (UIFont *)fontWithSize:(CGFloat)size textWeight:(CGFloat)textWeight textStyle:(WXTextStyle)textStyle fontFamily:(NSString *)fontFamily scaleFactor:(CGFloat)scaleFactor
+{
+ CGFloat fontSize = (isnan(size) || size == 0) ? 32 * scaleFactor : size;
UIFont *font = nil;
WXThreadSafeMutableDictionary *fontFace = [[WXRuleManager sharedInstance] getRule:@"fontFace"];
@@ -373,17 +358,17 @@ static BOOL WXNotStat;
font = [UIFont fontWithName:fontFamily size:fontSize];
if (!font) {
WXLogWarning(@"Unknown fontFamily:%@", fontFamily);
- font = [UIFont systemFontOfSize:fontSize];
+ font = [UIFont systemFontOfSize:fontSize weight:textWeight];
}
} else {
- font = [UIFont systemFontOfSize:fontSize];
+ font = [UIFont systemFontOfSize:fontSize weight:textWeight];
}
}
-
UIFontDescriptor *fontD = font.fontDescriptor;
UIFontDescriptorSymbolicTraits traits = 0;
+
traits = (textStyle == WXTextStyleItalic) ? (traits | UIFontDescriptorTraitItalic) : traits;
- traits = (textWeight == WXTextWeightBold) ? (traits | UIFontDescriptorTraitBold) : traits;
+ traits = (fabs(textWeight-(WX_SYS_VERSION_LESS_THAN(@"8.2")?0.4:UIFontWeightBold)) <= 1e-6) ? (traits | UIFontDescriptorTraitBold) : traits;
if (traits != 0) {
fontD = [fontD fontDescriptorWithSymbolicTraits:traits];
UIFont *tempFont = [UIFont fontWithDescriptor:fontD size:0];
@@ -500,31 +485,31 @@ static BOOL WXNotStat;
return model;
}
-CGFloat WXScreenResizeRadio(void)
++ (CGSize)portraitScreenSize
{
- return [WXUtility screenResizeScale];
+ static CGSize portraitScreenSize;
+ static dispatch_once_t onceToken;
+ dispatch_once(&onceToken, ^{
+ CGSize screenSize = [UIScreen mainScreen].bounds.size;
+ portraitScreenSize = CGSizeMake(MIN(screenSize.width, screenSize.height),
+ MAX(screenSize.width, screenSize.height));
+ });
+
+ return portraitScreenSize;
}
-+ (CGFloat)screenResizeScale
++ (CGFloat)defaultPixelScaleFactor
{
- static CGFloat resizeScale;
+ static CGFloat defaultScaleFactor;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
- CGSize size = WXScreenSize();
- CGFloat deviceWidth;
- if (size.width > size.height) {
- // Landscape
- deviceWidth = size.height;
- } else {
- deviceWidth = size.width;
- }
-
- resizeScale = deviceWidth / WXDefaultScreenWidth;
+ defaultScaleFactor = [self portraitScreenSize].width / WXDefaultScreenWidth;
});
- return resizeScale;
+ return defaultScaleFactor;
}
+
#pragma mark - get deviceID
+ (NSString *)getDeviceID {
NSMutableDictionary *usernamepasswordKVPairs = (NSMutableDictionary *)[self load:KEY_USERNAME_PASSWORD];
@@ -671,4 +656,48 @@ CGFloat WXScreenResizeRadio(void)
return str;
}
++ (NSUInteger)getSubStringNumber:(NSString *_Nullable)string subString:(NSString *_Nullable)subString
+{
+ if([string length] ==0) {
+ return 0;
+ }
+ if([subString length] ==0) {
+ return 0;
+ }
+ NSError *error = NULL;
+ NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:subString options:NSRegularExpressionCaseInsensitive error:&error];
+ NSUInteger numberOfMatches = [regex numberOfMatchesInString:string options:0 range:NSMakeRange(0, [string length])];
+ return numberOfMatches;
+
+}
+
@end
+
+
+//Deprecated
+CGFloat WXScreenResizeRadio(void)
+{
+ return [WXUtility defaultPixelScaleFactor];
+}
+
+CGFloat WXPixelResize(CGFloat value)
+{
+ return WXCeilPixelValue(value * WXScreenResizeRadio());
+}
+
+CGRect WXPixelFrameResize(CGRect value)
+{
+ CGRect new = CGRectMake(value.origin.x * WXScreenResizeRadio(),
+ value.origin.y * WXScreenResizeRadio(),
+ value.size.width * WXScreenResizeRadio(),
+ value.size.height * WXScreenResizeRadio());
+ return new;
+}
+
+CGPoint WXPixelPointResize(CGPoint value)
+{
+ CGPoint new = CGPointMake(value.x * WXScreenResizeRadio(),
+ value.y * WXScreenResizeRadio());
+ return new;
+}
+
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b5123119/ios/sdk/WeexSDK/Sources/View/WXComponent+PseudoClassManagement.h
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/View/WXComponent+PseudoClassManagement.h b/ios/sdk/WeexSDK/Sources/View/WXComponent+PseudoClassManagement.h
new file mode 100644
index 0000000..842978a
--- /dev/null
+++ b/ios/sdk/WeexSDK/Sources/View/WXComponent+PseudoClassManagement.h
@@ -0,0 +1,66 @@
+/**
+ * Created by Weex.
+ * Copyright (c) 2016, Alibaba, Inc. All rights reserved.
+ *
+ * This source code is licensed under the Apache Licence 2.0.
+ * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree.
+ */
+
+#import <WeexSDK/WeexSDK.h>
+
+@interface WXComponent (PseudoClassManagement)
+
+/**
+ * @abstract filter common styles and pseudoClassStyles.
+ *
+ */
+-(NSMutableDictionary *)parseStyles:(NSDictionary *)styles;
+
+/**
+ * @abstract filter common styles and pseudoClassStyles.
+ *
+ */
+-(NSString *)getPseudoKey:(NSString *)key;
+
+/**
+ * @abstract get pseudo class styles through key.
+ *
+ * @param key the key to search pseudo class
+ *
+ * @return pseudo class.
+ */
+-(NSMutableDictionary *)getPseudoClassStyles:(NSString *)key;
+
+/**
+ * @abstract get pseudo class styles through keys.
+ *
+ * @param keys the keys to search pseudo class
+ *
+ * @return pseudo class.
+ */
+-(NSMutableDictionary *)getPseudoClassStylesByKeys:(NSArray *)keys;
+
+///--------------------------------------
+/// @name Updating PseudoClass
+///--------------------------------------
+
+/**
+ * @abstract Called when component's style are updated
+ *
+ * @param styles The updated style dictionary
+ * @discussion It can be overrided to handle specific style updating. The method is called on the main thread.
+ **/
+- (void)updatePseudoClassStyles:(NSDictionary *)pseudoClassStyles;
+
+///--------------------------------------
+/// @name recovery styles
+///--------------------------------------
+
+/**
+ * @abstract Called when component recovery styles
+ *
+ * @discussion It can be overrided to handle specific style recovery. The method is called on the main thread.
+ **/
+- (void)recoveryPseudoStyles:(NSDictionary *)styles;
+
+@end
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b5123119/ios/sdk/WeexSDK/Sources/View/WXComponent+PseudoClassManagement.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/View/WXComponent+PseudoClassManagement.m b/ios/sdk/WeexSDK/Sources/View/WXComponent+PseudoClassManagement.m
new file mode 100644
index 0000000..0d8d9e6
--- /dev/null
+++ b/ios/sdk/WeexSDK/Sources/View/WXComponent+PseudoClassManagement.m
@@ -0,0 +1,144 @@
+/**
+ * Created by Weex.
+ * Copyright (c) 2016, Alibaba, Inc. All rights reserved.
+ *
+ * This source code is licensed under the Apache Licence 2.0.
+ * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree.
+ */
+
+#import "WXComponent+PseudoClassManagement.h"
+#import "WXComponent_internal.h"
+#import "WXAssert.h"
+#import "WXComponentManager.h"
+#import "WXSDKInstance_private.h"
+#import "WXUtility.h"
+
+@implementation WXComponent (PseudoClassManagement)
+
+-(NSMutableDictionary *)parseStyles:(NSDictionary *)styles
+{
+ NSMutableDictionary *newStyles = [NSMutableDictionary new];
+ _pseudoClassStyles = [NSMutableDictionary new];
+ if (styles && [styles count] > 0 ) {
+ for (NSString *key in styles){
+ if([key rangeOfString:@":"].location != NSNotFound){
+ if ([key rangeOfString:@"active"].location != NSNotFound) { //all active listen
+ _isListenPseudoTouch = YES;
+ }
+ [_pseudoClassStyles setObject:styles[key] forKey:key];
+ }else {
+ [newStyles setObject:styles[key] forKey:key];
+ }
+ }
+ }
+ return newStyles;
+}
+
+- (void)updatePseudoClassStyles:(NSDictionary *)pseudoClassStyles
+{
+ WXAssertMainThread();
+ NSMutableDictionary *styles = [NSMutableDictionary new];
+ for (NSString *k in pseudoClassStyles) {
+ [styles setObject:pseudoClassStyles[k] forKey:[self getPseudoKey:k]];
+ }
+ if ([styles count]>0) {
+ __weak typeof(self) weakSelf = self;
+ WXPerformBlockOnComponentThread(^{
+ WXComponentManager *manager = weakSelf.weexInstance.componentManager;
+ if (!manager.isValid) {
+ return;
+ }
+ [manager updatePseudoClassStyles:styles forComponent:self.ref];
+ [manager startComponentTasks];
+ });
+ }
+
+ if (styles && [styles count] > 0) {
+ if(!_updatedPseudoClassStyles) {
+ _updatedPseudoClassStyles = [NSMutableDictionary new];
+ }
+ for (NSString *key in styles) {
+ [_updatedPseudoClassStyles setObject:styles[key] forKey:key];
+ }
+ }
+}
+
+-(NSString *)getPseudoKey:(NSString *)key
+{
+ if ([key rangeOfString:@":"].location == NSNotFound) {
+ return key;
+ }
+ NSRange range = [key rangeOfString:@":"];
+ NSString *subKey = [key substringToIndex:range.location];
+ return subKey;
+}
+
+-(NSMutableDictionary *)getPseudoClassStyles:(NSString *)key
+{
+ NSMutableDictionary *styles = [NSMutableDictionary new];
+ [styles addEntriesFromDictionary:[self getPseudoClassStyles:key level:1]];
+ [styles addEntriesFromDictionary:[self getPseudoClassStyles:key level:2]];
+ return styles;
+}
+
+-(NSMutableDictionary *)getPseudoClassStyles:(NSString *)key level:(NSInteger )level
+{
+ NSMutableDictionary *styles = [NSMutableDictionary new];
+ if (_pseudoClassStyles && [_pseudoClassStyles count] > 0 ) {
+ for (NSString *k in _pseudoClassStyles){
+ if ([k rangeOfString:key].location != NSNotFound && [WXUtility getSubStringNumber:k subString:@":"] == level) {
+ [styles setObject:_pseudoClassStyles[k] forKey:[self getPseudoKey:k]];
+ }
+ }
+ }
+ return styles;
+}
+
+-(NSMutableDictionary *)getPseudoClassStylesByKeys:(NSArray *)keys
+{
+ NSMutableDictionary *styles = [NSMutableDictionary new];
+ if(keys && [keys count]>0) {
+ if (_pseudoClassStyles && [_pseudoClassStyles count] > 0 ) {
+ for (NSString *k in _pseudoClassStyles){
+ if([WXUtility getSubStringNumber:k subString:@":"] == [keys count]){
+ BOOL isContain = YES;
+ for(NSString *pKey in keys){
+ if ([k rangeOfString:pKey].location == NSNotFound) {
+ isContain = NO;
+ break;
+ }
+ }
+ if (isContain) {
+ [styles setObject:_pseudoClassStyles[k] forKey:[self getPseudoKey:k]];
+ }
+ }
+ }
+ }
+ }
+
+ return styles;
+}
+
+- (void)recoveryPseudoStyles:(NSDictionary *)styles
+{
+ WXAssertMainThread();
+ __weak typeof(self) weakSelf = self;
+ NSMutableDictionary *resetStyles = [styles mutableCopy];
+ if(_updatedPseudoClassStyles && [_updatedPseudoClassStyles count]>0){
+ for (NSString *key in _updatedPseudoClassStyles) {
+ if (![styles objectForKey:key] && [key length]>0) {
+ [resetStyles setObject:@"" forKey:key];
+ }
+ }
+ }
+ WXPerformBlockOnComponentThread(^{
+ WXComponentManager *manager = weakSelf.weexInstance.componentManager;
+ if (!manager.isValid) {
+ return;
+ }
+ [manager updatePseudoClassStyles:resetStyles forComponent:self.ref];
+ [manager startComponentTasks];
+ });
+}
+
+@end
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b5123119/ios/sdk/WeexSDK/Sources/View/WXComponent+ViewManagement.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/View/WXComponent+ViewManagement.m b/ios/sdk/WeexSDK/Sources/View/WXComponent+ViewManagement.m
index 5cc5094..16f8ddc 100644
--- a/ios/sdk/WeexSDK/Sources/View/WXComponent+ViewManagement.m
+++ b/ios/sdk/WeexSDK/Sources/View/WXComponent+ViewManagement.m
@@ -8,6 +8,7 @@
#import "WXComponent+ViewManagement.h"
#import "WXComponent_internal.h"
+#import "WXComponent+GradientColor.h"
#import "WXAssert.h"
#import "WXView.h"
#import "WXSDKInstance_private.h"
@@ -93,6 +94,7 @@
- (void)_initViewPropertyWithStyles:(NSDictionary *)styles
{
_backgroundColor = styles[@"backgroundColor"] ? [WXConvert UIColor:styles[@"backgroundColor"]] : [UIColor clearColor];
+ _backgroundImage = styles[@"backgroundImage"] ? [[WXConvert NSString:styles[@"backgroundImage"]]stringByReplacingOccurrencesOfString:@" " withString:@""]: nil;
_opacity = styles[@"opacity"] ? [WXConvert CGFloat:styles[@"opacity"]] : 1.0;
_clipToBounds = styles[@"overflow"] ? [WXConvert WXClipType:styles[@"overflow"]] : NO;
_visibility = styles[@"visibility"] ? [WXConvert WXVisibility:styles[@"visibility"]] : WXVisibilityShow;
@@ -108,6 +110,15 @@
_layer.backgroundColor = _backgroundColor.CGColor;
[self setNeedsDisplay];
}
+
+ if (styles[@"backgroundImage"]) {
+ _backgroundImage = styles[@"backgroundImage"] ? [[WXConvert NSString:styles[@"backgroundImage"]]stringByReplacingOccurrencesOfString:@" " withString:@""]: nil;
+
+ if (_backgroundImage) {
+ [self setGradientLayer];
+ }
+ }
+
if (styles[@"opacity"]) {
_opacity = [WXConvert CGFloat:styles[@"opacity"]];
_layer.opacity = _opacity;
@@ -156,7 +167,7 @@
if (styles[@"transform"]) {
if (!CGRectEqualToRect(self.calculatedFrame, CGRectZero)) {
_transform = [WXConvert NSString:styles[@"transform"]];
- _layer.transform = [[WXTransform new] getTransform:_transform withView:_view withOrigin:_transformOrigin];
+ _layer.transform = [[[WXTransform alloc] initWithInstance:self.weexInstance] getTransform:_transform withView:_view withOrigin:_transformOrigin];
[_layer setNeedsDisplay];
}
}
@@ -166,6 +177,7 @@
{
if (styles && [styles containsObject:@"backgroundColor"]) {
_backgroundColor = [UIColor clearColor];
+ [self setNeedsDisplay];
}
}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b5123119/ios/sdk/WeexSDK/Sources/View/WXErrorView.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/View/WXErrorView.m b/ios/sdk/WeexSDK/Sources/View/WXErrorView.m
index 9be62fb..f447656 100644
--- a/ios/sdk/WeexSDK/Sources/View/WXErrorView.m
+++ b/ios/sdk/WeexSDK/Sources/View/WXErrorView.m
@@ -16,7 +16,8 @@
if (self) {
UIImageView *imageView = [[UIImageView alloc]initWithFrame:self.bounds];
- NSString *file = [[NSBundle mainBundle] pathForResource:@"wx_load_error@3x" ofType:@"png"];
+ NSBundle *bundle = [NSBundle bundleForClass:self.class];
+ NSString *file = [bundle pathForResource:@"wx_load_error@3x" ofType:@"png"];
imageView.image = [UIImage imageWithContentsOfFile:file];
[self addSubview:imageView];
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b5123119/ios/sdk/WeexSDK/Sources/View/WXView.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/View/WXView.m b/ios/sdk/WeexSDK/Sources/View/WXView.m
index 94870cf..6185427 100644
--- a/ios/sdk/WeexSDK/Sources/View/WXView.m
+++ b/ios/sdk/WeexSDK/Sources/View/WXView.m
@@ -22,7 +22,7 @@
/**
* Capturing touches on a subview outside the frame of its superview if it does not clips to bounds.
*/
- if (self.hidden) {
+ if (self.hidden || !self.userInteractionEnabled) {
return nil;
}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b5123119/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..c4823d6
--- /dev/null
+++ b/ios/sdk/WeexSDK/Sources/WebSocket/SRWebSocket+Weex.h
@@ -0,0 +1,18 @@
+/**
+ * Created by Weex.
+ * Copyright (c) 2016, Alibaba, Inc. All rights reserved.
+ *
+ * This source code is licensed under the Apache Licence 2.0.
+ * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree.
+ */
+
+#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/b5123119/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..f6cdfd1
--- /dev/null
+++ b/ios/sdk/WeexSDK/Sources/WebSocket/SRWebSocket+Weex.m
@@ -0,0 +1,36 @@
+/**
+ * Created by Weex.
+ * Copyright (c) 2016, Alibaba, Inc. All rights reserved.
+ *
+ * This source code is licensed under the Apache Licence 2.0.
+ * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree.
+ */
+
+#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/b5123119/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..5ff8009
--- /dev/null
+++ b/ios/sdk/WeexSDK/Sources/WebSocket/WXWebSocketDefaultImpl.h
@@ -0,0 +1,14 @@
+/**
+ * Created by Weex.
+ * Copyright (c) 2016, Alibaba, Inc. All rights reserved.
+ *
+ * This source code is licensed under the Apache Licence 2.0.
+ * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree.
+ */
+
+#import <Foundation/Foundation.h>
+#import "WXWebSocketHandler.h"
+
+@interface WXWebSocketDefaultImpl : NSObject<WXWebSocketHandler>
+
+@end
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b5123119/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..12bb4ff
--- /dev/null
+++ b/ios/sdk/WeexSDK/Sources/WebSocket/WXWebSocketDefaultImpl.m
@@ -0,0 +1,110 @@
+/**
+ * Created by Weex.
+ * Copyright (c) 2016, Alibaba, Inc. All rights reserved.
+ *
+ * This source code is licensed under the Apache Licence 2.0.
+ * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree.
+ */
+
+#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:(NSString *)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/b5123119/ios/sdk/WeexSDK/Sources/WebSocket/WXWebSocketHandler.h
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/WebSocket/WXWebSocketHandler.h b/ios/sdk/WeexSDK/Sources/WebSocket/WXWebSocketHandler.h
new file mode 100644
index 0000000..3346609
--- /dev/null
+++ b/ios/sdk/WeexSDK/Sources/WebSocket/WXWebSocketHandler.h
@@ -0,0 +1,26 @@
+/**
+ * Created by Weex.
+ * Copyright (c) 2016, Alibaba, Inc. All rights reserved.
+ *
+ * This source code is licensed under the Apache Licence 2.0.
+ * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree.
+ */
+
+#import <Foundation/Foundation.h>
+#import "WXModuleProtocol.h"
+
+@protocol WXWebSocketDelegate<NSObject>
+- (void)didOpen;
+- (void)didFailWithError:(NSError *)error;
+- (void)didReceiveMessage:(id)message;
+- (void)didCloseWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean;
+@end
+
+@protocol WXWebSocketHandler<NSObject>
+
+- (void)open:(NSString *)url protocol:(NSString *)protocol identifier:(NSString *)identifier withDelegate:(id<WXWebSocketDelegate>)delegate;
+- (void)send:(NSString *)identifier data:(NSString *)data;
+- (void)close:(NSString *)identifier;
+- (void)close:(NSString *)identifier code:(NSInteger)code reason:(NSString *)reason;
+- (void)clear:(NSString *)identifier;
+@end
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b5123119/ios/sdk/WeexSDK/Sources/WeexSDK.h
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/WeexSDK.h b/ios/sdk/WeexSDK/Sources/WeexSDK.h
index d552031..33eb2bb 100644
--- a/ios/sdk/WeexSDK/Sources/WeexSDK.h
+++ b/ios/sdk/WeexSDK/Sources/WeexSDK.h
@@ -18,6 +18,7 @@
#import "WXSDKError.h"
#import "WXSDKEngine.h"
#import "WXRootViewController.h"
+#import "WXResourceRequest.h"
#import "WXNetworkProtocol.h"
#import "WXNavigationProtocol.h"
#import "WXMonitor.h"
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b5123119/ios/sdk/WeexSDKTests/TestSupportUtils.h
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDKTests/TestSupportUtils.h b/ios/sdk/WeexSDKTests/TestSupportUtils.h
index ead0e6c..748d8e9 100644
--- a/ios/sdk/WeexSDKTests/TestSupportUtils.h
+++ b/ios/sdk/WeexSDKTests/TestSupportUtils.h
@@ -7,6 +7,11 @@
*/
#import <Foundation/Foundation.h>
+#import <UIKit/UIKit.h>
+
+extern bool WXTransform3DApproximateToTransform(CATransform3D a,CATransform3D b);
+
+extern bool WXRectApproximateToRect(CGRect a,CGRect b);
@interface TestSupportUtils : NSObject
/**
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b5123119/ios/sdk/WeexSDKTests/TestSupportUtils.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDKTests/TestSupportUtils.m b/ios/sdk/WeexSDKTests/TestSupportUtils.m
index d244045..3c315b9 100644
--- a/ios/sdk/WeexSDKTests/TestSupportUtils.m
+++ b/ios/sdk/WeexSDKTests/TestSupportUtils.m
@@ -8,9 +8,43 @@
#import "TestSupportUtils.h"
-@implementation TestSupportUtils
-static dispatch_once_t onceToken;
+bool WXIsDoubleApproximate(double x, double y) {
+ return fabs(x - y) < 0.001;
+}
+
+bool WXTransform3DApproximateToTransform(CATransform3D a,CATransform3D b)
+{
+ return
+ WXIsDoubleApproximate(a.m11, b.m11) &&
+ WXIsDoubleApproximate(a.m12, b.m12) &&
+ WXIsDoubleApproximate(a.m13, b.m13) &&
+ WXIsDoubleApproximate(a.m14, b.m14) &&
+ WXIsDoubleApproximate(a.m21, b.m21) &&
+ WXIsDoubleApproximate(a.m22, b.m22) &&
+ WXIsDoubleApproximate(a.m23, b.m23) &&
+ WXIsDoubleApproximate(a.m24, b.m24) &&
+ WXIsDoubleApproximate(a.m31, b.m31) &&
+ WXIsDoubleApproximate(a.m32, b.m32) &&
+ WXIsDoubleApproximate(a.m33, b.m33) &&
+ WXIsDoubleApproximate(a.m34, b.m34) &&
+ WXIsDoubleApproximate(a.m41, b.m41) &&
+ WXIsDoubleApproximate(a.m42, b.m42) &&
+ WXIsDoubleApproximate(a.m43, b.m43) &&
+ WXIsDoubleApproximate(a.m44, b.m44);
+}
+
+bool WXRectApproximateToRect(CGRect a,CGRect b)
+{
+ return
+ WXIsDoubleApproximate(a.origin.x, b.origin.x) &&
+ WXIsDoubleApproximate(a.origin.y, b.origin.y) &&
+ WXIsDoubleApproximate(a.size.width, b.size.width) &&
+ WXIsDoubleApproximate(a.size.height, b.size.height);
+}
+
+
+@implementation TestSupportUtils
+(void)waitSecs:(NSTimeInterval)secs{
NSDate *timeoutDate = [NSDate dateWithTimeIntervalSinceNow:secs];
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b5123119/ios/sdk/WeexSDKTests/WXAnimationModuleTests.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDKTests/WXAnimationModuleTests.m b/ios/sdk/WeexSDKTests/WXAnimationModuleTests.m
index 3f7dd4c..95cdf0f 100644
--- a/ios/sdk/WeexSDKTests/WXAnimationModuleTests.m
+++ b/ios/sdk/WeexSDKTests/WXAnimationModuleTests.m
@@ -34,22 +34,14 @@
}
-- (void)testPerformanceExample {
- // This is an example of a performance test case.
- [self measureBlock:^{
- // Put the code you want to measure the time of here.
- }];
-}
-
- (void)testAnimationRotate {
WXComponent *component = [self component];
WXAnimationModule *object = [[WXAnimationModule alloc]init];
[object animation:component args:@{@"duration":@500, @"timingFunction":@"ease-in-out", @"styles":@{@"transform":@"rotate(90deg)"}} callback:nil];
[TestSupportUtils waitSecs:1];
- CGFloat angle = [(NSNumber *)[component.layer valueForKeyPath:@"transform.rotation.z"] floatValue];
-
- XCTAssert(fabs(angle - M_PI_2) < 0.00001);
+ CATransform3D transformToVerify = CATransform3DMakeAffineTransform(CGAffineTransformRotate(CGAffineTransformIdentity, M_PI / 2));
+ XCTAssert(WXTransform3DApproximateToTransform(component.layer.transform, transformToVerify));
}
- (void)testAnimationTranslate {
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b5123119/ios/sdk/WeexSDKTests/WXBridgeMethodTests.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDKTests/WXBridgeMethodTests.m b/ios/sdk/WeexSDKTests/WXBridgeMethodTests.m
index 26ecffe..d9d9eba 100644
--- a/ios/sdk/WeexSDKTests/WXBridgeMethodTests.m
+++ b/ios/sdk/WeexSDKTests/WXBridgeMethodTests.m
@@ -7,7 +7,7 @@
*/
#import <XCTest/XCTest.h>
-#import "WXBridgeMethod.h"
+#import "WXCallJSMethod.h"
#import "WXSDKInstance.h"
@interface WXBridgeMethodTests : XCTestCase
@@ -29,36 +29,29 @@
- (void)testExample {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
+ WXSDKInstance *instance = [[WXSDKInstance alloc] init];
- NSDictionary *data = @{@"module":@"dom", @"method":@"test", @"args":@[@"1", @"2", @"3"]};
- WXBridgeMethod *method = [[WXBridgeMethod alloc] initWithInstance:@"0" data:[NSMutableDictionary dictionaryWithDictionary:data]];
+ WXCallJSMethod *method = [[WXCallJSMethod alloc] initWithModuleName:@"dom" methodName:@"test" arguments:@[@"1", @"2", @"3"] instance:instance];
- NSDictionary *desc = [method dataDesc];
- XCTAssertEqualObjects(desc[@"module"], @"dom");
- XCTAssertEqualObjects(desc[@"method"], @"test");
+ NSDictionary *task = [method callJSTask];
+ XCTAssertEqualObjects(task[@"module"], @"dom");
+ XCTAssertEqualObjects(task[@"method"], @"test");
- NSArray *args = desc[@"args"];
+ NSArray *args = task[@"args"];
XCTAssertTrue(args.count == 3);
XCTAssertEqualObjects(args[0], @"1");
XCTAssertEqualObjects(args[1], @"2");
XCTAssertEqualObjects(args[2], @"3");
- method = [[WXBridgeMethod alloc] initWithInstance:@"1" data:[NSMutableDictionary dictionary]];
+ WXCallJSMethod *method2 = [[WXCallJSMethod alloc] initWithModuleName:nil methodName:nil arguments:nil instance:[[WXSDKInstance alloc] init]];
- desc = [method dataDesc];
- XCTAssertEqualObjects(desc[@"module"], @"");
- XCTAssertEqualObjects(desc[@"method"], @"");
+ task = [method2 callJSTask];
+ XCTAssertEqualObjects(task[@"module"], @"");
+ XCTAssertEqualObjects(task[@"method"], @"");
- args = desc[@"args"];
+ args = task[@"args"];
XCTAssertNotNil(args);
XCTAssertTrue(args.count == 0);
}
-- (void)testPerformanceExample {
- // This is an example of a performance test case.
- [self measureBlock:^{
- // Put the code you want to measure the time of here.
- }];
-}
-
@end
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b5123119/ios/sdk/WeexSDKTests/WXConvertTests.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDKTests/WXConvertTests.m b/ios/sdk/WeexSDKTests/WXConvertTests.m
index 7c960d6..3e89911 100644
--- a/ios/sdk/WeexSDKTests/WXConvertTests.m
+++ b/ios/sdk/WeexSDKTests/WXConvertTests.m
@@ -63,11 +63,4 @@
}
-- (void)testPerformanceExample {
- // This is an example of a performance test case.
- [self measureBlock:^{
- // Put the code you want to measure the time of here.
- }];
-}
-
@end
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b5123119/ios/sdk/WeexSDKTests/WXInstanceWrapTests.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDKTests/WXInstanceWrapTests.m b/ios/sdk/WeexSDKTests/WXInstanceWrapTests.m
index 9e004d8..57b6372 100644
--- a/ios/sdk/WeexSDKTests/WXInstanceWrapTests.m
+++ b/ios/sdk/WeexSDKTests/WXInstanceWrapTests.m
@@ -48,13 +48,6 @@
// Use XCTAssert and related functions to verify your tests produce the correct results.
}
-- (void)testPerformanceExample {
- // This is an example of a performance test case.
- [self measureBlock:^{
- // Put the code you want to measure the time of here.
- }];
-}
-
- (void)testErrorCodeInfo {
self.exp = [self expectationWithDescription:@" Error!"];
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b5123119/ios/sdk/WeexSDKTests/WXNetworkTests.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDKTests/WXNetworkTests.m b/ios/sdk/WeexSDKTests/WXNetworkTests.m
deleted file mode 100644
index eda53d8..0000000
--- a/ios/sdk/WeexSDKTests/WXNetworkTests.m
+++ /dev/null
@@ -1,116 +0,0 @@
-/**
- * Created by Weex.
- * Copyright (c) 2016, Alibaba, Inc. All rights reserved.
- *
- * This source code is licensed under the Apache Licence 2.0.
- * For the full copyright and license information,please view the LICENSE file in the root directory of this source tree.
- */
-
-#import <XCTest/XCTest.h>
-#import "WXNetworkDefaultImpl.h"
-#import "WXUtility.h"
-
-@interface WXNetworkTests : XCTestCase
-
-@property (nonatomic, strong) WXNetworkDefaultImpl *networkHandler;
-
-@end
-
-@implementation WXNetworkTests
-
-- (void)setUp {
- [super setUp];
- // Put setup code here. This method is called before the invocation of each test method in the class.
-
- self.networkHandler = [[WXNetworkDefaultImpl alloc] init];
-}
-
-- (void)tearDown {
- // Put teardown code here. This method is called after the invocation of each test method in the class.
- [super tearDown];
-}
-
-- (void)testExample {
- // This is an example of a functional test case.
- // Use XCTAssert and related functions to verify your tests produce the correct results.
-}
-
-- (void)testPerformanceExample {
- // This is an example of a performance test case.
- [self measureBlock:^{
- // Put the code you want to measure the time of here.
- }];
-}
-
-- (void) testSendRequestSuccess {
-
- XCTestExpectation *exp = [self expectationWithDescription:@"SendRequestSuccess Unit Test Error!"];
-
- NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://www.taobao.com"]];
-
- __block NSURLResponse *urlResponse;
- __block NSError *respError;
- __block NSData *respData;
-
- [_networkHandler sendRequest:request
- withSendingData:^(int64_t bytesSent, int64_t totalBytes) {}
- withResponse:^(NSURLResponse *response) {
- urlResponse = response;
- }
- withReceiveData:^(NSData *data) {}
- withCompeletion:^(NSData *totalData, NSError *error) {
-
- if (!error && [urlResponse isKindOfClass:[NSHTTPURLResponse class]] && ((NSHTTPURLResponse *)urlResponse).statusCode != 200) {
- error = [NSError errorWithDomain:WX_ERROR_DOMAIN
- code:((NSHTTPURLResponse *)urlResponse).statusCode
- userInfo:@{@"message":@"status code error."}];
- }
-
- respError = error;
- respData = totalData;
-
- [exp fulfill];
- }];
-
- [self waitForExpectationsWithTimeout:10 handler:^(NSError * _Nullable error) {
- XCTAssertNil(respError);
- XCTAssertNotNil(respData);
- }];
-}
-
-/*- (void) testSendRequestFailure {
-
- XCTestExpectation *exp = [self expectationWithDescription:@"SendRequestFailure Unit Test Error!"];
-
- NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://www.123.abc"]];
-
- __block NSURLResponse *urlResponse;
- __block NSError *respError;
- __block NSData *respData;
-
- [_networkHandler sendRequest:request
- withSendingData:^(int64_t bytesSent, int64_t totalBytes) {}
- withResponse:^(NSURLResponse *response) {
- urlResponse = response;
- }
- withReceiveData:^(NSData *data) {}
- withCompeletion:^(NSData *totalData, NSError *error) {
-
- if (!error && [urlResponse isKindOfClass:[NSHTTPURLResponse class]] && ((NSHTTPURLResponse *)urlResponse).statusCode != 200) {
- error = [NSError errorWithDomain:WX_ERROR_DOMAIN
- code:((NSHTTPURLResponse *)urlResponse).statusCode
- userInfo:@{@"message":@"status code error."}];
- }
-
- respError = error;
- respData = totalData;
- [exp fulfill];
- }];
-
- [self waitForExpectationsWithTimeout:10 handler:^(NSError * _Nullable error) {
- XCTAssertNotNil(respError);
- XCTAssertNil(respData);
- }];
-}*/
-
-@end
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b5123119/ios/sdk/WeexSDKTests/WXRootViewTests.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDKTests/WXRootViewTests.m b/ios/sdk/WeexSDKTests/WXRootViewTests.m
index b8cac0f..19c0e0a 100644
--- a/ios/sdk/WeexSDKTests/WXRootViewTests.m
+++ b/ios/sdk/WeexSDKTests/WXRootViewTests.m
@@ -41,7 +41,7 @@
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
NSString *path = [bundle pathForResource:@"main" ofType:@"js"];
NSString *script = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
- [WXSDKEngine initSDKEnviroment:script];
+ [WXSDKEngine initSDKEnvironment:script];
[WXLog setLogLevel:WXLogLevelDebug];
NSString *jsPath = [bundle pathForResource:@"testRootView" ofType:@"js"];
@@ -53,8 +53,8 @@
[instance1 renderView:jsScript options:nil data:nil];
XCTestExpectation *expectation1 = [self expectationWithDescription:@"instance 1"];
instance1.renderFinish = ^(UIView *view){
- XCTAssert(CGRectEqualToRect(view.frame, instanceFrame));
- XCTAssert(CGRectEqualToRect(view.subviews[0].frame, CGRectMake(0, 0, instanceFrame.size.width, instanceFrame.size.height)));
+ XCTAssert(WXRectApproximateToRect(view.frame, instanceFrame));
+ XCTAssert(WXRectApproximateToRect(view.subviews[0].frame, CGRectMake(0, 0, instanceFrame.size.width, instanceFrame.size.height)));
[expectation1 fulfill];
};
@@ -65,8 +65,8 @@
[instance2 renderView:jsScript options:nil data:templateRootFrameData];
XCTestExpectation *expectation2 = [self expectationWithDescription:@"instance 2"];
instance2.renderFinish = ^(UIView *view){
- XCTAssert(CGRectEqualToRect(view.frame, instanceFrame));
- XCTAssert(CGRectEqualToRect(view.subviews[0].frame,
+ XCTAssert(WXRectApproximateToRect(view.frame, instanceFrame));
+ XCTAssert(WXRectApproximateToRect(view.subviews[0].frame,
CGRectMake(
WXPixelResize(templateRootFrame.origin.x),
WXPixelResize(templateRootFrame.origin.y),
@@ -83,11 +83,11 @@
XCTestExpectation *expectation3 = [self expectationWithDescription:@"instance 3"];
XCTestExpectation *expectation31 = [self expectationWithDescription:@"instance 3 onLayoutChange"];
instance3.renderFinish = ^(UIView *view){
- XCTAssert(CGRectEqualToRect(view.frame,
+ XCTAssert(WXRectApproximateToRect(view.frame,
CGRectMake(0,0,
WXPixelResize(templateRootFrame.size.width),
WXPixelResize(templateRootFrame.size.height))));
- XCTAssert(CGRectEqualToRect(view.subviews[0].frame,
+ XCTAssert(WXRectApproximateToRect(view.subviews[0].frame,
CGRectMake(
WXPixelResize(templateRootFrame.origin.x),
WXPixelResize(templateRootFrame.origin.y),
@@ -101,7 +101,7 @@
[instance3 refreshInstance:changedFrameData];
instance3.onLayoutChange = ^(UIView *view) {
- XCTAssert(CGRectEqualToRect(view.frame,
+ XCTAssert(WXRectApproximateToRect(view.frame,
CGRectMake(0,0,
WXPixelResize(templateRootFrame.size.width),
WXPixelResize(400))));
@@ -115,14 +115,14 @@
[instance4 renderView:jsScript options:nil data:nil];
XCTestExpectation *expectation4 = [self expectationWithDescription:@"instance 4"];
instance4.renderFinish = ^(UIView *view){
- XCTAssert(CGRectEqualToRect(view.frame,
+ XCTAssert(WXRectApproximateToRect(view.frame,
CGRectMake(0,0,WXPixelResize(100),WXPixelResize(200))));
- XCTAssert(CGRectEqualToRect(view.subviews[0].frame,
+ XCTAssert(WXRectApproximateToRect(view.subviews[0].frame,
CGRectMake(0,0,WXPixelResize(100),WXPixelResize(200))));
[expectation4 fulfill];
};
- [self waitForExpectationsWithTimeout:5.0 handler:^(NSError *error) {
+ [self waitForExpectationsWithTimeout:10.0 handler:^(NSError *error) {
if (error) {
NSLog(@"Timeout Error: %@", error);
}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b5123119/ios/sdk/WeexSDKTests/WXSDKEngineTests.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDKTests/WXSDKEngineTests.m b/ios/sdk/WeexSDKTests/WXSDKEngineTests.m
index 7f06d4f..a3a22ed 100644
--- a/ios/sdk/WeexSDKTests/WXSDKEngineTests.m
+++ b/ios/sdk/WeexSDKTests/WXSDKEngineTests.m
@@ -11,7 +11,8 @@
#import "WXModuleFactory.h"
#import "WXComponentFactory.h"
#import "WXHandlerFactory.h"
-#import "WXNetworkDefaultImpl.h"
+#import "WXResourceRequest.h"
+#import "WXResourceRequestHandlerDefaultImpl.h"
@interface WXSDKEngineTests : XCTestCase
@@ -34,13 +35,6 @@
// Use XCTAssert and related functions to verify your tests produce the correct results.
}
-- (void)testPerformanceExample {
- // This is an example of a performance test case.
- [self measureBlock:^{
- // Put the code you want to measure the time of here.
- }];
-}
-
- (void)testRegisterModule {
[WXSDKEngine registerModule:@"stream" withClass:NSClassFromString(@"WXStreamModule")];
@@ -56,7 +50,7 @@
Class cls = [WXModuleFactory classWithModuleName:@"stream"];
XCTAssertEqualObjects(NSStringFromClass(cls), @"WXStreamModule");
- SEL selector = [WXModuleFactory methodWithModuleName:@"stream" withMethod:@"fetch"];
+ SEL selector = [WXModuleFactory selectorWithModuleName:@"stream" methodName:@"fetch" isSync:nil];
XCTAssertEqualObjects(NSStringFromSelector(selector), @"fetch:callback:progressCallback:");
}
@@ -92,15 +86,15 @@
- (void)testRegisterHandler {
- [WXSDKEngine registerHandler:[WXNetworkDefaultImpl new] withProtocol:@protocol(WXNetworkProtocol)];
- id handler = [WXHandlerFactory handlerForProtocol:@protocol(WXNetworkProtocol)];
+ [WXSDKEngine registerHandler:[WXResourceRequestHandlerDefaultImpl new] withProtocol:@protocol(WXResourceRequestHandler)];
+ id handler = [WXHandlerFactory handlerForProtocol:@protocol(WXResourceRequestHandler)];
XCTAssertNotNil(handler);
- XCTAssertTrue([handler conformsToProtocol:@protocol(WXNetworkProtocol)]);
+ XCTAssertTrue([handler conformsToProtocol:@protocol(WXResourceRequestHandler)]);
NSDictionary *handlerConfigs = [WXHandlerFactory handlerConfigs];
- handler = [handlerConfigs objectForKey:NSStringFromProtocol(@protocol(WXNetworkProtocol))];
+ handler = [handlerConfigs objectForKey:NSStringFromProtocol(@protocol(WXResourceRequestHandler))];
XCTAssertNotNil(handler);
- XCTAssertTrue([handler conformsToProtocol:@protocol(WXNetworkProtocol)]);
+ XCTAssertTrue([handler conformsToProtocol:@protocol(WXResourceRequestHandler)]);
}
- (void)testComponentFactory {
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b5123119/ios/sdk/WeexSDKTests/WXSDKManagerTests.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDKTests/WXSDKManagerTests.m b/ios/sdk/WeexSDKTests/WXSDKManagerTests.m
index f3e65bb..94d44fe 100644
--- a/ios/sdk/WeexSDKTests/WXSDKManagerTests.m
+++ b/ios/sdk/WeexSDKTests/WXSDKManagerTests.m
@@ -32,22 +32,11 @@
// Use XCTAssert and related functions to verify your tests produce the correct results.
}
-- (void)testPerformanceExample {
- // This is an example of a performance test case.
- [self measureBlock:^{
- // Put the code you want to measure the time of here.
- }];
-}
-
- (void)testWXSDKManager {
id bridgeMgr = [WXSDKManager bridgeMgr];
XCTAssertNotNil(bridgeMgr);
XCTAssertTrue([bridgeMgr isKindOfClass:NSClassFromString(@"WXBridgeManager")]);
- id moduleMgr = [WXSDKManager moduleMgr];
- XCTAssertNotNil(moduleMgr);
- XCTAssertTrue([moduleMgr isKindOfClass:NSClassFromString(@"WXModuleManager")]);
-
[WXSDKManager storeInstance:[WXSDKInstance new] forID:@"0"];
WXSDKInstance *instance0 = [WXSDKManager instanceForID:@"0"];
XCTAssertNotNil(instance0);
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b5123119/ios/sdk/WeexSDKTests/WXStorageTests.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDKTests/WXStorageTests.m b/ios/sdk/WeexSDKTests/WXStorageTests.m
index 862535b..3a48f1e 100644
--- a/ios/sdk/WeexSDKTests/WXStorageTests.m
+++ b/ios/sdk/WeexSDKTests/WXStorageTests.m
@@ -411,11 +411,4 @@
}];
}
-- (void)testPerformanceExample {
- // This is an example of a performance test case.
- [self measureBlock:^{
- // Put the code you want to measure the time of here.
- }];
-}
-
@end
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b5123119/ios/sdk/WeexSDKTests/WXStreamModuleTests.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDKTests/WXStreamModuleTests.m b/ios/sdk/WeexSDKTests/WXStreamModuleTests.m
index cf65463..6e024f0 100644
--- a/ios/sdk/WeexSDKTests/WXStreamModuleTests.m
+++ b/ios/sdk/WeexSDKTests/WXStreamModuleTests.m
@@ -9,7 +9,7 @@
#import <XCTest/XCTest.h>
#import "WXStreamModule.h"
#import <WeexSDK/WeexSDK.h>
-#import "WXNetworkDefaultImpl.h"
+#import "WXResourceRequestHandlerDefaultImpl.h"
@interface WXStreamModuleTests : XCTestCase
@property (nonatomic, strong) WXStreamModule *streamModule;
@@ -22,7 +22,7 @@
- (void)setUp {
[super setUp];
_streamModule = [[WXStreamModule alloc] init];
- [WXSDKEngine registerHandler:[WXNetworkDefaultImpl new] withProtocol:@protocol(WXNetworkProtocol)];
+ [WXSDKEngine registerHandler:[WXResourceRequestHandlerDefaultImpl new] withProtocol:@protocol(WXResourceRequestHandler)];
_exp = [self expectationWithDescription:@"SendRequestSuccess Unit Test Error!"];
}
@@ -55,7 +55,7 @@
callbackResult = result;
[_exp fulfill];
}];
- [self waitForExpectationsWithTimeout:10 handler:^(NSError * error) {
+ [self waitForExpectationsWithTimeout:20 handler:^(NSError * error) {
XCTAssertNotNil(callbackResult);
}];
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b5123119/ios/sdk/WeexSDKTests/WXTimerModuleTests.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDKTests/WXTimerModuleTests.m b/ios/sdk/WeexSDKTests/WXTimerModuleTests.m
index fc918c0..e6de37d 100644
--- a/ios/sdk/WeexSDKTests/WXTimerModuleTests.m
+++ b/ios/sdk/WeexSDKTests/WXTimerModuleTests.m
@@ -40,13 +40,6 @@
// Use XCTAssert and related functions to verify your tests produce the correct results.
}
-- (void)testPerformanceExample {
- // This is an example of a performance test case.
- [self measureBlock:^{
- // Put the code you want to measure the time of here.
- }];
-}
-
- (void)testSetTimeout{
self.exp = [self expectationWithDescription:@"Set Timeout Unit Test Error!"];
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b5123119/ios/sdk/WeexSDKTests/WXURLRewriteTests.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDKTests/WXURLRewriteTests.m b/ios/sdk/WeexSDKTests/WXURLRewriteTests.m
index 0612aa3..7a1f334 100644
--- a/ios/sdk/WeexSDKTests/WXURLRewriteTests.m
+++ b/ios/sdk/WeexSDKTests/WXURLRewriteTests.m
@@ -79,7 +79,7 @@ static id _mockNSBundle;
- (void)testFileURL {
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
NSURL *fileURL = [bundle URLForResource:@"testRootView" withExtension:@"js"];
- NSURL *rewriteURL = [_rewriteHandler rewriteURL:fileURL.absoluteString withResourceType:WXResourceTypeBundle withInstance:_instance];
+ NSURL *rewriteURL = [_rewriteHandler rewriteURL:fileURL.absoluteString withResourceType:WXResourceTypeMainBundle withInstance:_instance];
XCTAssertEqualObjects(fileURL.absoluteString, [rewriteURL absoluteString]);
}
@@ -87,7 +87,7 @@ static id _mockNSBundle;
NSString *testURL = @"local://testRootView.js";
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
NSURL *fileURL = [bundle URLForResource:@"testRootView" withExtension:@"js"];
- NSURL *rewriteURL = [_rewriteHandler rewriteURL:testURL withResourceType:WXResourceTypeBundle withInstance:_instance];
+ NSURL *rewriteURL = [_rewriteHandler rewriteURL:testURL withResourceType:WXResourceTypeMainBundle withInstance:_instance];
XCTAssertEqualObjects(fileURL.absoluteString, [rewriteURL absoluteString]);
}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b5123119/ios/sdk/WeexSDKTests/WeexSDKTests.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDKTests/WeexSDKTests.m b/ios/sdk/WeexSDKTests/WeexSDKTests.m
index 276dad8..d7cd73e 100644
--- a/ios/sdk/WeexSDKTests/WeexSDKTests.m
+++ b/ios/sdk/WeexSDKTests/WeexSDKTests.m
@@ -29,11 +29,5 @@
// Use XCTAssert and related functions to verify your tests produce the correct results.
}
-- (void)testPerformanceExample {
- // This is an example of a performance test case.
- [self measureBlock:^{
- // Put the code you want to measure the time of here.
- }];
-}
@end
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b5123119/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index 21649af..d4331be 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,11 @@
{
"name": "weex",
"version": "0.4.0",
+ "subversion": {
+ "browser": "0.5.0",
+ "framework": "0.19.6",
+ "transformer": ">=0.1.5 <0.5"
+ },
"description": "A framework for building Mobile cross-platform UI",
"license": "Apache-2.0",
"repository": {
@@ -32,8 +37,9 @@
},
"scripts": {
"postinstall": "bash ./bin/install-hooks.sh",
- "build:native": "rollup -c build/rollup.config.js",
- "build:browser": "wwp && rollup -c build/rollup.browser.config.js",
+ "build:native": "node build/build.js native",
+ "build:runtime": "node build/build.js runtime",
+ "build:browser": "wwp && node build/build.js browser",
"build:browser:common": "rollup -c build/rollup.browser.common.config.js",
"build:examples": "webpack --config build/webpack.examples.config.js",
"build:test": "webpack --config build/webpack.test.config.js",
@@ -41,8 +47,9 @@
"build": "npm run build:native && npm run build:browser && npm run build:examples && npm run build:test",
"dist:browser": "npm run build:browser && npm run build:browser:common && bash ./bin/dist-browser.sh",
"dist": "npm run dist:browser",
- "dev:native": "rollup -w -c build/rollup.config.js",
- "dev:browser": "rollup -w -c build/rollup.browser.config.js",
+ "dev:native": "node build/build.js native --watch",
+ "dev:runtime": "node build/build.js runtime --watch",
+ "dev:browser": "wwp && node build/build.js native --watch",
"dev:examples": "webpack --watch --config build/webpack.examples.config.js",
"dev:test": "webpack --watch --config build/webpack.test.config.js",
"lint": "eslint html5",
@@ -61,11 +68,6 @@
"copy:examples": "rm -rf ./android/playground/app/src/main/assets/* && cp -vrf ./examples/build/* ./android/playground/app/src/main/assets/",
"copy": "npm run copy:js && npm run copy:examples"
},
- "subversion": {
- "browser": "0.5.0",
- "framework": "0.16.18",
- "transformer": ">=0.1.5 <0.4"
- },
"dependencies": {
"animationjs": "^0.1.5",
"core-js": "^2.4.0",
@@ -76,8 +78,9 @@
"modals": "^0.1.6",
"scroll-to": "0.0.2",
"semver": "^5.1.0",
- "weex-vue-framework": "2.0.5-weex.1",
- "weex-components": "^0.2.0"
+ "weex-components": "^0.2.0",
+ "weex-rax-framework": "0.1.0",
+ "weex-vue-framework": "2.1.8-weex.1"
},
"devDependencies": {
"xml2map": "^1.0.2",
@@ -116,10 +119,8 @@
"uglify-js": "^2.6.4",
"webpack": "^1.13.1",
"weex-components": "^0.2.0",
- "weex-loader": "^0.3.1",
- "weex-vdom-tester": "^0.1.2",
- "weex-vue-components": "^0.1.0",
- "weex-vue-loader": "^0.1.1",
+ "weex-loader": "^0.4.0",
+ "weex-vdom-tester": "^0.2.0",
"wwp": "^0.3.0"
}
}