mirror of
https://github.com/anultravioletaurora/Jellify.git
synced 2026-01-26 08:19:51 -06:00
carplay module import typing
This commit is contained in:
@@ -2,11 +2,12 @@ import Client from "../api/client";
|
||||
import { isUndefined } from "lodash";
|
||||
import { createContext, ReactNode, SetStateAction, useContext, useEffect, useState } from "react";
|
||||
import { Platform } from 'react-native'
|
||||
import { CarPlayInterface } from "react-native-carplay";
|
||||
|
||||
// 'react-native-carplay' has also been disabled for android builds in react-native.config.js
|
||||
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;
|
||||
const CarPlay = Platform.OS === 'ios' ? require('react-native-carplay').CarPlay as CarPlayInterface : null;
|
||||
const CarPlayNavigation = CarPlay ? require('./CarPlay/Navigation').CarPlayNavigation : null;
|
||||
const CarPlayNowPlaying = CarPlay ? require('./CarPlay/NowPlaying').CarPlayNowPlaying : null;
|
||||
|
||||
interface JellifyContext {
|
||||
loggedIn: boolean;
|
||||
@@ -16,8 +17,8 @@ interface JellifyContext {
|
||||
|
||||
const JellifyContextInitializer = () => {
|
||||
|
||||
console.debug(CarPlayModule)
|
||||
console.debug(typeof(CarPlayModule))
|
||||
console.debug(CarPlay)
|
||||
console.debug(typeof(CarPlay))
|
||||
|
||||
const [loggedIn, setLoggedIn] = useState<boolean>(
|
||||
!isUndefined(Client) &&
|
||||
@@ -28,17 +29,17 @@ const JellifyContextInitializer = () => {
|
||||
);
|
||||
|
||||
|
||||
const [carPlayConnected, setCarPlayConnected] = useState(CarPlayModule ? CarPlayModule.connected : false);
|
||||
const [carPlayConnected, setCarPlayConnected] = useState(CarPlay ? CarPlay.connected : false);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
function onConnect() {
|
||||
setCarPlayConnected(true);
|
||||
|
||||
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
|
||||
if (loggedIn && CarPlay) {
|
||||
CarPlay.setRootTemplate(CarPlayNavigation, true);
|
||||
CarPlay.pushTemplate(CarPlayNowPlaying, true);
|
||||
CarPlay.enableNowPlaying(true); // https://github.com/birkir/react-native-carplay/issues/185
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,12 +47,12 @@ const JellifyContextInitializer = () => {
|
||||
setCarPlayConnected(false);
|
||||
}
|
||||
|
||||
if (CarPlayModule) {
|
||||
CarPlayModule.CarPlay.registerOnConnect(onConnect);
|
||||
CarPlayModule.CarPlay.registerOnDisconnect(onDisconnect);
|
||||
if (CarPlay) {
|
||||
CarPlay.registerOnConnect(onConnect);
|
||||
CarPlay.registerOnDisconnect(onDisconnect);
|
||||
return () => {
|
||||
CarPlayModule.CarPlay.unregisterOnConnect(onConnect)
|
||||
CarPlayModule.CarPlay.unregisterOnDisconnect(onDisconnect)
|
||||
CarPlay.unregisterOnConnect(onConnect)
|
||||
CarPlay.unregisterOnDisconnect(onDisconnect)
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user