[38/50] [abbrv] incubator-weex git commit: [WEEX-459][iOS] Fix crash if template not registered for recycle list on iOS.
[WEEX-459][iOS] Fix crash if template not registered for recycle list on iOS. Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/ece3827d Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/ece3827d Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/ece3827d Branch: refs/heads/release Commit: ece3827d5fd56f7cd7333dc744425df45e07edd9 Parents: d1d8005 Author: ç¥æ¼ Authored: Wed Jun 13 20:08:12 2018 +0800 Committer: Adam Feng Committed: Thu Jun 14 14:56:26 2018 +0800 -- .../Component/RecycleList/WXRecycleListComponent.mm | 16 +++- .../RecycleList/WXRecycleListTemplateManager.h | 4 .../RecycleList/WXRecycleListTemplateManager.m | 16 +++- 3 files changed, 30 insertions(+), 6 deletions(-) -- http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/ece3827d/ios/sdk/WeexSDK/Sources/Component/RecycleList/WXRecycleListComponent.mm -- diff --git a/ios/sdk/WeexSDK/Sources/Component/RecycleList/WXRecycleListComponent.mm b/ios/sdk/WeexSDK/Sources/Component/RecycleList/WXRecycleListComponent.mm index 551acd9..a55dada 100644 --- a/ios/sdk/WeexSDK/Sources/Component/RecycleList/WXRecycleListComponent.mm +++ b/ios/sdk/WeexSDK/Sources/Component/RecycleList/WXRecycleListComponent.mm @@ -499,12 +499,18 @@ WX_EXPORT_METHOD(@selector(setListData:)) // 1. get the data relating to the cell id data = [_dataManager dataAtIndex:indexPath.row]; -// 2. get the template type specified by data +// 2. get the template type specified by data, and if template is not found, return an empty view of any template to avoid crash. NSString * templateType = [self templateType:indexPath]; _templateManager.collectionView = collectionView; -if (!templateType) { -WXLogError(@"Each data should have a value for %@ to indicate template type", _templateSwitchKey); -return nil; +if (!templateType || (templateType && ![_templateManager isTemplateRegistered:templateType])) { +WXLogError(@"Template %@ not registered for collection view.", templateType); +UICollectionViewCell *cellView = [_collectionView dequeueReusableCellWithReuseIdentifier:[_templateManager anyRegisteredTemplate] forIndexPath:indexPath]; +for (UIView *view in cellView.contentView.subviews) { +[view removeFromSuperview]; +} +cellView.wx_component = nil; +[cellView setAccessibilityIdentifier:nil]; +return cellView; } // 3. dequeue a cell component by template type @@ -607,7 +613,7 @@ WX_EXPORT_METHOD(@selector(setListData:)) return templateType; } -if (_templateSwitchKey &[_templateSwitchKey]){ +if (_templateSwitchKey && data[_templateSwitchKey]){ templateType = data[_templateSwitchKey]; } else if (data[WXDefaultRecycleTemplateType]){ // read the default type. http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/ece3827d/ios/sdk/WeexSDK/Sources/Component/RecycleList/WXRecycleListTemplateManager.h -- diff --git a/ios/sdk/WeexSDK/Sources/Component/RecycleList/WXRecycleListTemplateManager.h b/ios/sdk/WeexSDK/Sources/Component/RecycleList/WXRecycleListTemplateManager.h index 926c2f1..b956122 100644 --- a/ios/sdk/WeexSDK/Sources/Component/RecycleList/WXRecycleListTemplateManager.h +++ b/ios/sdk/WeexSDK/Sources/Component/RecycleList/WXRecycleListTemplateManager.h @@ -32,4 +32,8 @@ - (WXCellSlotComponent *)topTemplate; +- (BOOL)isTemplateRegistered:(NSString *)aTemplate; + +- (NSString *)anyRegisteredTemplate; + @end http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/ece3827d/ios/sdk/WeexSDK/Sources/Component/RecycleList/WXRecycleListTemplateManager.m -- diff --git a/ios/sdk/WeexSDK/Sources/Component/RecycleList/WXRecycleListTemplateManager.m b/ios/sdk/WeexSDK/Sources/Component/RecycleList/WXRecycleListTemplateManager.m index 199d551..2a90eeb 100644 --- a/ios/sdk/WeexSDK/Sources/Component/RecycleList/WXRecycleListTemplateManager.m +++ b/ios/sdk/WeexSDK/Sources/Component/RecycleList/WXRecycleListTemplateManager.m @@ -31,12 +31,14 @@ @implementation WXRecycleListTemplateManager { +NSMutableSet *_registeredTemplates; NSMapTable *_templateTypeMap; } - (instancetype)init { if (self = [super init]) { +_registeredTemplates = [NSMutableSet set]; _templateTypeMap = [NSMapTable strongToWeakObjectsMapTable]; } @@ -87,7 +89,7 @@ - (void)_registerCellClassForReuseID:(NSString *)templateID { WXLogDebug(@"register cell class for
incubator-weex git commit: [WEEX-459][iOS] Fix crash if template not registered for recycle list on iOS.
Repository: incubator-weex Updated Branches: refs/heads/master d1d80057b -> ece3827d5 [WEEX-459][iOS] Fix crash if template not registered for recycle list on iOS. Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/ece3827d Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/ece3827d Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/ece3827d Branch: refs/heads/master Commit: ece3827d5fd56f7cd7333dc744425df45e07edd9 Parents: d1d8005 Author: ç¥æ¼ Authored: Wed Jun 13 20:08:12 2018 +0800 Committer: Adam Feng Committed: Thu Jun 14 14:56:26 2018 +0800 -- .../Component/RecycleList/WXRecycleListComponent.mm | 16 +++- .../RecycleList/WXRecycleListTemplateManager.h | 4 .../RecycleList/WXRecycleListTemplateManager.m | 16 +++- 3 files changed, 30 insertions(+), 6 deletions(-) -- http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/ece3827d/ios/sdk/WeexSDK/Sources/Component/RecycleList/WXRecycleListComponent.mm -- diff --git a/ios/sdk/WeexSDK/Sources/Component/RecycleList/WXRecycleListComponent.mm b/ios/sdk/WeexSDK/Sources/Component/RecycleList/WXRecycleListComponent.mm index 551acd9..a55dada 100644 --- a/ios/sdk/WeexSDK/Sources/Component/RecycleList/WXRecycleListComponent.mm +++ b/ios/sdk/WeexSDK/Sources/Component/RecycleList/WXRecycleListComponent.mm @@ -499,12 +499,18 @@ WX_EXPORT_METHOD(@selector(setListData:)) // 1. get the data relating to the cell id data = [_dataManager dataAtIndex:indexPath.row]; -// 2. get the template type specified by data +// 2. get the template type specified by data, and if template is not found, return an empty view of any template to avoid crash. NSString * templateType = [self templateType:indexPath]; _templateManager.collectionView = collectionView; -if (!templateType) { -WXLogError(@"Each data should have a value for %@ to indicate template type", _templateSwitchKey); -return nil; +if (!templateType || (templateType && ![_templateManager isTemplateRegistered:templateType])) { +WXLogError(@"Template %@ not registered for collection view.", templateType); +UICollectionViewCell *cellView = [_collectionView dequeueReusableCellWithReuseIdentifier:[_templateManager anyRegisteredTemplate] forIndexPath:indexPath]; +for (UIView *view in cellView.contentView.subviews) { +[view removeFromSuperview]; +} +cellView.wx_component = nil; +[cellView setAccessibilityIdentifier:nil]; +return cellView; } // 3. dequeue a cell component by template type @@ -607,7 +613,7 @@ WX_EXPORT_METHOD(@selector(setListData:)) return templateType; } -if (_templateSwitchKey &[_templateSwitchKey]){ +if (_templateSwitchKey && data[_templateSwitchKey]){ templateType = data[_templateSwitchKey]; } else if (data[WXDefaultRecycleTemplateType]){ // read the default type. http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/ece3827d/ios/sdk/WeexSDK/Sources/Component/RecycleList/WXRecycleListTemplateManager.h -- diff --git a/ios/sdk/WeexSDK/Sources/Component/RecycleList/WXRecycleListTemplateManager.h b/ios/sdk/WeexSDK/Sources/Component/RecycleList/WXRecycleListTemplateManager.h index 926c2f1..b956122 100644 --- a/ios/sdk/WeexSDK/Sources/Component/RecycleList/WXRecycleListTemplateManager.h +++ b/ios/sdk/WeexSDK/Sources/Component/RecycleList/WXRecycleListTemplateManager.h @@ -32,4 +32,8 @@ - (WXCellSlotComponent *)topTemplate; +- (BOOL)isTemplateRegistered:(NSString *)aTemplate; + +- (NSString *)anyRegisteredTemplate; + @end http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/ece3827d/ios/sdk/WeexSDK/Sources/Component/RecycleList/WXRecycleListTemplateManager.m -- diff --git a/ios/sdk/WeexSDK/Sources/Component/RecycleList/WXRecycleListTemplateManager.m b/ios/sdk/WeexSDK/Sources/Component/RecycleList/WXRecycleListTemplateManager.m index 199d551..2a90eeb 100644 --- a/ios/sdk/WeexSDK/Sources/Component/RecycleList/WXRecycleListTemplateManager.m +++ b/ios/sdk/WeexSDK/Sources/Component/RecycleList/WXRecycleListTemplateManager.m @@ -31,12 +31,14 @@ @implementation WXRecycleListTemplateManager { +NSMutableSet *_registeredTemplates; NSMapTable *_templateTypeMap; } - (instancetype)init { if (self = [super init]) { +_registeredTemplates = [NSMutableSet set]; _templateTypeMap = [NSMapTable strongToWeakObjectsMapTable]; } @@ -87,7 +89,7 @@ -