Files
jellyfin-audio-player/src/components/App.tsx

69 lines
2.0 KiB
TypeScript
Raw Normal View History

2020-06-16 17:51:51 +02:00
import React, { Component } from 'react';
2020-06-17 14:58:04 +02:00
import { Provider } from 'react-redux';
2020-06-16 17:51:51 +02:00
import TrackPlayer from 'react-native-track-player';
2020-06-17 14:58:04 +02:00
import { PersistGate } from 'redux-persist/integration/react';
import { AppearanceProvider, Appearance, AppearanceListener } from 'react-native-appearance';
2020-06-16 17:51:51 +02:00
import Routes from '../screens';
2020-06-21 10:30:41 +02:00
import store, { persistedStore } from 'store';
2020-07-26 14:45:32 +02:00
import {
NavigationContainer,
DefaultTheme,
DarkTheme,
} from '@react-navigation/native';
2020-06-16 17:51:51 +02:00
interface State {
isReady: boolean;
colorScheme?: string;
2020-06-16 17:51:51 +02:00
}
export default class App extends Component<{}, State> {
state: State = {
isReady: false,
2020-06-16 17:51:51 +02:00
};
subscription = null;
2020-06-16 17:51:51 +02:00
async componentDidMount() {
await TrackPlayer.setupPlayer();
2020-06-16 21:41:02 +02:00
await TrackPlayer.updateOptions({
capabilities: [
TrackPlayer.CAPABILITY_PLAY,
TrackPlayer.CAPABILITY_PAUSE,
TrackPlayer.CAPABILITY_SKIP_TO_NEXT,
TrackPlayer.CAPABILITY_SKIP_TO_PREVIOUS,
TrackPlayer.CAPABILITY_STOP,
2020-06-17 15:28:21 +02:00
TrackPlayer.CAPABILITY_SEEK_TO,
2020-06-16 21:41:02 +02:00
]
});
this.subscription = Appearance.addChangeListener(this.setScheme);
this.setState({ isReady: true, colorScheme: Appearance.getColorScheme() });
}
componentWillUnmount() {
this.subscription?.remove();
}
setScheme: AppearanceListener = ({ colorScheme }) => {
this.setState({ colorScheme });
2020-06-16 17:51:51 +02:00
}
render() {
const { isReady, colorScheme } = this.state;
2020-06-16 17:51:51 +02:00
if (!isReady) {
return null;
}
return (
2020-06-17 14:58:04 +02:00
<Provider store={store}>
2020-06-20 22:49:51 +02:00
<PersistGate loading={null} persistor={persistedStore}>
2020-07-26 14:45:32 +02:00
<AppearanceProvider>
<NavigationContainer theme={colorScheme === 'dark' ? DarkTheme : DefaultTheme}>
2020-07-26 14:45:32 +02:00
<Routes />
</NavigationContainer>
</AppearanceProvider>
2020-06-17 14:58:04 +02:00
</PersistGate>
</Provider>
2020-06-16 17:51:51 +02:00
);
}
}