diff --git a/components/provider.tsx b/components/provider.tsx index 6c769ad9..0cc5cf6e 100644 --- a/components/provider.tsx +++ b/components/provider.tsx @@ -4,9 +4,9 @@ import { createContext, ReactNode, SetStateAction, useContext, useEffect, useSta 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; +const CarPlayModule = Platform.OS === 'ios' ? require('react-native-carplay') : null; +const CarPlayNavigation = CarPlayModule ? require('./CarPlay/Navigation').CarPlayNavigation : null; +const CarPlayNowPlaying = CarPlayModule ? require('./CarPlay/NowPlaying').CarPlayNowPlaying : null; interface JellifyContext { loggedIn: boolean; @@ -16,8 +16,8 @@ interface JellifyContext { const JellifyContextInitializer = () => { - console.debug(CarPlay) - console.debug(typeof(CarPlay)) + console.debug(CarPlayModule) + console.debug(typeof(CarPlayModule)) const [loggedIn, setLoggedIn] = useState( !isUndefined(Client) && @@ -28,17 +28,17 @@ const JellifyContextInitializer = () => { ); - const [carPlayConnected, setCarPlayConnected] = useState(CarPlay ? CarPlay.connected : false); + const [carPlayConnected, setCarPlayConnected] = useState(CarPlayModule ? CarPlayModule.connected : false); useEffect(() => { function onConnect() { setCarPlayConnected(true); - if (loggedIn && CarPlay) { - CarPlay.setRootTemplate(CarPlayNavigation, true); - CarPlay.pushTemplate(CarPlayNowPlaying, true); - CarPlay.enableNowPlaying(true); // https://github.com/birkir/react-native-carplay/issues/185 + if (loggedIn && CarPlayModule) { + CarPlayModule.CarPlay.setRootTemplate(CarPlayNavigation, true); + CarPlayModule.CarPlay.pushTemplate(CarPlayNowPlaying, true); + CarPlayModule.CarPlay.enableNowPlaying(true); // https://github.com/birkir/react-native-carplay/issues/185 } } @@ -46,12 +46,12 @@ const JellifyContextInitializer = () => { setCarPlayConnected(false); } - if (CarPlay) { - CarPlay.registerOnConnect(onConnect); - CarPlay.registerOnDisconnect(onDisconnect); + if (CarPlayModule) { + CarPlayModule.CarPlay.registerOnConnect(onConnect); + CarPlayModule.CarPlay.registerOnDisconnect(onDisconnect); return () => { - CarPlay.unregisterOnConnect(onConnect) - CarPlay.unregisterOnDisconnect(onDisconnect) + CarPlayModule.CarPlay.unregisterOnConnect(onConnect) + CarPlayModule.CarPlay.unregisterOnDisconnect(onDisconnect) }; } });