birkir / react-native-carplay

CarPlay with React Native
https://birkir.dev/react-native-carplay/
MIT License
642 stars 107 forks source link

How to add new function to this library? #58

Closed vvusts closed 1 year ago

vvusts commented 3 years ago

Hi,

I am trying yo add additional function to library. I want to open another app from my carplay app. So I added:

RCT_EXPORT_METHOD(launchmap:(NSString*)templateId) {
    CPTemplate *template = [[RNCPStore sharedManager] findTemplateById:templateId];
    if (template) {
        CPMapTemplate *mapTemplate = (CPMapTemplate*) template;
        [mapTemplate hideTripPreviews];

        NSString *urlString = @"http://maps.apple.com/?daddr=\(42.3773697),\(7.3966319)&dirflg=d";

        [[RNCPStore sharedManager] openURL:urlString];
    }
}

I also added to MapTemplate.d.ts launchmap(): void; But when I call it from my code: mapTemplate.launchmap(); It doesn't work. What should I do to extend library with additional function?

princekurt commented 3 years ago

So with this library, you have to add it in a few more places. MapTemplate.ts has a place where it actually connects it to the native module. I would do a global search of "updateMapButtons" in your code and look at all the places it is declared. Just insert yours along the chain, and it will work!

tomdye commented 3 years ago

@vvusts you may want to just add an onClick handler to a button / menu within your carplay template and then execute this code in the callback. I may be missing something but I do not believe that the functionality you are suggesting is generic enough to warrant being added to this codebase. Happy to be corrected on this if you feel otherwise.

birkir commented 1 year ago

Have to agree with @tomdye. Feel free to open the issue if you still feel this is something we should consider. Or if there is some specific CarPlay linking things we need to do.