From 8aa583c897ac51a073802683b322711b6b77bfd5 Mon Sep 17 00:00:00 2001 From: acton393 Date: Mon, 9 Oct 2017 18:22:56 +0800 Subject: [PATCH 1/4] * [ios] add WXScrollerComponentView and compatible iOS 11 new API --- .../Sources/Component/WXScrollerComponent.m | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.m b/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.m index 88c934c96c..bf8021f3dc 100644 --- a/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.m +++ b/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.m @@ -26,7 +26,15 @@ #import "WXUtility.h" #import "WXLoadingComponent.h" #import "WXRefreshComponent.h" -@interface UIScrollView(WeexUIScrollerView_ContentInsetAdjustmentBehavior) + +@interface WXScrollerComponnetView:UIScrollView +@end + +@implementation WXScrollerComponnetView +@end; + +// add a category compatible for new API +@interface WXScrollerComponnetView(WXScrollerComponnetView_ContentInsetAdjustmentBehavior) @property(nonatomic, assign)NSUInteger contentInsetAdjustmentBehavior; @end @@ -139,14 +147,14 @@ -(instancetype)initWithRef:(NSString *)ref type:(NSString *)type styles:(NSDicti - (UIView *)loadView { - return [[UIScrollView alloc] init]; + return [[WXScrollerComponnetView alloc] init]; } - (void)viewDidLoad { [super viewDidLoad]; [self setContentSize:_contentSize]; - UIScrollView* scrollView = (UIScrollView *)self.view; + WXScrollerComponnetView* scrollView = (WXScrollerComponnetView *)self.view; scrollView.delegate = self; scrollView.exclusiveTouch = YES; scrollView.autoresizesSubviews = NO; From d606353f8352091d5c76721d958d687375e9660f Mon Sep 17 00:00:00 2001 From: acton393 Date: Mon, 9 Oct 2017 19:46:20 +0800 Subject: [PATCH 2/4] * [ios] add more comments about category --- ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.m | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.m b/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.m index bf8021f3dc..a7d042e440 100644 --- a/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.m +++ b/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.m @@ -33,7 +33,6 @@ @interface WXScrollerComponnetView:UIScrollView @implementation WXScrollerComponnetView @end; -// add a category compatible for new API @interface WXScrollerComponnetView(WXScrollerComponnetView_ContentInsetAdjustmentBehavior) @property(nonatomic, assign)NSUInteger contentInsetAdjustmentBehavior; @end @@ -166,7 +165,10 @@ - (void)viewDidLoad scrollView.alwaysBounceHorizontal = _alwaysScrollableHorizontal; scrollView.alwaysBounceVertical = _alwaysScrollableVertical; if (WX_SYS_VERSION_GREATER_THAN_OR_EQUAL_TO(@"11.0")) { - // now use the runtime to forbid the contentInset being Adjusted + // now use the runtime to forbid the contentInset being Adjusted. + // here we add a category for scoller component view class compatible for new API, + // as we are concerning about weexSDK build as framework by Xcode8, using in Xcode9 project, + // so the the macro __IPHONE_11_0 will be useless in this case. scrollView.contentInsetAdjustmentBehavior = 2; } From a2e5b1c1602c7cd72af2b31b3035f782a31f856e Mon Sep 17 00:00:00 2001 From: acton393 Date: Mon, 9 Oct 2017 21:39:16 +0800 Subject: [PATCH 3/4] * [ios] update image load performance --- .../Sources/Component/WXImageComponent.m | 89 ++++++++++--------- 1 file changed, 45 insertions(+), 44 deletions(-) diff --git a/ios/sdk/WeexSDK/Sources/Component/WXImageComponent.m b/ios/sdk/WeexSDK/Sources/Component/WXImageComponent.m index 90c29a14db..4cbe4da3f6 100644 --- a/ios/sdk/WeexSDK/Sources/Component/WXImageComponent.m +++ b/ios/sdk/WeexSDK/Sources/Component/WXImageComponent.m @@ -336,14 +336,17 @@ - (NSString *)imageSrc - (void)setImageSrc:(NSString*)src { - pthread_mutex_lock(&(_imageSrcMutex)); - if (![src isEqualToString:_imageSrc]) { - _imageSrc = src; - _imageDownloadFinish = NO; - ((UIImageView*)self.view).image = nil; - [self updateImage]; + if ([src isEqualToString:_imageSrc]) { + // if image src is equal to then ignore it. + return; } + pthread_mutex_lock(&(_imageSrcMutex)); + _imageSrc = src; + _imageDownloadFinish = NO; + ((UIImageView*)self.view).image = nil; pthread_mutex_unlock(&(_imageSrcMutex)); + + [self updateImage]; } - (void)updateImage @@ -426,45 +429,43 @@ - (void)updateContentImageWithFailedBlock:(void(^)(NSString *, NSError *))downlo NSString * newURL = [imageSrc copy]; WX_REWRITE_URL(imageSrc, WXResourceTypeImage, self.weexInstance) __weak typeof(self) weakSelf = self; - dispatch_async(dispatch_get_main_queue(), ^{ - weakSelf.imageOperation = [[weakSelf imageLoader] downloadImageWithURL:newURL imageFrame:weakSelf.calculatedFrame userInfo:userInfo completed:^(UIImage *image, NSError *error, BOOL finished) { - dispatch_async(dispatch_get_main_queue(), ^{ - __strong typeof(self) strongSelf = weakSelf; - - if (strongSelf.imageLoadEvent) { - NSMutableDictionary *sizeDict = [NSMutableDictionary new]; - sizeDict[@"naturalWidth"] = @0; - sizeDict[@"naturalHeight"] = @0; - if (!error) { - sizeDict[@"naturalWidth"] = @(image.size.width * image.scale); - sizeDict[@"naturalHeight"] = @(image.size.height * image.scale); - } else { - [sizeDict setObject:[error description]?:@"" forKey:@"errorDesc"]; - } - [strongSelf fireEvent:@"load" params:@{ @"success": error? @false : @true,@"size":sizeDict}]; - } - if (error) { - downloadFailedBlock(imageSrc, error); - [strongSelf readyToRender]; - return ; - } - - if (![imageSrc isEqualToString:strongSelf.imageSrc]) { - return ; - } - - if ([strongSelf isViewLoaded]) { - strongSelf.imageDownloadFinish = YES; - ((UIImageView *)strongSelf.view).image = image; - [strongSelf readyToRender]; - } else if (strongSelf->_isCompositingChild) { - strongSelf.imageDownloadFinish = YES; - strongSelf->_image = image; - [strongSelf setNeedsDisplay]; + weakSelf.imageOperation = [[weakSelf imageLoader] downloadImageWithURL:newURL imageFrame:weakSelf.calculatedFrame userInfo:userInfo completed:^(UIImage *image, NSError *error, BOOL finished) { + dispatch_async(dispatch_get_main_queue(), ^{ + __strong typeof(self) strongSelf = weakSelf; + + if (strongSelf.imageLoadEvent) { + NSMutableDictionary *sizeDict = [NSMutableDictionary new]; + sizeDict[@"naturalWidth"] = @0; + sizeDict[@"naturalHeight"] = @0; + if (!error) { + sizeDict[@"naturalWidth"] = @(image.size.width * image.scale); + sizeDict[@"naturalHeight"] = @(image.size.height * image.scale); + } else { + [sizeDict setObject:[error description]?:@"" forKey:@"errorDesc"]; } - }); - }]; - }); + [strongSelf fireEvent:@"load" params:@{ @"success": error? @false : @true,@"size":sizeDict}]; + } + if (error) { + downloadFailedBlock(imageSrc, error); + [strongSelf readyToRender]; + return ; + } + + if (![imageSrc isEqualToString:strongSelf.imageSrc]) { + return ; + } + + if ([strongSelf isViewLoaded]) { + strongSelf.imageDownloadFinish = YES; + ((UIImageView *)strongSelf.view).image = image; + [strongSelf readyToRender]; + } else if (strongSelf->_isCompositingChild) { + strongSelf.imageDownloadFinish = YES; + strongSelf->_image = image; + [strongSelf setNeedsDisplay]; + } + }); + }]; } - (void)readyToRender From d05c55e0908d5437fea2b7a7cbfb2576a1d202e5 Mon Sep 17 00:00:00 2001 From: acton393 Date: Wed, 11 Oct 2017 11:39:53 +0800 Subject: [PATCH 4/4] * [ios] bugfix list view can not scroll --- .../Sources/Component/WXScrollerComponent.m | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.m b/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.m index a7d042e440..b7a522a035 100644 --- a/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.m +++ b/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.m @@ -69,8 +69,8 @@ @implementation WXScrollerComponent CGPoint _lastContentOffset; CGPoint _lastScrollEventFiredOffset; BOOL _scrollable; - BOOL _alwaysScrollableVertical; - BOOL _alwaysScrollableHorizontal; + NSString * _alwaysScrollableVertical; + NSString * _alwaysScrollableHorizontal; // vertical & horizontal WXScrollDirection _scrollDirection; @@ -119,10 +119,13 @@ -(instancetype)initWithRef:(NSString *)ref type:(NSString *)type styles:(NSDicti _lastScrollEventFiredOffset = CGPointMake(0, 0); _scrollDirection = attributes[@"scrollDirection"] ? [WXConvert WXScrollDirection:attributes[@"scrollDirection"]] : WXScrollDirectionVertical; _showScrollBar = attributes[@"showScrollbar"] ? [WXConvert BOOL:attributes[@"showScrollbar"]] : YES; - // default value is NO; - _alwaysScrollableVertical = attributes[@"alwaysScrollableVertical"]?[WXConvert BOOL:attributes[@"alwaysScrollableVertical"]] : NO; - // default value is NO; - _alwaysScrollableHorizontal = attributes[@"alwaysScrollableHorizontal"]?[WXConvert BOOL:attributes[@"alwaysScrollableHorizontal"]] : NO; + + if (attributes[@"alwaysScrollableVertical"]) { + _alwaysScrollableVertical = [WXConvert NSString:attributes[@"alwaysScrollableVertical"]]; + } + if (attributes[@"alwaysScrollableHorizontal"]) { + _alwaysScrollableHorizontal = [WXConvert NSString:attributes[@"alwaysScrollableHorizontal"]]; + } _pagingEnabled = attributes[@"pagingEnabled"] ? [WXConvert BOOL:attributes[@"pagingEnabled"]] : NO; _loadMoreOffset = attributes[@"loadmoreoffset"] ? [WXConvert WXPixelType:attributes[@"loadmoreoffset"] scaleFactor:self.weexInstance.pixelScaleFactor] : 0; _loadmoreretry = attributes[@"loadmoreretry"] ? [WXConvert NSUInteger:attributes[@"loadmoreretry"]] : 0; @@ -162,8 +165,12 @@ - (void)viewDidLoad scrollView.showsHorizontalScrollIndicator = _showScrollBar; scrollView.scrollEnabled = _scrollable; scrollView.pagingEnabled = _pagingEnabled; - scrollView.alwaysBounceHorizontal = _alwaysScrollableHorizontal; - scrollView.alwaysBounceVertical = _alwaysScrollableVertical; + if (_alwaysScrollableHorizontal) { + scrollView.alwaysBounceHorizontal = [WXConvert BOOL:_alwaysScrollableHorizontal]; + } + if (_alwaysScrollableVertical) { + scrollView.alwaysBounceVertical = [WXConvert BOOL:_alwaysScrollableVertical]; + } if (WX_SYS_VERSION_GREATER_THAN_OR_EQUAL_TO(@"11.0")) { // now use the runtime to forbid the contentInset being Adjusted. // here we add a category for scoller component view class compatible for new API, @@ -232,13 +239,13 @@ - (void)updateAttributes:(NSDictionary *)attributes ((UIScrollView *)self.view).scrollEnabled = _scrollable; } if (attributes[@"alwaysScrollableHorizontal"]) { - _alwaysScrollableHorizontal = [WXConvert BOOL:attributes[@"alwaysScrollableHorizontal"]]; - ((UIScrollView*)self.view).alwaysBounceHorizontal = _alwaysScrollableHorizontal; + _alwaysScrollableHorizontal = [WXConvert NSString:attributes[@"alwaysScrollableHorizontal"]]; + ((UIScrollView*)self.view).alwaysBounceHorizontal = [WXConvert BOOL:_alwaysScrollableHorizontal]; } if (attributes[@"alwaysScrollableVertical"]) { - _alwaysScrollableVertical = [WXConvert BOOL:attributes[@"alwaysScrollableVertical"]]; - ((UIScrollView*)self.view).alwaysBounceVertical = _alwaysScrollableVertical; + _alwaysScrollableVertical = [WXConvert NSString:attributes[@"alwaysScrollableVertical"]]; + ((UIScrollView*)self.view).alwaysBounceVertical = [WXConvert BOOL:_alwaysScrollableVertical]; } if (attributes[@"offsetAccuracy"]) { _offsetAccuracy = [WXConvert WXPixelType:attributes[@"offsetAccuracy"] scaleFactor:self.weexInstance.pixelScaleFactor];