Skip to content

Commit 5090987

Browse files
committed
fix(ios): improved handling when images are nil
1 parent 9142ce0 commit 5090987

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

packages/react-native-carplay/ios/RNCarPlay.m

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,9 @@ - (void)updateItemImageWithURL:(CPListItem *)item imgUrl:(NSString *)imgUrlStrin
173173
if (data) {
174174
UIImage *image = [UIImage imageWithData:data];
175175
dispatch_async(dispatch_get_main_queue(), ^{
176-
[item setImage:image];
176+
if(image) {
177+
[item setImage:image];
178+
}
177179
});
178180
} else {
179181
NSLog(@"Failed to load image from URL: %@", imgUrl);
@@ -193,7 +195,9 @@ - (void)updateListRowItemImageWithURL:(CPListImageRowItem *)item imgUrl:(NSStrin
193195
NSMutableArray* newImages = [item.gridImages mutableCopy];
194196

195197
@try {
196-
newImages[index] = image;
198+
if(image) {
199+
newImages[index] = image;
200+
}
197201
}
198202
@catch (NSException *exception) {
199203
// Best effort updating the array
@@ -293,7 +297,7 @@ - (void)updateListRowItemImageWithURL:(CPListImageRowItem *)item imgUrl:(NSStrin
293297
if (![RCTConvert BOOL:config[@"backButtonHidden"]]) {
294298
if (@available(iOS 14.0, *)) {
295299
CPBarButton *backButton = [[CPBarButton alloc] initWithTitle:@" Back" handler:^(CPBarButton * _Nonnull barButton) {
296-
if (hasListeners) {
300+
if (self->hasListeners) {
297301
[self sendEventWithName:@"backButtonPressed" body:@{@"templateId":templateId}];
298302
}
299303
[self popTemplate:false];
@@ -676,9 +680,11 @@ - (void)updateListRowItemImageWithURL:(CPListImageRowItem *)item imgUrl:(NSStrin
676680
CPTemplate *template = [store findTemplateById:templateId];
677681
if (template) {
678682
CPListTemplate *listTemplate = (CPListTemplate*) template;
679-
[listTemplate updateSections:[self parseSections:sections templateId:templateId]];
683+
NSArray *parsedSections = [self parseSections:sections templateId:templateId];
684+
685+
[listTemplate updateSections:parsedSections];
680686
} else {
681-
NSLog(@"Failed to find template %@", template);
687+
NSLog(@"Failed to find template %@", templateId);
682688
}
683689
}
684690

@@ -1243,7 +1249,9 @@ - (void) applyConfigForMapTemplate:(CPMapTemplate*)mapTemplate templateId:(NSStr
12431249

12441250
for (NSObject *imageObj in slicedArray){
12451251
UIImage *_image = [RCTConvert UIImage:imageObj];
1246-
[_images addObject:_image];
1252+
if (_image) {
1253+
[_images addObject:_image];
1254+
}
12471255
}
12481256
}
12491257
if (@available(iOS 14.0, *)) {

packages/react-native-carplay/src/CarPlay.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export interface InternalCarPlay extends NativeModule {
8686
getMaximumListImageRowItemImageSize(id: string): Promise<ImageSize>;
8787
getTopTemplateId(): Promise<string>;
8888
reactToSelectedResult(status: boolean): void;
89+
updateListTemplate(id: string, config: unknown): void;
8990
updateListTemplateSections(id: string, config: unknown): void;
9091
updateListTemplateItem(id: string, config: unknown): void;
9192
updateListItemById(itemId: string, config: unknown): void;

0 commit comments

Comments
 (0)