Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add birdseye screen and nav button on home screen #6

Merged
merged 7 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/assets/icons/birdseye.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions src/navigation/navigationContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {TouchableOpacity, useColorScheme} from 'react-native';

import BirdseyeIcon from '@icons/birdseye.svg';
import EventIcon from '@icons/event.svg';
import HomeIcon from '@icons/home.svg';
import SettingsIcon from '@icons/settings.svg';
Expand All @@ -12,7 +13,9 @@ import {
} from '@react-navigation/native';
import {createNativeStackNavigator} from '@react-navigation/native-stack';

import {useConfig} from '@api';
import {
BirdseyeScreen,
EventsScreen,
HomeScreen,
LiveViewScreen,
Expand All @@ -26,6 +29,7 @@ import {colors} from '../../themeColors.js';

export type MainStackParamList = {
Home: undefined;
Birdseye: undefined;
Tabs: NavigatorScreenParams<TabsStackParamList>;
Settings: undefined;
Onboarding: undefined;
Expand All @@ -43,6 +47,7 @@ const TabStack = createBottomTabNavigator<TabsStackParamList>();

const TabNavigator = () => {
const isDarkMode = useColorScheme() === 'dark';

return (
<TabStack.Navigator
screenOptions={({route}) => ({
Expand Down Expand Up @@ -98,6 +103,30 @@ const TabNavigator = () => {
);
};

const LeftHeaderButton = ({tintColor}: {tintColor?: string}) => {
const nav = useNavigation();
const config = useConfig();

if (!config.data?.birdseye.enabled) {
return null;
}

return (
<TouchableOpacity
onPress={() => {
nav.navigate('Birdseye');
}}>
<BirdseyeIcon
height={24}
width={24}
fill={tintColor}
fillSecondary={tintColor}
style={{marginTop: 2}}
/>
</TouchableOpacity>
);
};

const RightHeaderButton = ({tintColor}: {tintColor?: string}) => {
const navigation = useNavigation();

Expand Down Expand Up @@ -134,6 +163,7 @@ export const RootNavigation = () => {
options={{
headerBackTitle: 'Back',
headerTitle: 'Bird Watcher - Frigate',
headerLeft: props => LeftHeaderButton(props as {tintColor: string}),
headerRight: props =>
RightHeaderButton(props as {tintColor: string}),
headerTintColor: isDarkMode
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then we can use is like this in the component.

Suggested change
headerTintColor: isDarkMode
headerLeft: props => HeaderLeftIcon(props),

Expand All @@ -156,6 +186,13 @@ export const RootNavigation = () => {
options={{presentation: 'modal', headerTransparent: false}}
/>
<Stack.Screen name="Onboarding" component={OnBoardingScreen} />
<Stack.Screen
name="Birdseye"
component={BirdseyeScreen}
options={{
headerBackTitle: 'Home',
}}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}}
presentation: 'modal',

Last nit - I think this should actually be presented in a Modal since the button to access is in the nav header. It feels a bit weird that it slides in as a card now. I'm okay with adding this later too, but wanted to call it out.

/>
</Stack.Navigator>
</NavigationContainer>
);
Expand Down
29 changes: 29 additions & 0 deletions src/screens/BirdseyeScreen/BirdseyeScreen.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {useConfig} from '@api';
import {BaseText, WebRTCView} from '@components';

export const BirdseyeScreen = () => {
const config = useConfig();

if (config.isLoading) {
return <BaseText>Loading ...</BaseText>;
}

if (config.isError) {
return <BaseText>Failed to load frigate config</BaseText>;
}

if (!config.data?.birdseye.enabled) {
return <BaseText>Birdseye is not enabled</BaseText>;
}

if (!config.data?.birdseye.restream) {
return (
<BaseText>
Restream must be enabled so that the birdseye feed is served through
WebRTC. Please update your Frigate config.
</BaseText>
);
}

return <WebRTCView cameraName="birdseye" />;
};
1 change: 1 addition & 0 deletions src/screens/BirdseyeScreen/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './BirdseyeScreen';
3 changes: 2 additions & 1 deletion src/screens/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from './HomeScreen';
export * from './homeScreen';
export * from './LiveViewScreen';
export * from './EventsScreen';
export * from './SettingsScreen';
//
export * from './onboardingScreen';
export * from './BirdseyeScreen';