diff options
author | Paul Frazee <pfrazee@gmail.com> | 2023-08-30 16:18:21 -0700 |
---|---|---|
committer | Paul Frazee <pfrazee@gmail.com> | 2023-08-30 16:18:21 -0700 |
commit | f9cab178b9ee2a0ccfde7e0e2cbabff7600de69c (patch) | |
tree | c8609bd39cad46a232153a3d3a598ed1b667a027 /src/view/com/util | |
parent | 9446c67880331452b3f79dabda183c23718edfa1 (diff) | |
parent | 59dcedeea25804188b3503dbf166fa794af20612 (diff) | |
download | voidsky-f9cab178b9ee2a0ccfde7e0e2cbabff7600de69c.tar.zst |
Merge branch 'ansh/app-812-add-custom-feed-discovery-to-onboarding' into main
Diffstat (limited to 'src/view/com/util')
-rw-r--r-- | src/view/com/util/ViewHeader.tsx | 78 | ||||
-rw-r--r-- | src/view/com/util/layouts/Breakpoints.tsx | 8 | ||||
-rw-r--r-- | src/view/com/util/layouts/Breakpoints.web.tsx | 20 | ||||
-rw-r--r-- | src/view/com/util/layouts/TitleColumnLayout.tsx | 69 | ||||
-rw-r--r-- | src/view/com/util/layouts/withBreakpoints.tsx | 21 |
5 files changed, 166 insertions, 30 deletions
diff --git a/src/view/com/util/ViewHeader.tsx b/src/view/com/util/ViewHeader.tsx index f5a921ac0..7482db8eb 100644 --- a/src/view/com/util/ViewHeader.tsx +++ b/src/view/com/util/ViewHeader.tsx @@ -17,6 +17,7 @@ const BACK_HITSLOP = {left: 20, top: 20, right: 50, bottom: 20} export const ViewHeader = observer(function ({ title, canGoBack, + showBackButton = true, hideOnScroll, showOnDesktop, showBorder, @@ -24,6 +25,7 @@ export const ViewHeader = observer(function ({ }: { title: string canGoBack?: boolean + showBackButton?: boolean hideOnScroll?: boolean showOnDesktop?: boolean showBorder?: boolean @@ -49,7 +51,13 @@ export const ViewHeader = observer(function ({ if (isDesktopWeb) { if (showOnDesktop) { - return <DesktopWebHeader title={title} renderButton={renderButton} /> + return ( + <DesktopWebHeader + title={title} + renderButton={renderButton} + showBorder={showBorder} + /> + ) } return null } else { @@ -59,30 +67,32 @@ export const ViewHeader = observer(function ({ return ( <Container hideOnScroll={hideOnScroll || false} showBorder={showBorder}> - <TouchableOpacity - testID="viewHeaderDrawerBtn" - onPress={canGoBack ? onPressBack : onPressMenu} - hitSlop={BACK_HITSLOP} - style={canGoBack ? styles.backBtn : styles.backBtnWide} - accessibilityRole="button" - accessibilityLabel={canGoBack ? 'Back' : 'Menu'} - accessibilityHint={ - canGoBack ? '' : 'Access navigation links and settings' - }> - {canGoBack ? ( - <FontAwesomeIcon - size={18} - icon="angle-left" - style={[styles.backIcon, pal.text]} - /> - ) : ( - <FontAwesomeIcon - size={18} - icon="bars" - style={[styles.backIcon, pal.textLight]} - /> - )} - </TouchableOpacity> + {showBackButton ? ( + <TouchableOpacity + testID="viewHeaderDrawerBtn" + onPress={canGoBack ? onPressBack : onPressMenu} + hitSlop={BACK_HITSLOP} + style={canGoBack ? styles.backBtn : styles.backBtnWide} + accessibilityRole="button" + accessibilityLabel={canGoBack ? 'Back' : 'Menu'} + accessibilityHint={ + canGoBack ? '' : 'Access navigation links and settings' + }> + {canGoBack ? ( + <FontAwesomeIcon + size={18} + icon="angle-left" + style={[styles.backIcon, pal.text]} + /> + ) : ( + <FontAwesomeIcon + size={18} + icon="bars" + style={[styles.backIcon, pal.textLight]} + /> + )} + </TouchableOpacity> + ) : null} <View style={styles.titleContainer} pointerEvents="none"> <Text type="title" style={[pal.text, styles.title]}> {title} @@ -90,9 +100,9 @@ export const ViewHeader = observer(function ({ </View> {renderButton ? ( renderButton() - ) : ( + ) : showBackButton ? ( <View style={canGoBack ? styles.backBtn : styles.backBtnWide} /> - )} + ) : null} </Container> ) } @@ -101,13 +111,23 @@ export const ViewHeader = observer(function ({ function DesktopWebHeader({ title, renderButton, + showBorder = true, }: { title: string renderButton?: () => JSX.Element + showBorder?: boolean }) { const pal = usePalette('default') return ( - <CenteredView style={[styles.header, styles.desktopHeader, pal.border]}> + <CenteredView + style={[ + styles.header, + styles.desktopHeader, + pal.border, + { + borderBottomWidth: showBorder ? 1 : 0, + }, + ]}> <View style={styles.titleContainer} pointerEvents="none"> <Text type="title-lg" style={[pal.text, styles.title]}> {title} @@ -195,13 +215,11 @@ const styles = StyleSheet.create({ width: '100%', }, desktopHeader: { - borderBottomWidth: 1, paddingVertical: 12, }, border: { borderBottomWidth: 1, }, - titleContainer: { marginLeft: 'auto', marginRight: 'auto', diff --git a/src/view/com/util/layouts/Breakpoints.tsx b/src/view/com/util/layouts/Breakpoints.tsx new file mode 100644 index 000000000..51c3ccd5a --- /dev/null +++ b/src/view/com/util/layouts/Breakpoints.tsx @@ -0,0 +1,8 @@ +import React from 'react' + +export const Desktop = ({}: React.PropsWithChildren<{}>) => null +export const TabletOrDesktop = ({}: React.PropsWithChildren<{}>) => null +export const Tablet = ({}: React.PropsWithChildren<{}>) => null +export const TabletOrMobile = ({children}: React.PropsWithChildren<{}>) => + children +export const Mobile = ({children}: React.PropsWithChildren<{}>) => children diff --git a/src/view/com/util/layouts/Breakpoints.web.tsx b/src/view/com/util/layouts/Breakpoints.web.tsx new file mode 100644 index 000000000..7031a1735 --- /dev/null +++ b/src/view/com/util/layouts/Breakpoints.web.tsx @@ -0,0 +1,20 @@ +import React from 'react' +import MediaQuery from 'react-responsive' + +export const Desktop = ({children}: React.PropsWithChildren<{}>) => ( + <MediaQuery minWidth={1224}>{children}</MediaQuery> +) +export const TabletOrDesktop = ({children}: React.PropsWithChildren<{}>) => ( + <MediaQuery minWidth={800}>{children}</MediaQuery> +) +export const Tablet = ({children}: React.PropsWithChildren<{}>) => ( + <MediaQuery minWidth={800} maxWidth={1224}> + {children} + </MediaQuery> +) +export const TabletOrMobile = ({children}: React.PropsWithChildren<{}>) => ( + <MediaQuery maxWidth={1224}>{children}</MediaQuery> +) +export const Mobile = ({children}: React.PropsWithChildren<{}>) => ( + <MediaQuery maxWidth={800}>{children}</MediaQuery> +) diff --git a/src/view/com/util/layouts/TitleColumnLayout.tsx b/src/view/com/util/layouts/TitleColumnLayout.tsx new file mode 100644 index 000000000..49ad9fcdb --- /dev/null +++ b/src/view/com/util/layouts/TitleColumnLayout.tsx @@ -0,0 +1,69 @@ +import React from 'react' +import {StyleProp, StyleSheet, View, ViewStyle} from 'react-native' +import {usePalette} from 'lib/hooks/usePalette' +import {useColorSchemeStyle} from 'lib/hooks/useColorSchemeStyle' + +interface Props { + testID?: string + title: JSX.Element + horizontal: boolean + titleStyle?: StyleProp<ViewStyle> + contentStyle?: StyleProp<ViewStyle> +} + +export function TitleColumnLayout({ + testID, + title, + horizontal, + children, + titleStyle, + contentStyle, +}: React.PropsWithChildren<Props>) { + const pal = usePalette('default') + const titleBg = useColorSchemeStyle(pal.viewLight, pal.view) + const contentBg = useColorSchemeStyle(pal.view, { + backgroundColor: pal.colors.background, + borderColor: pal.colors.border, + borderLeftWidth: 1, + }) + + const layoutStyles = horizontal ? styles2Column : styles1Column + return ( + <View testID={testID} style={layoutStyles.container}> + <View style={[layoutStyles.title, titleBg, titleStyle]}>{title}</View> + <View style={[layoutStyles.content, contentBg, contentStyle]}> + {children} + </View> + </View> + ) +} + +const styles2Column = StyleSheet.create({ + container: { + flexDirection: 'row', + height: '100%', + }, + title: { + flex: 1, + paddingHorizontal: 40, + paddingBottom: 80, + justifyContent: 'center', + }, + content: { + flex: 2, + paddingHorizontal: 40, + justifyContent: 'center', + }, +}) + +const styles1Column = StyleSheet.create({ + container: {}, + title: { + paddingHorizontal: 40, + paddingVertical: 40, + }, + content: { + paddingHorizontal: 40, + paddingVertical: 40, + }, +}) diff --git a/src/view/com/util/layouts/withBreakpoints.tsx b/src/view/com/util/layouts/withBreakpoints.tsx new file mode 100644 index 000000000..dc3f50dc9 --- /dev/null +++ b/src/view/com/util/layouts/withBreakpoints.tsx @@ -0,0 +1,21 @@ +import React from 'react' +import {isNative} from 'platform/detection' +import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries' + +export const withBreakpoints = + <P extends object>( + Mobile: React.ComponentType<P>, + Tablet: React.ComponentType<P>, + Desktop: React.ComponentType<P>, + ): React.FC<P> => + (props: P) => { + const {isMobile, isTabletOrMobile} = useWebMediaQueries() + + if (isMobile || isNative) { + return <Mobile {...props} /> + } + if (isTabletOrMobile) { + return <Tablet {...props} /> + } + return <Desktop {...props} /> + } |