@javascriptcommon/react-native-carplay 2.3.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/README.md +633 -0
  2. package/ios/RCTConvert+RNCarPlay.h +19 -0
  3. package/ios/RCTConvert+RNCarPlay.m +95 -0
  4. package/ios/RNCPStore.h +22 -0
  5. package/ios/RNCPStore.m +68 -0
  6. package/ios/RNCarPlay.h +32 -0
  7. package/ios/RNCarPlay.m +1755 -0
  8. package/ios/RNCarPlay.xcodeproj/project.pbxproj +300 -0
  9. package/lib/CarPlay.js +146 -0
  10. package/lib/index.js +63 -0
  11. package/lib/interfaces/Action.js +2 -0
  12. package/lib/interfaces/AlertAction.js +2 -0
  13. package/lib/interfaces/BarButton.js +2 -0
  14. package/lib/interfaces/CarColor.js +2 -0
  15. package/lib/interfaces/GridButton.js +2 -0
  16. package/lib/interfaces/Header.js +2 -0
  17. package/lib/interfaces/ListItem.js +2 -0
  18. package/lib/interfaces/ListItemUpdate.js +2 -0
  19. package/lib/interfaces/ListSection.js +2 -0
  20. package/lib/interfaces/Maneuver.js +2 -0
  21. package/lib/interfaces/MapButton.js +2 -0
  22. package/lib/interfaces/NavigationAlert.js +9 -0
  23. package/lib/interfaces/NavigationInfo.js +2 -0
  24. package/lib/interfaces/NavigationStep.js +2 -0
  25. package/lib/interfaces/Pane.js +2 -0
  26. package/lib/interfaces/PauseReason.js +11 -0
  27. package/lib/interfaces/Place.js +2 -0
  28. package/lib/interfaces/TextConfiguration.js +2 -0
  29. package/lib/interfaces/TimeRemainingColor.js +2 -0
  30. package/lib/interfaces/TravelEstimates.js +2 -0
  31. package/lib/interfaces/VoiceControlState.js +2 -0
  32. package/lib/navigation/NavigationSession.js +53 -0
  33. package/lib/navigation/Trip.js +19 -0
  34. package/lib/templates/ActionSheetTemplate.js +15 -0
  35. package/lib/templates/AlertTemplate.js +15 -0
  36. package/lib/templates/ContactTemplate.js +15 -0
  37. package/lib/templates/GridTemplate.js +16 -0
  38. package/lib/templates/InformationTemplate.js +24 -0
  39. package/lib/templates/ListTemplate.js +67 -0
  40. package/lib/templates/MapTemplate.js +115 -0
  41. package/lib/templates/NowPlayingTemplate.js +17 -0
  42. package/lib/templates/PointOfInterestTemplate.js +16 -0
  43. package/lib/templates/SearchTemplate.js +41 -0
  44. package/lib/templates/TabBarTemplate.js +26 -0
  45. package/lib/templates/Template.js +74 -0
  46. package/lib/templates/VoiceControlTemplate.js +19 -0
  47. package/lib/templates/android/AndroidNavigationBaseTemplate.js +29 -0
  48. package/lib/templates/android/MessageTemplate.js +10 -0
  49. package/lib/templates/android/NavigationTemplate.js +16 -0
  50. package/lib/templates/android/PaneTemplate.js +10 -0
  51. package/lib/templates/android/PlaceListMapTemplate.js +18 -0
  52. package/lib/templates/android/PlaceListNavigationTemplate.js +19 -0
  53. package/lib/templates/android/RoutePreviewNavigationTemplate.js +22 -0
  54. package/package.json +71 -0
  55. package/react-native-carplay.podspec +21 -0
  56. package/src/CarPlay.ts +286 -0
  57. package/src/index.ts +50 -0
  58. package/src/interfaces/Action.ts +15 -0
  59. package/src/interfaces/AlertAction.ts +5 -0
  60. package/src/interfaces/BarButton.ts +41 -0
  61. package/src/interfaces/CarColor.ts +1 -0
  62. package/src/interfaces/GridButton.ts +25 -0
  63. package/src/interfaces/Header.ts +16 -0
  64. package/src/interfaces/ListItem.ts +84 -0
  65. package/src/interfaces/ListItemUpdate.ts +14 -0
  66. package/src/interfaces/ListSection.ts +21 -0
  67. package/src/interfaces/Maneuver.ts +30 -0
  68. package/src/interfaces/MapButton.ts +27 -0
  69. package/src/interfaces/NavigationAlert.ts +46 -0
  70. package/src/interfaces/NavigationInfo.ts +19 -0
  71. package/src/interfaces/NavigationStep.ts +17 -0
  72. package/src/interfaces/Pane.ts +29 -0
  73. package/src/interfaces/PauseReason.ts +7 -0
  74. package/src/interfaces/Place.ts +12 -0
  75. package/src/interfaces/TextConfiguration.ts +5 -0
  76. package/src/interfaces/TimeRemainingColor.ts +1 -0
  77. package/src/interfaces/TravelEstimates.ts +39 -0
  78. package/src/interfaces/VoiceControlState.ts +8 -0
  79. package/src/navigation/NavigationSession.ts +57 -0
  80. package/src/navigation/Trip.ts +36 -0
  81. package/src/templates/ActionSheetTemplate.ts +21 -0
  82. package/src/templates/AlertTemplate.ts +20 -0
  83. package/src/templates/ContactTemplate.ts +45 -0
  84. package/src/templates/GridTemplate.ts +45 -0
  85. package/src/templates/InformationTemplate.ts +42 -0
  86. package/src/templates/ListTemplate.ts +167 -0
  87. package/src/templates/MapTemplate.ts +231 -0
  88. package/src/templates/NowPlayingTemplate.ts +31 -0
  89. package/src/templates/PointOfInterestTemplate.ts +40 -0
  90. package/src/templates/SearchTemplate.ts +70 -0
  91. package/src/templates/TabBarTemplate.ts +56 -0
  92. package/src/templates/Template.ts +164 -0
  93. package/src/templates/VoiceControlTemplate.ts +25 -0
  94. package/src/templates/android/AndroidNavigationBaseTemplate.ts +46 -0
  95. package/src/templates/android/MessageTemplate.ts +19 -0
  96. package/src/templates/android/NavigationTemplate.ts +50 -0
  97. package/src/templates/android/PaneTemplate.ts +16 -0
  98. package/src/templates/android/PlaceListMapTemplate.ts +64 -0
  99. package/src/templates/android/PlaceListNavigationTemplate.ts +57 -0
  100. package/src/templates/android/RoutePreviewNavigationTemplate.ts +66 -0
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Trip = void 0;
4
+ const CarPlay_1 = require("../CarPlay");
5
+ class Trip {
6
+ config;
7
+ id;
8
+ constructor(config) {
9
+ this.config = config;
10
+ if (config.id) {
11
+ this.id = config.id;
12
+ }
13
+ if (!this.id) {
14
+ this.id = `trip-${Date.now()}-${Math.round(Math.random() * Number.MAX_SAFE_INTEGER)}`;
15
+ }
16
+ CarPlay_1.CarPlay.bridge.createTrip(this.id, config);
17
+ }
18
+ }
19
+ exports.Trip = Trip;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ActionSheetTemplate = void 0;
4
+ const Template_1 = require("./Template");
5
+ class ActionSheetTemplate extends Template_1.Template {
6
+ get type() {
7
+ return 'actionsheet';
8
+ }
9
+ get eventMap() {
10
+ return {
11
+ actionButtonPressed: 'onActionButtonPressed',
12
+ };
13
+ }
14
+ }
15
+ exports.ActionSheetTemplate = ActionSheetTemplate;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AlertTemplate = void 0;
4
+ const Template_1 = require("./Template");
5
+ class AlertTemplate extends Template_1.Template {
6
+ get type() {
7
+ return 'alert';
8
+ }
9
+ get eventMap() {
10
+ return {
11
+ actionButtonPressed: 'onActionButtonPressed',
12
+ };
13
+ }
14
+ }
15
+ exports.AlertTemplate = AlertTemplate;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ContactTemplate = void 0;
4
+ const Template_1 = require("./Template");
5
+ class ContactTemplate extends Template_1.Template {
6
+ get type() {
7
+ return 'contact';
8
+ }
9
+ get eventMap() {
10
+ return {
11
+ buttonPressed: 'onButtonPressed',
12
+ };
13
+ }
14
+ }
15
+ exports.ContactTemplate = ContactTemplate;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GridTemplate = void 0;
4
+ const Template_1 = require("./Template");
5
+ class GridTemplate extends Template_1.Template {
6
+ get type() {
7
+ return 'grid';
8
+ }
9
+ get eventMap() {
10
+ return {
11
+ gridButtonPressed: 'onButtonPressed',
12
+ backButtonPressed: 'onBackButtonPressed',
13
+ };
14
+ }
15
+ }
16
+ exports.GridTemplate = GridTemplate;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InformationTemplate = void 0;
4
+ const Template_1 = require("./Template");
5
+ const CarPlay_1 = require("../CarPlay");
6
+ class InformationTemplate extends Template_1.Template {
7
+ get type() {
8
+ return 'information';
9
+ }
10
+ get eventMap() {
11
+ return {
12
+ actionButtonPressed: 'onActionButtonPressed',
13
+ };
14
+ }
15
+ updateInformationTemplateItems = (items) => {
16
+ this.config.items = items;
17
+ return CarPlay_1.CarPlay.bridge.updateInformationTemplateItems(this.id, this.parseConfig(items));
18
+ };
19
+ updateInformationTemplateActions = (actions) => {
20
+ this.config.actions = actions;
21
+ return CarPlay_1.CarPlay.bridge.updateInformationTemplateActions(this.id, this.parseConfig(actions));
22
+ };
23
+ }
24
+ exports.InformationTemplate = InformationTemplate;
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ListTemplate = void 0;
4
+ const CarPlay_1 = require("../CarPlay");
5
+ const Template_1 = require("./Template");
6
+ /**
7
+ * A hierarchical list of menu items can be displayed on the CarPlay screen using a list template.
8
+ *
9
+ * The List Template allows navigation apps to present a hierarchical list of menu items. It includes a navigation bar and a list view.
10
+ *
11
+ * The navigation bar includes a title, and up to two (2) leading buttons and two (2) trailing buttons. You can customize the appearance of these buttons with icons or text.
12
+ *
13
+ * Each item in the list view may include an icon, title, subtitle, and an optional disclosure indicator indicating the presence of a submenu. The depth of the menu hierarchy may not exceed 5 levels. Note that some cars limit the total number of items that may be shown in a list.
14
+ */
15
+ class ListTemplate extends Template_1.Template {
16
+ config;
17
+ get type() {
18
+ return 'list';
19
+ }
20
+ get eventMap() {
21
+ return {
22
+ backButtonPressed: 'onBackButtonPressed',
23
+ };
24
+ }
25
+ constructor(config) {
26
+ super(config);
27
+ this.config = config;
28
+ CarPlay_1.CarPlay.emitter.addListener('didSelectListItem', e => {
29
+ if (config.onItemSelect && e.templateId === this.id) {
30
+ void Promise.resolve(config.onItemSelect(e)).then(() => {
31
+ CarPlay_1.CarPlay.bridge.reactToSelectedResult(true);
32
+ });
33
+ }
34
+ });
35
+ CarPlay_1.CarPlay.emitter.addListener('didSelectRowItem', e => {
36
+ if (config.onRowItemSelect && e.templateId === this.id) {
37
+ void Promise.resolve(config.onRowItemSelect(e)).then(() => {
38
+ CarPlay_1.CarPlay.bridge.reactToSelectedResult(true);
39
+ });
40
+ }
41
+ });
42
+ CarPlay_1.CarPlay.emitter.addListener('templateLoaded', e => {
43
+ if (config.onTemplateLoaded && e.templateId === this.id) {
44
+ void Promise.resolve(config.onTemplateLoaded());
45
+ }
46
+ });
47
+ }
48
+ updateSections = (sections) => {
49
+ return CarPlay_1.CarPlay.bridge.updateListTemplateSections(this.id, this.parseConfig(sections));
50
+ };
51
+ updateListTemplateItem = (config) => {
52
+ return CarPlay_1.CarPlay.bridge.updateListTemplateItem(this.id, this.parseConfig(config));
53
+ };
54
+ updateListTemplateRowItems = (config) => {
55
+ return CarPlay_1.CarPlay.bridge.updateListTemplateRowItems(this.id, this.parseConfig(config));
56
+ };
57
+ getMaximumListItemCount() {
58
+ return CarPlay_1.CarPlay.bridge.getMaximumListItemCount(this.id);
59
+ }
60
+ getMaximumListSectionCount() {
61
+ return CarPlay_1.CarPlay.bridge.getMaximumListSectionCount(this.id);
62
+ }
63
+ getMaximumRowItemsCount() {
64
+ return CarPlay_1.CarPlay.bridge.getMaximumRowItemsCount(this.id);
65
+ }
66
+ }
67
+ exports.ListTemplate = ListTemplate;
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MapTemplate = void 0;
4
+ const react_native_1 = require("react-native");
5
+ const CarPlay_1 = require("../CarPlay");
6
+ const NavigationSession_1 = require("../navigation/NavigationSession");
7
+ const Template_1 = require("./Template");
8
+ /**
9
+ * The Map Template is a control layer that appears as an overlay over the base view and allows you to present user controls.
10
+ *
11
+ * The control layer consists of a navigation bar and map buttons. By default, the navigation bar appears when the user interacts with the app, and disappears after a period of inactivity.
12
+ *
13
+ * The navigation bar includes up to two leading buttons and two trailing buttons. You can customize the appearance of these buttons with icons or text.
14
+ *
15
+ * The control layer may also include up to four map buttons. The map buttons are always shown as icons.
16
+ *
17
+ * Navigation apps enter panning mode, zoom in or out, and perform other functions by responding to user actions on these buttons.
18
+ */
19
+ class MapTemplate extends Template_1.Template {
20
+ config;
21
+ get type() {
22
+ return 'map';
23
+ }
24
+ get eventMap() {
25
+ return {
26
+ alertActionPressed: 'onAlertActionPressed',
27
+ mapButtonPressed: 'onMapButtonPressed',
28
+ panWithDirection: 'onPanWithDirection',
29
+ panBeganWithDirection: 'onPanBeganWithDirection',
30
+ panEndedWithDirection: 'onPanEndedWithDirection',
31
+ selectedPreviewForTrip: 'onSelectedPreviewForTrip',
32
+ didCancelNavigation: 'onDidCancelNavigation',
33
+ startedTrip: 'onStartedTrip',
34
+ };
35
+ }
36
+ constructor(config) {
37
+ super(config);
38
+ this.config = config;
39
+ if (config.component) {
40
+ react_native_1.AppRegistry.registerComponent(this.id, () => config.component);
41
+ }
42
+ const callbackFn = react_native_1.Platform.select({
43
+ android: ({ error } = {}) => {
44
+ error && console.error(error);
45
+ },
46
+ });
47
+ CarPlay_1.CarPlay.bridge.createTemplate(this.id, this.parseConfig({ type: this.type, ...config, render: true }), callbackFn);
48
+ }
49
+ /**
50
+ * Begins guidance for a trip.
51
+ *
52
+ * Keep a reference to the navigation session to perform guidance updates.
53
+ * @param trip Trip class instance
54
+ */
55
+ async startNavigationSession(trip) {
56
+ const res = await CarPlay_1.CarPlay.bridge.startNavigationSession(this.id, trip.id);
57
+ return new NavigationSession_1.NavigationSession(res.navigationSessionId, trip, this);
58
+ }
59
+ updateTravelEstimates(trip, travelEstimates, timeRemainingColor = 0) {
60
+ if (!travelEstimates.distanceUnits) {
61
+ travelEstimates.distanceUnits = 'kilometers';
62
+ }
63
+ CarPlay_1.CarPlay.bridge.updateTravelEstimatesForTrip(this.id, trip.id, travelEstimates, timeRemainingColor);
64
+ }
65
+ /**
66
+ * Update MapTemplate configuration
67
+ */
68
+ updateConfig(config) {
69
+ this.config = config;
70
+ CarPlay_1.CarPlay.bridge.updateMapTemplateConfig(this.id, this.parseConfig(config));
71
+ }
72
+ updateMapButtons(mapButtons) {
73
+ this.config.mapButtons = mapButtons;
74
+ CarPlay_1.CarPlay.bridge.updateMapTemplateMapButtons(this.id, this.parseConfig(mapButtons));
75
+ }
76
+ /**
77
+ * Hides the display of trip previews.
78
+ */
79
+ hideTripPreviews() {
80
+ CarPlay_1.CarPlay.bridge.hideTripPreviews(this.id);
81
+ }
82
+ showTripPreviews(tripPreviews, textConfiguration = {}) {
83
+ CarPlay_1.CarPlay.bridge.showTripPreviews(this.id, tripPreviews.map(trip => trip.id), textConfiguration);
84
+ }
85
+ showRouteChoicesPreviewForTrip(trip, textConfiguration = {}) {
86
+ CarPlay_1.CarPlay.bridge.showRouteChoicesPreviewForTrip(this.id, trip.id, textConfiguration);
87
+ }
88
+ presentNavigationAlert(config, animated = true) {
89
+ CarPlay_1.CarPlay.bridge.presentNavigationAlert(this.id, config, animated);
90
+ }
91
+ dismissNavigationAlert(animated = true) {
92
+ CarPlay_1.CarPlay.bridge.dismissNavigationAlert(this.id, animated);
93
+ }
94
+ /**
95
+ * Shows the panning interface over the map.
96
+ *
97
+ * Calling this method while displaying the panning interface has no effect.
98
+ *
99
+ * While showing the panning interface, the system hides all map buttons. The system doesn't provide a button to dismiss the panning interface. Instead, you must provide a map button in the navigation bar that the user taps to dismiss the panning interface.
100
+ * @param animated A Boolean value that determines whether to animate the panning interface.
101
+ */
102
+ showPanningInterface(animated = false) {
103
+ CarPlay_1.CarPlay.bridge.showPanningInterface(this.id, animated);
104
+ }
105
+ /**
106
+ * Dismisses the panning interface.
107
+ *
108
+ * When dismissing the panning interface, the system shows the previously hidden map buttons.
109
+ * @param animated A Boolean value that determines whether to animate the dismissal of the panning interface.
110
+ */
111
+ dismissPanningInterface(animated = false) {
112
+ CarPlay_1.CarPlay.bridge.dismissPanningInterface(this.id, animated);
113
+ }
114
+ }
115
+ exports.MapTemplate = MapTemplate;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NowPlayingTemplate = void 0;
4
+ const Template_1 = require("./Template");
5
+ class NowPlayingTemplate extends Template_1.Template {
6
+ get type() {
7
+ return 'nowplaying';
8
+ }
9
+ get eventMap() {
10
+ return {
11
+ albumArtistButtonPressed: 'onAlbumArtistButtonPressed',
12
+ upNextButtonPressed: 'onUpNextButtonPressed',
13
+ buttonPressed: 'onButtonPressed',
14
+ };
15
+ }
16
+ }
17
+ exports.NowPlayingTemplate = NowPlayingTemplate;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PointOfInterestTemplate = void 0;
4
+ const Template_1 = require("./Template");
5
+ class PointOfInterestTemplate extends Template_1.Template {
6
+ get type() {
7
+ return 'poi';
8
+ }
9
+ get eventMap() {
10
+ return {
11
+ didSelectPointOfInterest: 'onPointOfInterestSelect',
12
+ didChangeMapRegion: 'onChangeMapRegion',
13
+ };
14
+ }
15
+ }
16
+ exports.PointOfInterestTemplate = PointOfInterestTemplate;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SearchTemplate = void 0;
4
+ const CarPlay_1 = require("../CarPlay");
5
+ const Template_1 = require("./Template");
6
+ const react_native_1 = require("react-native");
7
+ class SearchTemplate extends Template_1.Template {
8
+ config;
9
+ get type() {
10
+ return 'search';
11
+ }
12
+ get eventMap() {
13
+ return {
14
+ searchButtonPressed: 'onSearchButtonPressed',
15
+ };
16
+ }
17
+ constructor(config) {
18
+ // parse out any images in the results
19
+ super(config);
20
+ this.config = config;
21
+ CarPlay_1.CarPlay.emitter.addListener('updatedSearchText', (e) => {
22
+ if (config.onSearch && e.templateId === this.id) {
23
+ void Promise.resolve(config.onSearch(e.searchText)).then((result = []) => {
24
+ if (react_native_1.Platform.OS === 'ios') {
25
+ const parsedResults = result.map(item => ({
26
+ ...item,
27
+ image: item.image ? react_native_1.Image.resolveAssetSource(item.image) : undefined,
28
+ }));
29
+ CarPlay_1.CarPlay.bridge.reactToUpdatedSearchText(parsedResults);
30
+ }
31
+ });
32
+ }
33
+ });
34
+ CarPlay_1.CarPlay.emitter.addListener('selectedResult', (e) => {
35
+ if (config.onItemSelect && e.templateId === this.id) {
36
+ void Promise.resolve(config.onItemSelect(e)).then(() => react_native_1.Platform.OS === 'ios' && CarPlay_1.CarPlay.bridge.reactToSelectedResult(true));
37
+ }
38
+ });
39
+ }
40
+ }
41
+ exports.SearchTemplate = SearchTemplate;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TabBarTemplate = void 0;
4
+ const CarPlay_1 = require("../CarPlay");
5
+ const Template_1 = require("./Template");
6
+ /**/
7
+ class TabBarTemplate extends Template_1.Template {
8
+ config;
9
+ get type() {
10
+ return 'tabbar';
11
+ }
12
+ constructor(config) {
13
+ super(config);
14
+ this.config = config;
15
+ CarPlay_1.CarPlay.emitter.addListener('didSelectTemplate', (e) => {
16
+ if (config.onTemplateSelect && e.templateId === this.id) {
17
+ config.onTemplateSelect(config.templates.find(tpl => tpl.id === e.selectedTemplateId), e);
18
+ }
19
+ });
20
+ }
21
+ updateTemplates = (config) => {
22
+ this.config = config;
23
+ return CarPlay_1.CarPlay.bridge.updateTabBarTemplates(this.id, this.parseConfig(config));
24
+ };
25
+ }
26
+ exports.TabBarTemplate = TabBarTemplate;
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Template = void 0;
4
+ const react_native_1 = require("react-native");
5
+ const CarPlay_1 = require("../CarPlay");
6
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
7
+ const resolveAssetSource = require('react-native/Libraries/Image/resolveAssetSource');
8
+ class Template {
9
+ config;
10
+ get type() {
11
+ return 'unset';
12
+ }
13
+ id;
14
+ get eventMap() {
15
+ return {};
16
+ }
17
+ constructor(config) {
18
+ this.config = config;
19
+ if (config.id) {
20
+ this.id = config.id;
21
+ }
22
+ if (!this.id) {
23
+ this.id = `${this.type}-${Date.now()}-${Math.round(Math.random() * Number.MAX_SAFE_INTEGER)}`;
24
+ }
25
+ const eventMap = {
26
+ barButtonPressed: 'onBarButtonPressed',
27
+ didAppear: 'onDidAppear',
28
+ didDisappear: 'onDidDisappear',
29
+ willAppear: 'onWillAppear',
30
+ willDisappear: 'onWillDisappear',
31
+ ...(this.eventMap || {}),
32
+ };
33
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
34
+ Object.entries(eventMap).forEach(([eventName, callbackName]) => {
35
+ CarPlay_1.CarPlay.emitter.addListener(eventName, (e) => {
36
+ const configEventName = callbackName;
37
+ if (config[configEventName] && e.templateId === this.id) {
38
+ config[configEventName]?.(e);
39
+ }
40
+ });
41
+ });
42
+ if (this.type !== 'map') {
43
+ const callbackFn = react_native_1.Platform.select({
44
+ android: ({ error } = {}) => {
45
+ error && console.error(error);
46
+ },
47
+ });
48
+ CarPlay_1.CarPlay.bridge.createTemplate(this.id, this.parseConfig({ type: this.type, ...config }), callbackFn);
49
+ }
50
+ }
51
+ updateTemplate = (config) => {
52
+ console.log('LETSGO!', config, this.type);
53
+ CarPlay_1.CarPlay.bridge.updateTemplate(this.id, this.parseConfig({ type: this.type, ...config }));
54
+ };
55
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
56
+ parseConfig(config) {
57
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
58
+ function traverse(obj) {
59
+ for (const i in obj) {
60
+ if (obj[i] !== null && typeof obj[i] === 'object') {
61
+ traverse(obj[i]);
62
+ }
63
+ if (String(i).match(/[Ii]mage$/)) {
64
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
65
+ obj[i] = resolveAssetSource(obj[i]);
66
+ }
67
+ }
68
+ }
69
+ const result = JSON.parse(JSON.stringify(config));
70
+ traverse(result);
71
+ return result;
72
+ }
73
+ }
74
+ exports.Template = Template;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VoiceControlTemplate = void 0;
4
+ const CarPlay_1 = require("../CarPlay");
5
+ const Template_1 = require("./Template");
6
+ /**
7
+ * Displays a voice control indicator on the CarPlay screen.
8
+ *
9
+ * CarPlay navigation apps must show the voice control template during audio input.
10
+ */
11
+ class VoiceControlTemplate extends Template_1.Template {
12
+ get type() {
13
+ return 'voicecontrol';
14
+ }
15
+ activateVoiceControlState(identifier) {
16
+ CarPlay_1.CarPlay.bridge.activateVoiceControlState(this.id, identifier);
17
+ }
18
+ }
19
+ exports.VoiceControlTemplate = VoiceControlTemplate;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AndroidNavigationBaseTemplate = void 0;
4
+ const react_native_1 = require("react-native");
5
+ const Template_1 = require("../Template");
6
+ const CarPlay_1 = require("../../CarPlay");
7
+ class AndroidNavigationBaseTemplate extends Template_1.Template {
8
+ config;
9
+ get eventMap() {
10
+ return {
11
+ didShowPanningInterface: 'onDidShowPanningInterface',
12
+ didDismissPanningInterface: 'onDidDismissPanningInterface',
13
+ };
14
+ }
15
+ constructor(config) {
16
+ super(config);
17
+ this.config = config;
18
+ if (config.component) {
19
+ react_native_1.AppRegistry.registerComponent(this.id, () => config.component);
20
+ }
21
+ const callbackFn = react_native_1.Platform.select({
22
+ android: ({ error } = {}) => {
23
+ error && console.error(error);
24
+ },
25
+ });
26
+ CarPlay_1.CarPlay.bridge.createTemplate(this.id, this.parseConfig({ type: this.type, ...config, render: true }), callbackFn);
27
+ }
28
+ }
29
+ exports.AndroidNavigationBaseTemplate = AndroidNavigationBaseTemplate;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MessageTemplate = void 0;
4
+ const Template_1 = require("../Template");
5
+ class MessageTemplate extends Template_1.Template {
6
+ get type() {
7
+ return 'message';
8
+ }
9
+ }
10
+ exports.MessageTemplate = MessageTemplate;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NavigationTemplate = void 0;
4
+ const AndroidNavigationBaseTemplate_1 = require("./AndroidNavigationBaseTemplate");
5
+ /**
6
+ * A template for showing navigation information.
7
+ * This template has two independent sections which can be updated:
8
+ * - Navigation information such as routing instructions or navigation-related messages.
9
+ * - Travel estimates to the destination.
10
+ */
11
+ class NavigationTemplate extends AndroidNavigationBaseTemplate_1.AndroidNavigationBaseTemplate {
12
+ get type() {
13
+ return 'navigation';
14
+ }
15
+ }
16
+ exports.NavigationTemplate = NavigationTemplate;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PaneTemplate = void 0;
4
+ const Template_1 = require("../Template");
5
+ class PaneTemplate extends Template_1.Template {
6
+ get type() {
7
+ return 'pane';
8
+ }
9
+ }
10
+ exports.PaneTemplate = PaneTemplate;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PlaceListMapTemplate = void 0;
4
+ const AndroidNavigationBaseTemplate_1 = require("./AndroidNavigationBaseTemplate");
5
+ /**
6
+ * A template that displays a map along with a list of places.
7
+ * The map can display markers corresponding to the places in the list. See setItemList for details.
8
+ * Template Restrictions In regards to template refreshes, as described in onGetTemplate, this template is considered a refresh of a previous one if:
9
+ * - The previous template is in a loading state (see setLoading, or
10
+ * - The template title has not changed, and the number of rows and the title (not counting spans) of each row between the previous and new ItemLists have not changed.
11
+ * - The template is sent in response to a user-initiated content refresh request. (see setOnContentRefreshListener.
12
+ */
13
+ class PlaceListMapTemplate extends AndroidNavigationBaseTemplate_1.AndroidNavigationBaseTemplate {
14
+ get type() {
15
+ return 'place-list-map';
16
+ }
17
+ }
18
+ exports.PlaceListMapTemplate = PlaceListMapTemplate;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PlaceListNavigationTemplate = void 0;
4
+ const AndroidNavigationBaseTemplate_1 = require("./AndroidNavigationBaseTemplate");
5
+ /**
6
+ * A template that supports showing a list of places alongside a custom drawn map.
7
+ * The template itself does not expose a drawing surface. In order to draw on the canvas, use setSurfaceCallback.
8
+ * Template Restrictions In regards to template refreshes, as described in onGetTemplate, this template is considered a refresh of a previous one if:
9
+ * - The previous template is in a loading state (see setLoading, or
10
+ * - The template title has not changed, and the number of rows and the title (not counting spans) of each row between the previous and new ItemLists have not changed.
11
+ * - The template is sent in response to a user-initiated content refresh request. (see setOnContentRefreshListener.
12
+ * In order to use this template your car app MUST declare that it uses the **androidx.car.app.NAVIGATION_TEMPLATES** permission in the manifest.
13
+ */
14
+ class PlaceListNavigationTemplate extends AndroidNavigationBaseTemplate_1.AndroidNavigationBaseTemplate {
15
+ get type() {
16
+ return 'place-navigation-map';
17
+ }
18
+ }
19
+ exports.PlaceListNavigationTemplate = PlaceListNavigationTemplate;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RoutePreviewNavigationTemplate = void 0;
4
+ const AndroidNavigationBaseTemplate_1 = require("./AndroidNavigationBaseTemplate");
5
+ /**
6
+ * A template that supports showing a list of routes alongside a custom drawn map.
7
+ * The list must have its ItemList.OnSelectedListener set, and the template must have its navigate action set (see setNavigateAction). These are used in conjunction to inform the app that:
8
+ * - A route has been selected. The app should also highlight the route on the map surface.
9
+ * - A navigate action has been triggered. The app should begin navigation using the selected route.
10
+ * The template itself does not expose a drawing surface. In order to draw on the canvas, use setSurfaceCallback.
11
+ * Template Restrictions In regards to template refreshes, as described in onGetTemplate, this template is considered a refresh of a previous one if:
12
+ * - The previous template is in a loading state (see setLoading, or
13
+ * - The template title has not changed, and the number of rows and the title (not counting spans) of each row between the previous and new ItemLists have not changed.
14
+ * Note that specifically, this means the app should not use this template to continuously refresh the routes as the car moves.
15
+ * In order to use this template your car app MUST declare that it uses the **androidx.car.app.NAVIGATION_TEMPLATES** permission in the manifest.
16
+ */
17
+ class RoutePreviewNavigationTemplate extends AndroidNavigationBaseTemplate_1.AndroidNavigationBaseTemplate {
18
+ get type() {
19
+ return 'route-preview-navigation';
20
+ }
21
+ }
22
+ exports.RoutePreviewNavigationTemplate = RoutePreviewNavigationTemplate;