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 2 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
1 change: 1 addition & 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.
36 changes: 35 additions & 1 deletion src/navigation/navigationContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,35 @@
import {useColorScheme} from 'react-native';
import {Button, useColorScheme} from 'react-native';

Check failure on line 1 in src/navigation/navigationContainer.tsx

View workflow job for this annotation

GitHub Actions / lint

'Button' is defined but never used. Allowed unused vars must match /^_/u

import EventIcon from '@icons/event.svg';
import HomeIcon from '@icons/home.svg';
import VideoIcon from '@icons/video-waveform.svg';
import BirdseyeIcon from '@icons/birdseye.svg';

Check failure on line 6 in src/navigation/navigationContainer.tsx

View workflow job for this annotation

GitHub Actions / lint

`@icons/birdseye.svg` import should occur before import of `@icons/event.svg`
import {createBottomTabNavigator} from '@react-navigation/bottom-tabs';
import {
NavigationContainer,
NavigatorScreenParams,
useNavigation,
} from '@react-navigation/native';
import {createNativeStackNavigator} from '@react-navigation/native-stack';

import {
EventsScreen,
HomeScreen,

Check failure on line 17 in src/navigation/navigationContainer.tsx

View workflow job for this annotation

GitHub Actions / typescript-check

Module '"@screens"' has no exported member 'HomeScreen'.
LiveViewScreen,
OnBoardingScreen,
BirdseyeScreen,

Check failure on line 20 in src/navigation/navigationContainer.tsx

View workflow job for this annotation

GitHub Actions / lint

Member 'BirdseyeScreen' of the import declaration should be sorted alphabetically
} from '@screens';
import {useAppDataStore} from '@stores';

//? Can't figure out how to properly type this
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
import {colors, hslFunction} from '../../themeColors.js';

Check failure on line 27 in src/navigation/navigationContainer.tsx

View workflow job for this annotation

GitHub Actions / lint

There should be at least one empty line between import groups
import {useConfig} from '@api';

Check failure on line 28 in src/navigation/navigationContainer.tsx

View workflow job for this annotation

GitHub Actions / lint

`@api` import should occur before import of `@screens`

export type MainStackParamList = {
Home: undefined;
Birdseye: undefined;
Tabs: NavigatorScreenParams<TabsStackParamList>;
Onboarding: undefined;
};
Expand All @@ -41,6 +46,7 @@

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

//TODO: make work with tailwind theme...
return (
<TabStack.Navigator
Expand Down Expand Up @@ -98,6 +104,8 @@
};

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

const currentCamera = useAppDataStore(state => state.currentCamera);
Copy link
Owner

Choose a reason for hiding this comment

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

The Header Button should be defined before the actual nav component.

Suggested change
const config = useConfig();
const currentCamera = useAppDataStore(state => state.currentCamera);
const HeaderLeftIcon = ({tintColor}: HeaderBackButtonProps) => {
const nav = useNavigation();
const config = useConfig();
if (!config.data?.birdseye.enabled) {
return null;
}
return (
<BirdseyeIcon
height={25}
width={25}
onPress={() => {
nav.navigate('Birdseye');
}}
fill={tintColor}
fillSecondary={tintColor}
/>
);
};

Copy link
Owner

Choose a reason for hiding this comment

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

FYI using tint color like this is currently causing a warning since it's sort of an HSL value, but I don't think RN knows how to parse that. I'll be addressing this soon when I try and overhaul theming a bit.

const isDarkMode = useColorScheme() === 'dark';

Expand All @@ -117,6 +125,25 @@
options={{
headerBackTitle: 'Back',
headerTitle: 'Bird Watcher - Frigate',
headerLeft: () => {
const nav = useNavigation();

Check failure on line 129 in src/navigation/navigationContainer.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook "useNavigation" is called in function "headerLeft" that is neither a React function component nor a custom React Hook function. React component names must start with an uppercase letter. React Hook names must start with the word "use"

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

return (
<BirdseyeIcon
height={25}
width={25}
onPress={() => {
nav.navigate('Birdseye');
}}
fill={tintColor}
fillSecondary={tintColor}
/>
);
},
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),

? colors.dark.accent
: colors.light.accent,
Expand All @@ -132,6 +159,13 @@
}}
/>
<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
16 changes: 16 additions & 0 deletions src/screens/BirdseyeScreen/BirdseyeScreen.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {useConfig} from '@api';
import {BaseText, WebRTCView} from '@components';

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

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

if (config.data?.birdseye.enabled) {
return <WebRTCView cameraName="birdseye" />;
}

return <BaseText>Birdseye is not enabled</BaseText>;
};
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';
1 change: 1 addition & 0 deletions src/screens/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './HomeScreen';

Check failure on line 1 in src/screens/index.ts

View workflow job for this annotation

GitHub Actions / lint

Unable to resolve path to module './HomeScreen'

Check failure on line 1 in src/screens/index.ts

View workflow job for this annotation

GitHub Actions / typescript-check

Cannot find module './HomeScreen' or its corresponding type declarations.
export * from './LiveViewScreen';
export * from './EventsScreen';
//
export * from './onboardingScreen';
export * from './BirdseyeScreen';
Loading