Files
jellyfin-audio-player/src/screens/index.tsx

105 lines
3.5 KiB
TypeScript
Raw Normal View History

2020-06-16 17:51:51 +02:00
import React from 'react';
2020-06-17 14:58:04 +02:00
import { createBottomTabNavigator, BottomTabNavigationProp } from '@react-navigation/bottom-tabs';
2020-07-07 13:21:03 +02:00
import { createStackNavigator, StackNavigationProp } from '@react-navigation/stack';
import { CompositeNavigationProp } from '@react-navigation/native';
import SetJellyfinServer from './modals/SetJellyfinServer';
2020-06-16 17:51:51 +02:00
import Player from './Player';
2020-06-21 13:02:23 +02:00
import Music from './Music';
2020-06-16 23:11:05 +02:00
import Settings from './Settings';
2020-07-07 13:21:03 +02:00
import PlayPauseIcon from 'assets/play-pause-fill.svg';
import NotesIcon from 'assets/notes.svg';
import GearIcon from 'assets/gear.svg';
2020-07-10 15:25:32 +02:00
import { THEME_COLOR } from 'CONSTANTS';
2020-08-09 17:49:36 +02:00
import { useTypedSelector } from 'store';
import Onboarding from './Onboarding';
import TrackPopupMenu from './modals/TrackPopupMenu';
import { ModalStackParams } from './types';
2020-11-02 22:50:00 +01:00
import { t } from '@localisation';
import ErrorReportingAlert from 'utility/ErrorReportingAlert';
import ErrorReportingPopup from './modals/ErrorReportingPopup';
2020-06-16 17:51:51 +02:00
const Stack = createStackNavigator<ModalStackParams>();
2020-06-16 17:51:51 +02:00
const Tab = createBottomTabNavigator();
2020-06-17 14:58:04 +02:00
type Screens = {
NowPlaying: undefined;
2020-06-21 13:02:23 +02:00
Music: undefined;
2020-06-17 14:58:04 +02:00
Settings: undefined;
}
2020-07-07 13:21:03 +02:00
function getIcon(route: string): React.FC<any> | null {
switch(route) {
case 'NowPlaying':
return PlayPauseIcon;
case 'Music':
return NotesIcon;
case 'Settings':
return GearIcon;
default:
return null;
}
}
2020-06-17 14:58:04 +02:00
function Screens() {
2020-08-09 17:49:36 +02:00
const isOnboardingComplete = useTypedSelector(state => state.settings.isOnboardingComplete);
// GUARD: If onboarding has not been completed, we instead render the
// onboarding component, so that the user can get setup in the app.
if (!isOnboardingComplete) {
return <Onboarding />;
}
2020-06-16 17:51:51 +02:00
return (
<>
<ErrorReportingAlert />
<Tab.Navigator
screenOptions={({ route }) => ({
tabBarIcon: function TabBarIcon({ color, size }) {
const Icon = getIcon(route.name);
2020-07-07 13:21:03 +02:00
if (!Icon) {
return null;
}
2020-07-07 13:21:03 +02:00
return <Icon fill={color} width={size} height={size} />;
},
tabBarActiveTintColor: THEME_COLOR,
tabBarInactiveTintColor: 'gray',
headerShown: false,
})}
>
<Tab.Screen name="NowPlaying" component={Player} options={{ tabBarLabel: t('now-playing') }} />
<Tab.Screen name="Music" component={Music} options={{ tabBarLabel: t('music') }} />
<Tab.Screen name="Settings" component={Settings} options={{ tabBarLabel: t('settings') }} />
</Tab.Navigator>
</>
2020-06-16 17:51:51 +02:00
);
2020-06-17 14:58:04 +02:00
}
type Routes = {
Screens: undefined;
SetJellyfinServer: undefined;
}
export default function Routes() {
return (
<Stack.Navigator screenOptions={{
2020-06-17 14:58:04 +02:00
cardStyle: {
backgroundColor: 'transparent'
},
presentation: 'modal',
headerShown: false,
2020-06-17 14:58:04 +02:00
}}>
<Stack.Screen name="Screens" component={Screens} />
<Stack.Screen name="SetJellyfinServer" component={SetJellyfinServer} />
<Stack.Screen name="TrackPopupMenu" component={TrackPopupMenu} />
<Stack.Screen name="ErrorReporting" component={ErrorReportingPopup} />
2020-06-17 14:58:04 +02:00
</Stack.Navigator>
);
}
export type NavigationProp = CompositeNavigationProp<
StackNavigationProp<Routes>,
BottomTabNavigationProp<Screens>
2020-06-17 14:58:04 +02:00
>;