Repository: incubator-weex Updated Branches: refs/heads/master 7c5ef1c68 -> 9c9ae8846
* [iOS] fix multithread crash about mutable array in scroller component Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/9c9ae884 Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/9c9ae884 Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/9c9ae884 Branch: refs/heads/master Commit: 9c9ae884659682882ba2803906a0116556377859 Parents: 7c5ef1c Author: acton393 <zhangxing610...@gmail.com> Authored: Thu Mar 8 15:27:44 2018 +0800 Committer: acton393 <zhangxing610...@gmail.com> Committed: Thu Mar 8 15:28:34 2018 +0800 ---------------------------------------------------------------------- ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.m | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/9c9ae884/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.m ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.m b/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.m index 4ebaec5..ede9de3 100644 --- a/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.m +++ b/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.m @@ -28,6 +28,7 @@ #import "WXRefreshComponent.h" #import "WXConfigCenterProtocol.h" #import "WXSDKEngine.h" +#import "WXThreadSafeMutableArray.h" @interface WXScrollerComponnetView:UIScrollView @end @@ -50,7 +51,7 @@ @interface WXScrollerComponent() @property (nonatomic, strong) NSMutableArray * stickyArray; -@property (nonatomic, strong) NSMutableArray * listenerArray; +@property (nonatomic, strong) WXThreadSafeMutableArray * listenerArray; @property (nonatomic, weak) WXRefreshComponent *refreshComponent; @property (nonatomic, weak) WXLoadingComponent *loadingComponent; @@ -118,7 +119,7 @@ WX_EXPORT_METHOD(@selector(resetLoadmore)) if (self) { _stickyArray = [NSMutableArray array]; - _listenerArray = [NSMutableArray array]; + _listenerArray = [WXThreadSafeMutableArray array]; _scrollEvent = NO; _scrollStartEvent = NO; _scrollEndEvent = NO; @@ -382,7 +383,8 @@ WX_EXPORT_METHOD(@selector(resetLoadmore)) - (void)addScrollToListener:(WXComponent *)target { BOOL has = NO; - for (WXScrollToTarget *targetData in self.listenerArray) { + WXThreadSafeMutableArray *listenerArray = [self.listenerArray copy]; + for (WXScrollToTarget *targetData in listenerArray) { if (targetData.target == target) { has = YES; break; @@ -400,7 +402,8 @@ WX_EXPORT_METHOD(@selector(resetLoadmore)) { if (_shouldRemoveScrollerListener) { WXScrollToTarget *targetData = nil; - for (WXScrollToTarget *targetDataTemp in self.listenerArray) { + WXThreadSafeMutableArray *listenerArray = [self.listenerArray copy]; + for (WXScrollToTarget *targetDataTemp in listenerArray) { if (targetDataTemp.target == target) { targetData = targetDataTemp; break;