Skip to content

Commit

Permalink
Implement image buttons in CarPlay CPNowPlayingTemplate.
Browse files Browse the repository at this point in the history
  • Loading branch information
janwiebe-jump committed Apr 5, 2024
1 parent 109c0a6 commit 962d214
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions packages/react-native-carplay/ios/RNCarPlay.m
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,23 @@ - (void)updateItemImageWithURL:(CPListItem *)item imgUrl:(NSString *)imgUrlStrin
NSDictionary *body = @{@"templateId":templateId, @"id": _button[@"id"] };
Class buttonClass = buttonTypeMapping[buttonType];
if (buttonClass) {
CPNowPlayingButton *button = [[buttonClass alloc] initWithHandler:^(__kindof CPNowPlayingButton * _Nonnull) {
if (self->hasListeners) {
[self sendEventWithName:@"buttonPressed" body:body];
}
}];
CPNowPlayingButton *button;

if ([buttonType isEqualToString:@"image"]) {
UIImage *_image = [RCTConvert UIImage:[_button objectForKey:@"image"]];
button = [[CPNowPlayingImageButton alloc] initWithImage:_image handler:^(__kindof CPNowPlayingImageButton * _Nonnull) {
if (self->hasListeners) {
[self sendEventWithName:@"buttonPressed" body:body];
}
}];
} else {
button = [[buttonClass alloc] initWithHandler:^(__kindof CPNowPlayingButton * _Nonnull) {
if (self->hasListeners) {
[self sendEventWithName:@"buttonPressed" body:body];
}
}];
}

[buttons addObject:button];
}
}
Expand Down

0 comments on commit 962d214

Please sign in to comment.