mirror of
https://github.com/Jellify-Music/App.git
synced 2026-05-02 00:19:32 -05:00
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:
+16
-11
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user