diff options
author | Paul Frazee <pfrazee@gmail.com> | 2022-06-09 21:34:43 -0500 |
---|---|---|
committer | Paul Frazee <pfrazee@gmail.com> | 2022-06-09 21:34:43 -0500 |
commit | 967f9fc474f2903dd2c12ef4f662ead1592ea26c (patch) | |
tree | af90380121af16ce2382d725fee3d50cd6332598 /src/platform | |
parent | 802222fe7181303d710607129e1c74427f07c97c (diff) | |
download | voidsky-967f9fc474f2903dd2c12ef4f662ead1592ea26c.tar.zst |
Add desktop shell
Diffstat (limited to 'src/platform')
-rw-r--r-- | src/platform/desktop-web/left-column.tsx | 57 | ||||
-rw-r--r-- | src/platform/desktop-web/right-column.tsx | 19 | ||||
-rw-r--r-- | src/platform/desktop-web/shell.tsx | 35 | ||||
-rw-r--r-- | src/platform/detection.ts | 11 | ||||
-rw-r--r-- | src/platform/shell.tsx | 12 |
5 files changed, 134 insertions, 0 deletions
diff --git a/src/platform/desktop-web/left-column.tsx b/src/platform/desktop-web/left-column.tsx new file mode 100644 index 000000000..082231ec9 --- /dev/null +++ b/src/platform/desktop-web/left-column.tsx @@ -0,0 +1,57 @@ +import React from 'react' +import {Pressable, View, StyleSheet} from 'react-native' +import {Link} from '@react-navigation/native' +import {useRoute} from '@react-navigation/native' + +export const NavItem: React.FC<{label: string; screen: string}> = ({ + label, + screen, +}) => { + const route = useRoute() + return ( + <View> + <Pressable + style={state => [ + // @ts-ignore it does exist! (react-native-web) -prf + state.hovered && styles.navItemHovered, + ]}> + <Link + style={[ + styles.navItemLink, + route.name === screen && styles.navItemLinkSelected, + ]} + to={{screen, params: {}}}> + {label} + </Link> + </Pressable> + </View> + ) +} + +export const DesktopLeftColumn: React.FC = () => { + return ( + <View style={styles.container}> + <NavItem screen="Home" label="Home" /> + <NavItem screen="Search" label="Search" /> + <NavItem screen="Notifications" label="Notifications" /> + </View> + ) +} + +const styles = StyleSheet.create({ + container: { + position: 'absolute', + left: 'calc(50vw - 500px)', + width: '200px', + height: '100%', + }, + navItemHovered: { + backgroundColor: 'gray', + }, + navItemLink: { + padding: '1rem', + }, + navItemLinkSelected: { + color: 'blue', + }, +}) diff --git a/src/platform/desktop-web/right-column.tsx b/src/platform/desktop-web/right-column.tsx new file mode 100644 index 000000000..5fe65cac8 --- /dev/null +++ b/src/platform/desktop-web/right-column.tsx @@ -0,0 +1,19 @@ +import React from 'react' +import {Text, View, StyleSheet} from 'react-native' + +export const DesktopRightColumn: React.FC = () => { + return ( + <View style={styles.container}> + <Text>Right Column</Text> + </View> + ) +} + +const styles = StyleSheet.create({ + container: { + position: 'absolute', + right: 'calc(50vw - 500px)', + width: '200px', + height: '100%', + }, +}) diff --git a/src/platform/desktop-web/shell.tsx b/src/platform/desktop-web/shell.tsx new file mode 100644 index 000000000..ef880306b --- /dev/null +++ b/src/platform/desktop-web/shell.tsx @@ -0,0 +1,35 @@ +import React from 'react' +import {observer} from 'mobx-react-lite' +import {View, StyleSheet} from 'react-native' +import {DesktopLeftColumn} from './left-column' +import {DesktopRightColumn} from './right-column' +import {useStores} from '../../state' + +export const DesktopWebShell: React.FC = observer(({children}) => { + const store = useStores() + return ( + <View style={styles.outerContainer}> + {store.session.isAuthed ? ( + <> + <DesktopLeftColumn /> + <View style={styles.innerContainer}>{children}</View> + <DesktopRightColumn /> + </> + ) : ( + <View style={styles.innerContainer}>{children}</View> + )} + </View> + ) +}) + +const styles = StyleSheet.create({ + outerContainer: { + height: '100%', + }, + innerContainer: { + marginLeft: 'auto', + marginRight: 'auto', + width: '600px', + height: '100%', + }, +}) diff --git a/src/platform/detection.ts b/src/platform/detection.ts new file mode 100644 index 000000000..5d2ffcb22 --- /dev/null +++ b/src/platform/detection.ts @@ -0,0 +1,11 @@ +import {Platform} from 'react-native' + +export const isIOS = Platform.OS === 'ios' +export const isAndroid = Platform.OS === 'android' +export const isNative = isIOS || isAndroid +export const isWeb = !isNative +export const isMobileWeb = + isWeb && + // @ts-ignore we know window exists -prf + global.window.matchMedia('only screen and (max-width: 1000px)')?.matches +export const isDesktopWeb = isWeb && !isMobileWeb diff --git a/src/platform/shell.tsx b/src/platform/shell.tsx new file mode 100644 index 000000000..ec8d51e1f --- /dev/null +++ b/src/platform/shell.tsx @@ -0,0 +1,12 @@ +import React from 'react' +import {SafeAreaView} from 'react-native' +import {isDesktopWeb} from './detection' +import {DesktopWebShell} from './desktop-web/shell' + +export const Shell: React.FC = ({children}) => { + return isDesktopWeb ? ( + <DesktopWebShell>{children}</DesktopWebShell> + ) : ( + <SafeAreaView>{children}</SafeAreaView> + ) +} |