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

feat: add carplay and android auto support #255

Merged
merged 29 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
900bdf7
feat: navigation support for auto
jokerttu Sep 3, 2024
f72c949
fix: fix ios build
illuminati1911 Sep 4, 2024
04e31ab
feat: change carplay map init setup to match android auto
illuminati1911 Sep 4, 2024
afce7d4
feat: added android auto base screen
illuminati1911 Sep 4, 2024
671cbd6
fix: revert keys.plist removal from the project
jokerttu Sep 4, 2024
2fcbf24
fix: fix missing windows ref in app delegate
illuminati1911 Sep 5, 2024
80f6785
feat: support for navigation auto custom events
jokerttu Sep 6, 2024
049e91e
feat: separate ios build targets
jokerttu Sep 6, 2024
b220b83
chore: add new carplay build target to podfile
illuminati1911 Sep 9, 2024
e1b3214
fix: event transformer callback response handling
jokerttu Sep 9, 2024
1a64117
feat: notify on auto screen availibility changes (#5)
jokerttu Sep 9, 2024
c2ecac7
fix: fix carplay session attach management
illuminati1911 Sep 10, 2024
4baf805
feat: add basecarscenedelegate and enable panning for carlay
illuminati1911 Sep 10, 2024
dda6163
refactor: cleanup unused code from podfile
illuminati1911 Sep 10, 2024
d061791
chore: format codebase
jokerttu Sep 12, 2024
db1e63b
Merge remote-tracking branch 'codemate/main' into feat/navigation-for…
jokerttu Sep 12, 2024
3d8f48e
fix: add missing import to NavViewFragment.java
jokerttu Sep 12, 2024
37dd316
fix: solve merge conflicts
illuminati1911 Sep 13, 2024
13c6daa
docs: initial carplay docs wip
illuminati1911 Sep 16, 2024
d9e9a8e
docs: initial android auto docs wip
illuminati1911 Sep 18, 2024
7270b10
docs: update readme for android auto and carplay doc links
illuminati1911 Sep 19, 2024
7702c2f
Merge branch 'main' into feat/navigation-for-auto
illuminati1911 Sep 19, 2024
d4ccf86
docs: android auto documentation improvements
illuminati1911 Sep 23, 2024
01776c3
fix: move android auto template invalidation to example app
illuminati1911 Sep 24, 2024
580ad6f
chore: minor improvements to documentation and code quality
jokerttu Sep 27, 2024
0384d9c
Merge branch 'main' into feat/navigation-for-auto
jokerttu Oct 4, 2024
13da0ec
refactor: minor refactoring and fixes for android auto
illuminati1911 Oct 7, 2024
6492783
Merge branch 'main' into feat/navigation-for-auto
jokerttu Oct 14, 2024
00d3d03
Merge branch 'main' into feat/navigation-for-auto
jokerttu Oct 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions ANDROIDAUTO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# Navigation for Android Auto

This guide explains how to enable and integrate Android Auto with the React Native Navigation SDK.

## Requirements

- Android device
- Android Auto test device or Android Automotive OS emulator

## Setup

Refer to the [Android for Cars developer documentation](https://developer.android.com/training/cars) to understand how the Android Auto works and to complete the initial setup. Key steps include:

- Installing Android for Cars App Library.
- Configuring your app's manifest file to include Android Auto.
- Declaring a minimum car-app level in your manifest.
- Creating CarApService and session
jokerttu marked this conversation as resolved.
Show resolved Hide resolved

For all the steps above, you can refer to the Android example application. for guidance
jokerttu marked this conversation as resolved.
Show resolved Hide resolved

### Screen for Android Auto

Once your project is configured accordingly, and you are ready to build the screen for Android Auto, you can leverage the `AndroidAutoBaseScreen` provided by the SDK. This base class simplifies the setup by handling initialization, teardown, and rendering the map on the Android Auto display.

Please refer to the `SampleAndroidAutoScreen.java` file in the Android example app for guidance.

To customize the Android Auto experience, override the `onGetTemplate` method in your custom AndroidAutoScreen class, providing your own `Template`:

```java
@NonNull
@Override
public Template onGetTemplate() {
/** ... */
@SuppressLint("MissingPermission")
NavigationTemplate.Builder navigationTemplateBuilder =
new NavigationTemplate.Builder()
.setActionStrip(
new ActionStrip.Builder()
.addAction(
new Action.Builder()
.setTitle("Re-center")
.setOnClickListener(
() -> {
if (mGoogleMap == null) return;
mGoogleMap.followMyLocation(GoogleMap.CameraPerspective.TILTED);
})
.build())
.addAction(
new Action.Builder()
.setTitle("Custom event")
.setOnClickListener(
() -> {
WritableMap map = Arguments.createMap();
map.putString("sampleKey", "sampleValue");
sendCustomEvent("sampleEvent", map);
})
.build())
.build())
.setMapActionStrip(new ActionStrip.Builder().addAction(Action.PAN).build());
/** ... */
}
```

For advanced customization, you can bypass the base class and implement your own screen by inheriting `Screen`. You can use the provided `AndroidAutoBaseScreen` base class as a reference on how to do that.

### React Native specific setup

On the React Native side, you can use the `useNavigationAuto` hook to interface with the Android Auto instance. The `mapViewAutoController` allows you to call map functions on the Android Auto map, and you can manage listeners using the provided functions.

```tsx
const {
mapViewAutoController,
addListeners: addAutoListener,
removeListeners: removeAutoListeners,
} = useNavigationAuto();

const navigationAutoCallbacks: NavigationAutoCallbacks = useMemo(
() => ({
onCustomNavigationAutoEvent: (event: CustomNavigationAutoEvent) => {
console.log('onCustomNavigationAutoEvent:', event);
},
onAutoScreenAvailabilityChanged: (available: boolean) => {
console.log('onAutoScreenAvailabilityChanged:', available);
setMapViewAutoAvailable(available);
},
}),
[]
);

const setMapType = (mapType: MapType) => {
console.log('setMapType', mapType);
mapViewAutoController.setMapType(mapType);
};
```

For a more detailed example, refer to the `NavigationScreen.tsx` in the React Native example application.

## Example Project

For a fully functional Android Auto implementation, check out the `SampleApp` Android Studio project.
jokerttu marked this conversation as resolved.
Show resolved Hide resolved
86 changes: 86 additions & 0 deletions CARPLAY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Navigation for Apple CarPlay

This guide explains how to enable and integrate Apple CarPlay with the React Native Navigation SDK.

## Requirements

- iOS device or iOS simulator (iOS 14.0+)
- CarPlay Simulator
- CarPlay entitlement for your application (provided by Apple)

## Setup

Refer to the [Apple CarPlay Developer Guide](https://developer.apple.com/carplay/) to understand how CarPlay works and to complete the initial setup. Key steps include:

- Adding the CarPlay entitlement to your Xcode project.
- Creating a separate scene for the CarPlay map and enabling support for multiple scenes.

### SceneDelegate for CarPlay

Once your project is configured to support multiple scenes, and you are setting up a dedicated scene for CarPlay, you can leverage the `BaseCarSceneDelegate` provided by the SDK. This base class simplifies the setup by handling initialization, teardown, and rendering the map on the CarPlay display.

Please refer to the `CarSceneDelegate.h` and `CarSceneDelegate.m` files in the iOS example app for guidance.

To customize the CarPlay experience, override the `getTemplate` method in your custom `CarSceneDelegate` class, providing your own `CPMapTemplate`:

```objc
- (CPMapTemplate *)getTemplate {
  CPMapTemplate *template = [[CPMapTemplate alloc] init];
  [template showPanningInterfaceAnimated:YES];

  CPBarButton *customButton = [[CPBarButton alloc]
      initWithTitle:@"Custom Event"
            handler:^(CPBarButton ***_Nonnull** button) {
              NSMutableDictionary *dictionary = [
              [NSMutableDictionary alloc] init
          ];
              dictionary[@"sampleDataKey"] = @"sampleDataContent";
              [[NavAutoModule getOrCreateSharedInstance]
              onCustomNavigationAutoEvent:@"sampleEvent"
              data:dictionary
          ];
            }];

  template.leadingNavigationBarButtons = @[ customButton ];
  template.trailingNavigationBarButtons = @[];
  return template;
}
```

For advanced customization, you can bypass the base class and implement your own delegate inheriting `CPTemplateApplicationSceneDelegate`. You can use the provided `BaseCarSceneDelegate` base class as a reference on how to do that.

### React Native Setup

On the React Native side, you can use the `useNavigationAuto` hook to interface with the CarPlay instance. The `mapViewAutoController` allows you to call map functions on the CarPlay map view, and you can manage listeners using the provided functions.

```tsx
const {
mapViewAutoController,
addListeners: addAutoListener,
removeListeners: removeAutoListeners,
} = useNavigationAuto();

const navigationAutoCallbacks: NavigationAutoCallbacks = useMemo(
() => ({
onCustomNavigationAutoEvent: (event: CustomNavigationAutoEvent) => {
console.log('onCustomNavigationAutoEvent:', event);
},
onAutoScreenAvailabilityChanged: (available: boolean) => {
console.log('onAutoScreenAvailabilityChanged:', available);
setMapViewAutoAvailable(available);
},
}),
[]
);

const setMapType = (mapType: MapType) => {
console.log('setMapType', mapType);
mapViewAutoController.setMapType(mapType);
};
```

For a more detailed example, refer to the `NavigationScreen.tsx` in the React Native example application.

## Example Project

For a fully functional CarPlay implementation, check out the `SampleApp` Xcode project, which includes the `SampleAppCarPlay` build target. The sample already contains test entitlement so you don't need to request one from Apple to run it.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ By default, `NavigationView` uses all the available space provided to it. To adj
/>
```

## Support for Android Auto and Apple CarPlay
This plugin is compatible with both Android Auto and Apple CarPlay infotainment systems. For more details, please refer to the respective platform documentation:

- [Android Auto documentation](./ANDROIDAUTO.md)
- [CarPlay documentation](./CARPLAY.md)

## Contributing

See the [Contributing guide](./CONTRIBUTING.md).
Expand Down
10 changes: 6 additions & 4 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright 2023 Google LLC
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down Expand Up @@ -37,7 +37,7 @@ if (isNewArchitectureEnabled()) {

android {
namespace "com.google.android.react.navsdk"

compileSdkVersion 31

compileOptions {
Expand Down Expand Up @@ -71,6 +71,8 @@ repositories {
}

dependencies {
implementation "androidx.car.app:app:1.4.0"
implementation "androidx.car.app:app-projected:1.4.0"
implementation 'com.facebook.react:react-native:+'
implementation 'com.android.support:multidex:1.0.3'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
Expand Down
Loading
Loading