Sticky desktop header (#3077)
parent
f2249614be
commit
b70c404d4b
|
@ -52,7 +52,7 @@ export function HomeHeader(
|
||||||
)
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<HomeHeaderLayout>
|
<HomeHeaderLayout tabBarAnchor={props.tabBarAnchor}>
|
||||||
<TabBar
|
<TabBar
|
||||||
key={items.join(',')}
|
key={items.join(',')}
|
||||||
onPressSelected={props.onPressSelected}
|
onPressSelected={props.onPressSelected}
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import {StyleSheet, View} from 'react-native'
|
import {StyleSheet, View} from 'react-native'
|
||||||
import Animated from 'react-native-reanimated'
|
|
||||||
import {usePalette} from 'lib/hooks/usePalette'
|
import {usePalette} from 'lib/hooks/usePalette'
|
||||||
import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
|
import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
|
||||||
import {HomeHeaderLayoutMobile} from './HomeHeaderLayoutMobile'
|
import {HomeHeaderLayoutMobile} from './HomeHeaderLayoutMobile'
|
||||||
import {useMinimalShellMode} from 'lib/hooks/useMinimalShellMode'
|
|
||||||
import {useShellLayout} from '#/state/shell/shell-layout'
|
|
||||||
import {Logo} from '#/view/icons/Logo'
|
import {Logo} from '#/view/icons/Logo'
|
||||||
import {Link, TextLink} from '../util/Link'
|
import {Link} from '../util/Link'
|
||||||
import {
|
import {
|
||||||
FontAwesomeIcon,
|
FontAwesomeIcon,
|
||||||
FontAwesomeIconStyle,
|
FontAwesomeIconStyle,
|
||||||
|
@ -16,41 +13,42 @@ import {useLingui} from '@lingui/react'
|
||||||
import {msg} from '@lingui/macro'
|
import {msg} from '@lingui/macro'
|
||||||
import {CogIcon} from '#/lib/icons'
|
import {CogIcon} from '#/lib/icons'
|
||||||
|
|
||||||
export function HomeHeaderLayout({children}: {children: React.ReactNode}) {
|
export function HomeHeaderLayout(props: {
|
||||||
|
children: React.ReactNode
|
||||||
|
tabBarAnchor: JSX.Element | null | undefined
|
||||||
|
}) {
|
||||||
const {isMobile} = useWebMediaQueries()
|
const {isMobile} = useWebMediaQueries()
|
||||||
if (isMobile) {
|
if (isMobile) {
|
||||||
return <HomeHeaderLayoutMobile>{children}</HomeHeaderLayoutMobile>
|
return <HomeHeaderLayoutMobile {...props} />
|
||||||
} else {
|
} else {
|
||||||
return <HomeHeaderLayoutTablet>{children}</HomeHeaderLayoutTablet>
|
return <HomeHeaderLayoutDesktopAndTablet {...props} />
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function HomeHeaderLayoutTablet({children}: {children: React.ReactNode}) {
|
function HomeHeaderLayoutDesktopAndTablet({
|
||||||
|
children,
|
||||||
|
tabBarAnchor,
|
||||||
|
}: {
|
||||||
|
children: React.ReactNode
|
||||||
|
tabBarAnchor: JSX.Element | null | undefined
|
||||||
|
}) {
|
||||||
const pal = usePalette('default')
|
const pal = usePalette('default')
|
||||||
const {headerMinimalShellTransform} = useMinimalShellMode()
|
|
||||||
const {headerHeight} = useShellLayout()
|
|
||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
// @ts-ignore the type signature for transform wrong here, translateX and translateY need to be in separate objects -prf
|
<>
|
||||||
<Animated.View
|
<View style={[pal.view, pal.border, styles.bar, styles.topBar]}>
|
||||||
style={[pal.view, pal.border, styles.tabBar, headerMinimalShellTransform]}
|
<Link
|
||||||
onLayout={e => {
|
|
||||||
headerHeight.value = e.nativeEvent.layout.height
|
|
||||||
}}>
|
|
||||||
<View style={[pal.view, styles.topBar]}>
|
|
||||||
<TextLink
|
|
||||||
type="title-lg"
|
|
||||||
href="/settings/following-feed"
|
href="/settings/following-feed"
|
||||||
|
hitSlop={10}
|
||||||
|
accessibilityRole="button"
|
||||||
accessibilityLabel={_(msg`Following Feed Preferences`)}
|
accessibilityLabel={_(msg`Following Feed Preferences`)}
|
||||||
accessibilityHint=""
|
accessibilityHint="">
|
||||||
text={
|
<FontAwesomeIcon
|
||||||
<FontAwesomeIcon
|
icon="sliders"
|
||||||
icon="sliders"
|
style={pal.textLight as FontAwesomeIconStyle}
|
||||||
style={pal.textLight as FontAwesomeIconStyle}
|
/>
|
||||||
/>
|
</Link>
|
||||||
}
|
|
||||||
/>
|
|
||||||
<Logo width={28} />
|
<Logo width={28} />
|
||||||
<Link
|
<Link
|
||||||
href="/settings/saved-feeds"
|
href="/settings/saved-feeds"
|
||||||
|
@ -61,32 +59,38 @@ function HomeHeaderLayoutTablet({children}: {children: React.ReactNode}) {
|
||||||
<CogIcon size={22} strokeWidth={2} style={pal.textLight} />
|
<CogIcon size={22} strokeWidth={2} style={pal.textLight} />
|
||||||
</Link>
|
</Link>
|
||||||
</View>
|
</View>
|
||||||
{children}
|
{tabBarAnchor}
|
||||||
</Animated.View>
|
<View style={[pal.view, pal.border, styles.bar, styles.tabBar]}>
|
||||||
|
{children}
|
||||||
|
</View>
|
||||||
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
|
bar: {
|
||||||
|
// @ts-ignore Web only
|
||||||
|
left: 'calc(50% - 300px)',
|
||||||
|
width: 600,
|
||||||
|
borderLeftWidth: 1,
|
||||||
|
borderRightWidth: 1,
|
||||||
|
},
|
||||||
topBar: {
|
topBar: {
|
||||||
flexDirection: 'row',
|
flexDirection: 'row',
|
||||||
justifyContent: 'space-between',
|
justifyContent: 'space-between',
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
paddingHorizontal: 18,
|
paddingHorizontal: 18,
|
||||||
paddingVertical: 8,
|
paddingTop: 16,
|
||||||
marginTop: 8,
|
paddingBottom: 8,
|
||||||
width: '100%',
|
|
||||||
},
|
},
|
||||||
tabBar: {
|
tabBar: {
|
||||||
// @ts-ignore Web only
|
// @ts-ignore Web only
|
||||||
position: 'sticky',
|
position: 'sticky',
|
||||||
zIndex: 1,
|
|
||||||
// @ts-ignore Web only -prf
|
|
||||||
left: 'calc(50% - 300px)',
|
|
||||||
width: 600,
|
|
||||||
top: 0,
|
top: 0,
|
||||||
flexDirection: 'column',
|
flexDirection: 'column',
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
borderLeftWidth: 1,
|
borderLeftWidth: 1,
|
||||||
borderRightWidth: 1,
|
borderRightWidth: 1,
|
||||||
|
zIndex: 1,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
@ -23,6 +23,7 @@ export function HomeHeaderLayoutMobile({
|
||||||
children,
|
children,
|
||||||
}: {
|
}: {
|
||||||
children: React.ReactNode
|
children: React.ReactNode
|
||||||
|
tabBarAnchor: JSX.Element | null | undefined
|
||||||
}) {
|
}) {
|
||||||
const pal = usePalette('default')
|
const pal = usePalette('default')
|
||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
|
|
|
@ -123,8 +123,7 @@ function HomeScreenReady({
|
||||||
return (
|
return (
|
||||||
<HomeHeader
|
<HomeHeader
|
||||||
key="FEEDS_TAB_BAR"
|
key="FEEDS_TAB_BAR"
|
||||||
selectedPage={props.selectedPage}
|
{...props}
|
||||||
onSelect={props.onSelect}
|
|
||||||
testID="homeScreenFeedTabs"
|
testID="homeScreenFeedTabs"
|
||||||
onPressSelected={onPressSelected}
|
onPressSelected={onPressSelected}
|
||||||
feeds={pinnedFeedInfos}
|
feeds={pinnedFeedInfos}
|
||||||
|
|
Loading…
Reference in New Issue