Skip to content

Commit

Permalink
Merge pull request #178 from janwiebe-jump/feature/nowplaying-image-b…
Browse files Browse the repository at this point in the history
…utton

Implement image button in CarPlay CPNowPlayingTemplate.
  • Loading branch information
birkir authored Jun 12, 2024
2 parents 923f96b + ed383a9 commit 313193c
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 @@ -319,11 +319,23 @@ - (void)updateListRowItemImageWithURL:(CPListImageRowItem *)item imgUrl:(NSStrin
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 313193c

Please sign in to comment.