Skip to content

Commit d54a496

Browse files
committed
feat!: support new React Native architecture
1 parent eb7cca8 commit d54a496

File tree

240 files changed

+25675
-12989
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

240 files changed

+25675
-12989
lines changed

.github/ISSUE_TEMPLATE/bug_report.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,16 @@ body:
6060
attributes:
6161
label: React Native Doctor Output
6262
description: |
63-
Run `npx react-native doctor` in your projectq and paste the output below.
63+
Run `npx react-native doctor` in your project folder and paste the output below.
64+
render: shell
65+
validations:
66+
required: true
67+
- type: textarea
68+
attributes:
69+
label: React Native Info Output
70+
description: |
71+
Run `npx react-native info` in your project folder and paste the output below.
72+
render: shell
6473
validations:
6574
required: true
6675
- type: textarea
@@ -96,9 +105,13 @@ body:
96105
Without this we will unlikely be able to progress on the issue,
97106
as we need to be able to reproduce the problem locally.
98107
value: |
108+
<details open><summary>Code sample</summary>
109+
99110
```javascript
100111
// Example code here
101112
```
113+
114+
</details>
102115
validations:
103116
required: true
104117
- type: textarea

.github/workflows/ci.yml

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
run: yarn lint
3838

3939
- name: Typecheck files
40-
run: yarn test:types
40+
run: yarn typecheck
4141

4242
check-objc-formatting:
4343
runs-on: ubuntu-latest
@@ -52,7 +52,7 @@ jobs:
5252
- name: Check Objective-C formatting
5353
run: ./scripts/format-objc.sh --check
5454

55-
check-java-formatting:
55+
check-java-and-kotlin-formatting:
5656
runs-on: ubuntu-latest
5757
timeout-minutes: 30
5858
steps:
@@ -84,6 +84,24 @@ jobs:
8484
- name: Check Java formatting
8585
run: ./scripts/format-java.sh --check
8686

87+
- name: Download ktfmt
88+
run: |
89+
KTFMT_VERSION=0.54
90+
KTFMT_URL=https://repo1.maven.org/maven2/com/facebook/ktfmt/${KTFMT_VERSION}/ktfmt-${KTFMT_VERSION}-jar-with-dependencies.jar
91+
mkdir -p $HOME/ktfmt
92+
curl -L -o $HOME/ktfmt/ktfmt.jar $KTFMT_URL
93+
94+
- name: Create ktfmt wrapper script
95+
run: |
96+
cat << 'EOF' > /usr/local/bin/ktfmt
97+
#!/bin/sh
98+
exec java -jar "$HOME/ktfmt/ktfmt.jar" "$@"
99+
EOF
100+
chmod +x /usr/local/bin/ktfmt
101+
102+
- name: Check Kotlin formatting
103+
run: ./scripts/format-kotlin.sh --check
104+
87105
test:
88106
runs-on: ubuntu-latest
89107
timeout-minutes: 30
@@ -222,7 +240,7 @@ jobs:
222240
NO_FLIPPER: 1
223241

224242
- name: Copy Keys.plist file from sample
225-
run: cp example/ios/SampleApp/Keys.plist.sample example/ios/SampleApp/Keys.plist
243+
run: cp example/ios/ReactNativeNavigationSdkExample/Keys.plist.sample example/ios/ReactNativeNavigationSdkExample/Keys.plist
226244

227245
- name: Build example for iOS
228246
run: |

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ DerivedData
2828
*.ipa
2929
*.xcuserstate
3030
project.xcworkspace
31-
.xcode.env.local
31+
**/.xcode.env.local
3232
Keys.plist
3333

3434
# Android/IJ
@@ -81,5 +81,5 @@ android/keystores/debug.keystore
8181
# generated by bob
8282
lib/
8383

84-
# tests
84+
# Tests
8585
coverage/

.npmignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
example
22
coverage
3-
node_modules
3+
node_modules
4+
scripts

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v18
1+
v20

.tool-versions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
nodejs 18.20.1
1+
nodejs 20.18.3

.watchmanconfig

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
{
2-
"fsevents_latency": 0.1
3-
}
1+
{}

.yarnrc.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ nmHoistingLimits: workspaces
1717

1818
plugins:
1919
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
20-
spec: "@yarnpkg/plugin-interactive-tools"
20+
spec: '@yarnpkg/plugin-interactive-tools'
2121
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
22-
spec: "@yarnpkg/plugin-workspace-tools"
22+
spec: '@yarnpkg/plugin-workspace-tools'
2323

2424
yarnPath: .yarn/releases/yarn-3.6.1.cjs

ANDROIDAUTO.md

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ For all the steps above, you can refer to the Android example application for gu
2020

2121
### Screen for Android Auto
2222

23-
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.
23+
Once your project is configured accordingly, and you are ready to build the screen for Android Auto, you can leverage the `GMNAndroidAutoBaseScreen` provided by the SDK. This base class simplifies the setup by handling initialization, teardown, and rendering the map on the Android Auto display.
2424

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

@@ -61,7 +61,7 @@ public Template onGetTemplate() {
6161
}
6262
```
6363

64-
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.
64+
For advanced customization, you can bypass the base class and implement your own screen by inheriting `Screen`. You can use the provided `GMNAndroidAutoBaseScreen` base class as a reference on how to do that.
6565

6666
### React Native specific setup
6767

@@ -70,22 +70,25 @@ On the React Native side, you can use the `useNavigationAuto` hook to interface
7070
```tsx
7171
const {
7272
mapViewAutoController,
73-
addListeners: addAutoListener,
74-
removeListeners: removeAutoListeners,
7573
} = useNavigationAuto();
7674

77-
const navigationAutoCallbacks: NavigationAutoCallbacks = useMemo(
78-
() => ({
79-
onCustomNavigationAutoEvent: (event: CustomNavigationAutoEvent) => {
80-
console.log('onCustomNavigationAutoEvent:', event);
81-
},
82-
onAutoScreenAvailabilityChanged: (available: boolean) => {
75+
useEffect(() => {
76+
mapViewAutoController.setOnAutoScreenAvailabilityChangedListener(
77+
(available: boolean) => {
8378
console.log('onAutoScreenAvailabilityChanged:', available);
8479
setMapViewAutoAvailable(available);
85-
},
86-
}),
87-
[]
88-
);
80+
}
81+
);
82+
mapViewAutoController.setOnCustomNavigationAutoEventListener(
83+
(event: CustomNavigationAutoEvent) => {
84+
console.log('onCustomNavigationAutoEvent:', event);
85+
}
86+
);
87+
88+
return () => {
89+
mapViewAutoController.removeAllListeners();
90+
};
91+
});
8992

9093
const setMapType = (mapType: MapType) => {
9194
console.log('setMapType', mapType);

CARPLAY.md

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,25 @@ On the React Native side, you can use the `useNavigationAuto` hook to interface
5656
```tsx
5757
const {
5858
mapViewAutoController,
59-
addListeners: addAutoListener,
60-
removeListeners: removeAutoListeners,
6159
} = useNavigationAuto();
6260

63-
const navigationAutoCallbacks: NavigationAutoCallbacks = useMemo(
64-
() => ({
65-
onCustomNavigationAutoEvent: (event: CustomNavigationAutoEvent) => {
66-
console.log('onCustomNavigationAutoEvent:', event);
67-
},
68-
onAutoScreenAvailabilityChanged: (available: boolean) => {
61+
useEffect(() => {
62+
mapViewAutoController.setOnAutoScreenAvailabilityChangedListener(
63+
(available: boolean) => {
6964
console.log('onAutoScreenAvailabilityChanged:', available);
7065
setMapViewAutoAvailable(available);
71-
},
72-
}),
73-
[]
74-
);
66+
}
67+
);
68+
mapViewAutoController.setOnCustomNavigationAutoEventListener(
69+
(event: CustomNavigationAutoEvent) => {
70+
console.log('onCustomNavigationAutoEvent:', event);
71+
}
72+
);
73+
74+
return () => {
75+
mapViewAutoController.removeAllListeners();
76+
};
77+
});
7578

7679
const setMapType = (mapType: MapType) => {
7780
console.log('setMapType', mapType);
@@ -83,4 +86,4 @@ For a more detailed example, refer to the `NavigationScreen.tsx` in the React Na
8386

8487
## Example Project
8588

86-
For a fully functional CarPlay implementation, check out the [SampleApp](./example/ios/) 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.
89+
For a fully functional CarPlay implementation, check out the [SampleApp](./example/ios/) Xcode project, which includes the `ReactNativeNavigationSdkExampleCarPlay` build target. The sample already contains test entitlement so you don't need to request one from Apple to run it.

CONTRIBUTING.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ This project follows
3131
- [addlicense](https://github.com/google/addlicense)
3232
- [google-java-format Version 1.23.0](https://github.com/google/google-java-format) (used to format Java code).
3333
- [clang-format](https://clang.llvm.org/docs/ClangFormat.html) (used to format Objective-C code).
34+
- [ktfmt](https://facebook.github.io/ktfmt/) (used to format Kotlin code).
3435

3536
## 2. Forking & cloning the repository
3637

@@ -97,6 +98,18 @@ This script will format all Objective-C files under the /ios and /example/ios di
9798
```
9899
This script will format all Java files under the /android and /example/android directories according to Google's Java style guide.
99100

101+
**Kotlin:**
102+
```bash
103+
./scripts/format-kotlin.sh
104+
```
105+
This script will format all Kotlin files under the /android and /example/android directories according to Google's Kotlin style guide.
106+
107+
**All:**
108+
```bash
109+
./scripts/format.sh
110+
```
111+
This script run all above formatters.
112+
100113

101114
## 5. Code reviews
102115

@@ -140,6 +153,7 @@ yarn run example detox:test:ios-release
140153
```
141154

142155
Android:
156+
Create AVD emulator with the name "Pixel_9_Pro_API_35" and run the command below.
143157
```bash
144158
yarn run example detox:test:android-release
145159
```

README.md

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ This repository contains a React Native plugin that provides a [Google Navigatio
1111

1212
| | Android | iOS |
1313
| ------------------------------- | ------- | --------- |
14-
| **Minimum mobile OS supported** | SDK 23+ | iOS 15.0+ |
14+
| **Minimum mobile OS supported** | SDK 23+ | iOS 16.0+ |
1515

16-
* A React Native project
16+
* Supported React Native version: **0.78+**
17+
* See [React Native Support](#react-native-support) below for version and architecture requirements
1718
* A Google Cloud project
18-
* If you are a Mobility Services developer, you must contact Sales as described in [Mobility services documentation](https://developers.google.com/maps/documentation/transportation-logistics/mobility).
19-
* If you are not a Mobility Services developer, refer to [Setup Google Cloud Project](https://developers.google.com/maps/documentation/navigation/android-sdk/cloud-setup) for instructions.
19+
* If you are a Mobility Services developer, you must contact Sales as described in [Mobility services documentation](https://developers.google.com/maps/documentation/transportation-logistics/mobility).
20+
* If you are not a Mobility Services developer, refer to [Setup Google Cloud Project](https://developers.google.com/maps/documentation/navigation/android-sdk/cloud-setup) for instructions.
2021
* An [API key](https://console.cloud.google.com/google/maps-apis/credentials) from the project above
2122
* The API key must be configured for both Android and iOS. Refer to [Android Using Api Keys](https://developers.google.com/maps/documentation/navigation/android-sdk/get-api-key) and [iOS Using Api Keys](https://developers.google.com/maps/documentation/navigation/ios-sdk/get-api-key) respectively for instructions.
2223
* If targeting Android, [Google Play Services](https://developers.google.com/android/guides/overview) installed and enabled
@@ -41,14 +42,6 @@ import { NavigationView } from '@googlemaps/react-native-navigation-sdk';
4142

4243
### Android
4344

44-
#### Disable new architecture
45-
46-
This package does not yet support new architecture. Make sure new architecture is disabled in your `android/gradle.properties` file:
47-
48-
```groovy
49-
newArchEnabled=false
50-
```
51-
5245
#### Enable Jetifier
5346

5447
To ensure compatibility with AndroidX, enable Jetifier in your `android/gradle.properties` file:
@@ -96,14 +89,6 @@ See example configuration for secrets plugin at example applications [build.grad
9689

9790
### iOS
9891

99-
#### Disable new architecture
100-
101-
This package does not yet support new architecture. Make sure new architecture is disabled in your `ios/Podfile`:
102-
103-
```ruby
104-
ENV['RCT_NEW_ARCH_ENABLED'] = '0'
105-
```
106-
10792
#### Set Google Maps API Key
10893

10994
To set up, specify your API key in the application delegate `ios/Runner/AppDelegate.m`:
@@ -175,7 +160,7 @@ const { navigationController } = useNavigation();
175160

176161
const initializeNavigation = useCallback(async () => {
177162
try {
178-
await navigationController.init();
163+
const status: NavigationInitializationStatus = await navigationController.init();
179164
console.log('Navigation initialized');
180165
} catch (error) {
181166
console.error('Error initializing navigation', error);
@@ -357,6 +342,34 @@ This package uses the Google Maps [Navigation SDK](https://mapsplatform.google.c
357342
> [!NOTE]
358343
> This package provides a `MapView` component, which can be used as a classic Google Maps view without navigation. See [Add a map view](#add-a-map-view) for details.
359344
345+
## React Native Support
346+
347+
> [!IMPORTANT]
348+
> **This package is tested and supported only with React Native versions 0.78 and above, and requires the New Architecture (Fabric and TurboModules) to be enabled.**
349+
>
350+
> If you are using an older version of React Native (below 0.78) or cannot have the New Architecture enabled, you must use version `0.9.3` or earlier of this package.
351+
352+
The New Architecture is enabled by default from React Native 0.76 onwards, but you should verify it is enabled in your project. See below for instructions.
353+
354+
#### Enabling New Architecture
355+
356+
**Android:**
357+
Add the following to your `android/gradle.properties` file:
358+
```groovy
359+
newArchEnabled=true
360+
```
361+
362+
**iOS:**
363+
Add the following to your `ios/Podfile` file:
364+
```ruby
365+
ENV['RCT_NEW_ARCH_ENABLED'] = '1'
366+
```
367+
368+
If you need to use the legacy React Native architecture or an older React Native version, install version `0.9.3` or earlier:
369+
```shell
370+
npm i @googlemaps/[email protected]
371+
```
372+
360373
## Contributing
361374

362375
See the [Contributing guide](./CONTRIBUTING.md).

0 commit comments

Comments
 (0)