Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

didPresssMenuItem is not an available event on iOS #161

Closed
janwiebe-jump opened this issue Dec 12, 2023 · 2 comments · Fixed by #162
Closed

didPresssMenuItem is not an available event on iOS #161

janwiebe-jump opened this issue Dec 12, 2023 · 2 comments · Fixed by #162
Labels
bug Something isn't working

Comments

@janwiebe-jump
Copy link
Contributor

Describe the bug
Error:
didPressMenuItem is not a supporte event type for RNCarPlay

To Reproduce
Steps to reproduce the behavior:

  1. Use an iOS device, try to start the example project

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots/Videos
If applicable, add screenshots to help explain your problem.

CarPlay (please complete the following information):

Android Auto (please complete the following information):

  • Device: [e.g. Pixel 8 / emulator]
  • Android Version: [e.g. iOS8.1]
  • RNCarPlay version [e.g. 2.4.0]

Additional context

@janwiebe-jump janwiebe-jump added the bug Something isn't working label Dec 12, 2023
janwiebe-jump added a commit to janwiebe-jump/react-native-carplay that referenced this issue Dec 12, 2023
@uzegonemad
Copy link
Contributor

I looked through the source and I don't think this method is registered on Android either.

@birkir Did you have a vision in mind with didPressMenuItem? It doesn't actually appear to be implemented on Android or iOS.

@thomas-rx
Copy link

thomas-rx commented Feb 15, 2024

Fixed on #162.

Patch :

diff --git a/node_modules/react-native-carplay/src/CarPlay.ts b/node_modules/react-native-carplay/src/CarPlay.ts
index 4694d0a..c9e074f 100644
--- a/node_modules/react-native-carplay/src/CarPlay.ts
+++ b/node_modules/react-native-carplay/src/CarPlay.ts
@@ -1,4 +1,4 @@
-import { ImageSourcePropType, NativeEventEmitter, NativeModule, NativeModules } from 'react-native';
+import { ImageSourcePropType, NativeEventEmitter, NativeModule, NativeModules, Platform } from 'react-native';
 import { ActionSheetTemplate } from './templates/ActionSheetTemplate';
 import { AlertTemplate } from './templates/AlertTemplate';
 import { ContactTemplate } from './templates/ContactTemplate';
@@ -22,6 +22,8 @@ import { TripConfig } from './navigation/Trip';
 import { TimeRemainingColor } from './interfaces/TimeRemainingColor';
 import { TextConfiguration } from './interfaces/TextConfiguration';
 import { Action } from './interfaces/Action';
+import { MessageTemplate } from './templates/android/MessageTemplate';
+import { PaneTemplate } from './templates/android/PaneTemplate';
 
 export interface InternalCarPlay extends NativeModule {
   checkForConnection(): void;
@@ -35,9 +37,9 @@ export interface InternalCarPlay extends NativeModule {
   enableNowPlaying(enabled: boolean): void;
   updateManeuversNavigationSession(id: string, x: Maneuver[]): void;
   updateTravelEstimatesNavigationSession(
-    id: string,
-    index: number,
-    estimates: TravelEstimates,
+      id: string,
+      index: number,
+      estimates: TravelEstimates,
   ): void;
   cancelNavigationSession(id: string): void;
   finishNavigationSession(id: string): void;
@@ -49,17 +51,17 @@ export interface InternalCarPlay extends NativeModule {
   updateTemplate(id: string, config: unknown): void;
   invalidate(id: string): void;
   startNavigationSession(
-    id: string,
-    tripId: string,
+      id: string,
+      tripId: string,
   ): Promise<{
     tripId: string;
     navigationSessionId: string;
   }>;
   updateTravelEstimatesForTrip(
-    id: string,
-    tripId: string,
-    travelEstimates: TravelEstimates,
-    timeRemainingColor: TimeRemainingColor,
+      id: string,
+      tripId: string,
+      travelEstimates: TravelEstimates,
+      timeRemainingColor: TimeRemainingColor,
   ): void;
   updateMapTemplateConfig(id: string, config: unknown): void;
   updateMapTemplateMapButtons(id: string, config: unknown): void;
@@ -94,18 +96,20 @@ export interface InternalCarPlay extends NativeModule {
 const { RNCarPlay } = NativeModules as { RNCarPlay: InternalCarPlay };
 
 export type PushableTemplates =
-  | MapTemplate
-  | SearchTemplate
-  | GridTemplate
-  | PointOfInterestTemplate
-  | ListTemplate
-  | InformationTemplate
-  | ContactTemplate
-  | NowPlayingTemplate
-  | NavigationTemplate
-  | PlaceListMapTemplate
-  | PlaceListNavigationTemplate
-  | RoutePreviewNavigationTemplate;
+    | MapTemplate
+    | SearchTemplate
+    | GridTemplate
+    | PointOfInterestTemplate
+    | ListTemplate
+    | MessageTemplate
+    | PaneTemplate
+    | InformationTemplate
+    | ContactTemplate
+    | NowPlayingTemplate
+    | NavigationTemplate
+    | PlaceListMapTemplate
+    | PlaceListNavigationTemplate
+    | RoutePreviewNavigationTemplate;
 
 export type PresentableTemplates = AlertTemplate | ActionSheetTemplate | VoiceControlTemplate;
 
@@ -157,11 +161,13 @@ export class CarPlayInterface {
         callback();
       });
     });
-    this.emitter.addListener('didPressMenuItem', e => {
-      if (e?.title === 'Reload Android Auto') {
-        this.bridge.reload();
-      }
-    });
+    if (Platform.OS === 'android') {
+      this.emitter.addListener('didPressMenuItem', e => {
+        if (e?.title === 'Reload Android Auto') {
+          this.bridge.reload();
+        }
+      });
+    }
 
     // check if already connected this will fire any 'didConnect' events
     // if a connected is already present.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants