restrict react-native-carplay to ios

While these changes weren't neccessery for a successful android build, they make it clearer that the carplay provider is only for ios
This commit is contained in:
John Grant
2025-03-19 23:07:37 +11:00
parent 796f86e5d8
commit b6231b499d
+16 -11
View File
@@ -1,9 +1,12 @@
import Client from "../api/client";
import { isUndefined } from "lodash";
import { createContext, ReactNode, SetStateAction, useContext, useEffect, useState } from "react";
import { CarPlay } from "react-native-carplay";
import CarPlayNavigation from "./CarPlay/Navigation";
import CarPlayNowPlaying from "./CarPlay/NowPlaying";
import { Platform } from 'react-native'
// 'react-native-carplay' has also been disabled for android builds in react-native.config.js
const CarPlay = Platform.OS === 'ios' ? require('react-native-carplay') : null;
const CarPlayNavigation = CarPlay ? require('./CarPlay/Navigation').CarPlayNavigation : null;
const CarPlayNowPlaying = CarPlay ? require('./CarPlay/NowPlaying').CarPlayNowPlaying : null;
interface JellifyContext {
loggedIn: boolean;
@@ -22,14 +25,14 @@ const JellifyContextInitializer = () => {
);
const [carPlayConnected, setCarPlayConnected] = useState(CarPlay.connected);
const [carPlayConnected, setCarPlayConnected] = useState(CarPlay ? CarPlay.connected : false);
useEffect(() => {
function onConnect() {
setCarPlayConnected(true);
if (loggedIn) {
if (loggedIn && CarPlay) {
CarPlay.setRootTemplate(CarPlayNavigation, true);
CarPlay.pushTemplate(CarPlayNowPlaying, true);
CarPlay.enableNowPlaying(true); // https://github.com/birkir/react-native-carplay/issues/185
@@ -40,12 +43,14 @@ const JellifyContextInitializer = () => {
setCarPlayConnected(false);
}
CarPlay.registerOnConnect(onConnect);
CarPlay.registerOnDisconnect(onDisconnect);
return () => {
CarPlay.unregisterOnConnect(onConnect)
CarPlay.unregisterOnDisconnect(onDisconnect)
};
if (CarPlay) {
CarPlay.registerOnConnect(onConnect);
CarPlay.registerOnDisconnect(onDisconnect);
return () => {
CarPlay.unregisterOnConnect(onConnect)
CarPlay.unregisterOnDisconnect(onDisconnect)
};
}
});
return {