Fix web home feed sizing and related issues (close #432) (#475)

* Fix web home feed sizing (close #432)

* Fix lint

* Fix positioning of profile not found error

* Fix load latest on mobile

* Fix overflow issues on mobile web (visible in postthread)

* Fix bottom pad on mobile web

* Remove old comment
zio/stable
Paul Frazee 2023-04-15 10:15:30 -07:00 committed by GitHub
parent a79dcd3d38
commit 91fadadb58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 109 additions and 24 deletions

View File

@ -1,5 +1,6 @@
import {StyleProp, StyleSheet, TextStyle} from 'react-native' import {StyleProp, StyleSheet, TextStyle} from 'react-native'
import {Theme, TypographyVariant} from './ThemeContext' import {Theme, TypographyVariant} from './ThemeContext'
import {isMobileWeb} from 'platform/detection'
// 1 is lightest, 2 is light, 3 is mid, 4 is dark, 5 is darkest // 1 is lightest, 2 is light, 3 is mid, 4 is dark, 5 is darkest
export const colors = { export const colors = {
@ -162,7 +163,7 @@ export const s = StyleSheet.create({
// dimensions // dimensions
w100pct: {width: '100%'}, w100pct: {width: '100%'},
h100pct: {height: '100%'}, h100pct: {height: '100%'},
hContentRegion: {height: '100%'}, hContentRegion: isMobileWeb ? {flex: 1} : {height: '100%'},
// text align // text align
textLeft: {textAlign: 'left'}, textLeft: {textAlign: 'left'},

View File

@ -1,30 +1,76 @@
import React from 'react' import React from 'react'
import {Animated, StyleSheet} from 'react-native'
import {observer} from 'mobx-react-lite' import {observer} from 'mobx-react-lite'
import {TabBar} from 'view/com/pager/TabBar' import {TabBar} from 'view/com/pager/TabBar'
import {CenteredView} from 'view/com/util/Views'
import {RenderTabBarFnProps} from 'view/com/pager/Pager' import {RenderTabBarFnProps} from 'view/com/pager/Pager'
import {useStores} from 'state/index'
import {usePalette} from 'lib/hooks/usePalette' import {usePalette} from 'lib/hooks/usePalette'
import {useAnimatedValue} from 'lib/hooks/useAnimatedValue'
import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries' import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
import {FeedsTabBar as FeedsTabBarMobile} from './FeedsTabBarMobile' import {FeedsTabBar as FeedsTabBarMobile} from './FeedsTabBarMobile'
export const FeedsTabBar = observer( export const FeedsTabBar = observer(
(props: RenderTabBarFnProps & {onPressSelected: () => void}) => { (
const pal = usePalette('default') props: RenderTabBarFnProps & {testID?: string; onPressSelected: () => void},
) => {
const {isDesktop} = useWebMediaQueries() const {isDesktop} = useWebMediaQueries()
if (!isDesktop) { if (!isDesktop) {
return <FeedsTabBarMobile {...props} /> return <FeedsTabBarMobile {...props} />
} else {
return <FeedsTabBarDesktop {...props} />
} }
},
)
const FeedsTabBarDesktop = observer(
(
props: RenderTabBarFnProps & {testID?: string; onPressSelected: () => void},
) => {
const store = useStores()
const pal = usePalette('default')
const interp = useAnimatedValue(0)
React.useEffect(() => {
Animated.timing(interp, {
toValue: store.shell.minimalShellMode ? 1 : 0,
duration: 100,
useNativeDriver: true,
isInteraction: false,
}).start()
}, [interp, store.shell.minimalShellMode])
const transform = {
transform: [
{translateX: '-50%'},
{translateY: Animated.multiply(interp, -100)},
],
}
return ( return (
<CenteredView> // @ts-ignore the type signature for transform wrong here, translateX and translateY need to be in separate objects -prf
<Animated.View style={[pal.view, styles.tabBar, transform]}>
<TabBar <TabBar
{...props} {...props}
items={['Following', "What's hot"]} items={['Following', "What's hot"]}
indicatorPosition="bottom" indicatorPosition="bottom"
indicatorColor={pal.colors.link} indicatorColor={pal.colors.link}
/> />
</CenteredView> </Animated.View>
) )
}, },
) )
const styles = StyleSheet.create({
tabBar: {
position: 'absolute',
zIndex: 1,
left: '50%',
width: 640,
top: 0,
flexDirection: 'row',
alignItems: 'center',
paddingHorizontal: 18,
},
tabBarAvi: {
marginTop: 1,
marginRight: 18,
},
})

View File

@ -21,14 +21,14 @@ import {ComposePrompt} from '../composer/Prompt'
import {ErrorMessage} from '../util/error/ErrorMessage' import {ErrorMessage} from '../util/error/ErrorMessage'
import {Text} from '../util/text/Text' import {Text} from '../util/text/Text'
import {s} from 'lib/styles' import {s} from 'lib/styles'
import {isDesktopWeb} from 'platform/detection' import {isDesktopWeb, isMobileWeb} from 'platform/detection'
import {usePalette} from 'lib/hooks/usePalette' import {usePalette} from 'lib/hooks/usePalette'
import {useNavigation} from '@react-navigation/native' import {useNavigation} from '@react-navigation/native'
import {NavigationProp} from 'lib/routes/types' import {NavigationProp} from 'lib/routes/types'
const REPLY_PROMPT = {_reactKey: '__reply__', _isHighlightedPost: false} const REPLY_PROMPT = {_reactKey: '__reply__', _isHighlightedPost: false}
const BOTTOM_BORDER = { const BOTTOM_COMPONENT = {
_reactKey: '__bottom_border__', _reactKey: '__bottom_component__',
_isHighlightedPost: false, _isHighlightedPost: false,
} }
type YieldedItem = PostThreadItemModel | typeof REPLY_PROMPT type YieldedItem = PostThreadItemModel | typeof REPLY_PROMPT
@ -48,7 +48,7 @@ export const PostThread = observer(function PostThread({
const navigation = useNavigation<NavigationProp>() const navigation = useNavigation<NavigationProp>()
const posts = React.useMemo(() => { const posts = React.useMemo(() => {
if (view.thread) { if (view.thread) {
return Array.from(flattenThread(view.thread)).concat([BOTTOM_BORDER]) return Array.from(flattenThread(view.thread)).concat([BOTTOM_COMPONENT])
} }
return [] return []
}, [view.thread]) }, [view.thread])
@ -103,12 +103,23 @@ export const PostThread = observer(function PostThread({
({item}: {item: YieldedItem}) => { ({item}: {item: YieldedItem}) => {
if (item === REPLY_PROMPT) { if (item === REPLY_PROMPT) {
return <ComposePrompt onPressCompose={onPressReply} /> return <ComposePrompt onPressCompose={onPressReply} />
} else if (item === BOTTOM_BORDER) { } else if (item === BOTTOM_COMPONENT) {
// HACK // HACK
// due to some complexities with how flatlist works, this is the easiest way // due to some complexities with how flatlist works, this is the easiest way
// I could find to get a border positioned directly under the last item // I could find to get a border positioned directly under the last item
// -
// addendum -- it's also the best way to get mobile web to add padding
// at the bottom of the thread since paddingbottom is ignored. yikes.
// -prf // -prf
return <View style={[styles.bottomBorder, pal.border]} /> return (
<View
style={[
styles.bottomBorder,
pal.border,
isMobileWeb && styles.bottomSpacer,
]}
/>
)
} else if (item instanceof PostThreadItemModel) { } else if (item instanceof PostThreadItemModel) {
return <PostThreadItem item={item} onPostReply={onRefresh} /> return <PostThreadItem item={item} onPostReply={onRefresh} />
} }
@ -224,4 +235,7 @@ const styles = StyleSheet.create({
bottomBorder: { bottomBorder: {
borderBottomWidth: 1, borderBottomWidth: 1,
}, },
bottomSpacer: {
height: 200,
},
}) })

View File

@ -35,6 +35,8 @@ export function CenteredView({
export const FlatList = React.forwardRef(function <ItemT>( export const FlatList = React.forwardRef(function <ItemT>(
{ {
contentContainerStyle, contentContainerStyle,
style,
contentOffset,
...props ...props
}: React.PropsWithChildren<FlatListProps<ItemT>>, }: React.PropsWithChildren<FlatListProps<ItemT>>,
ref: React.Ref<RNFlatList>, ref: React.Ref<RNFlatList>,
@ -43,10 +45,25 @@ export const FlatList = React.forwardRef(function <ItemT>(
contentContainerStyle, contentContainerStyle,
styles.containerScroll, styles.containerScroll,
) )
if (contentOffset && contentOffset?.y !== 0) {
// NOTE
// we use paddingTop & contentOffset to space around the floating header
// but reactnative web puts the paddingTop on the wrong element (style instead of the contentContainer)
// so we manually correct it here
// -prf
style = addStyle(style, {
paddingTop: 0,
})
contentContainerStyle = addStyle(contentContainerStyle, {
paddingTop: Math.abs(contentOffset.y),
})
}
return ( return (
<RNFlatList <RNFlatList
contentContainerStyle={contentContainerStyle}
ref={ref} ref={ref}
contentContainerStyle={contentContainerStyle}
style={style}
contentOffset={contentOffset}
{...props} {...props}
/> />
) )

View File

@ -8,6 +8,7 @@ import {Text} from '../text/Text'
import {colors} from 'lib/styles' import {colors} from 'lib/styles'
import {useTheme} from 'lib/ThemeContext' import {useTheme} from 'lib/ThemeContext'
import {usePalette} from 'lib/hooks/usePalette' import {usePalette} from 'lib/hooks/usePalette'
import {CenteredView} from '../Views'
export function ErrorScreen({ export function ErrorScreen({
title, title,
@ -25,7 +26,7 @@ export function ErrorScreen({
const theme = useTheme() const theme = useTheme()
const pal = usePalette('error') const pal = usePalette('error')
return ( return (
<View testID={testID} style={[styles.outer, pal.view]}> <CenteredView testID={testID} style={[styles.outer, pal.view]}>
<View style={styles.errorIconContainer}> <View style={styles.errorIconContainer}>
<View <View
style={[ style={[
@ -72,7 +73,7 @@ export function ErrorScreen({
</TouchableOpacity> </TouchableOpacity>
</View> </View>
)} )}
</View> </CenteredView>
) )
} }

View File

@ -0,0 +1 @@
export * from './LoadLatestBtnMobile'

View File

@ -1,8 +1,10 @@
import React from 'react' import React from 'react'
import {StyleSheet, TouchableOpacity} from 'react-native' import {StyleSheet, TouchableOpacity} from 'react-native'
import {Text} from './text/Text' import {Text} from '../text/Text'
import {usePalette} from 'lib/hooks/usePalette' import {usePalette} from 'lib/hooks/usePalette'
import {UpIcon} from 'lib/icons' import {UpIcon} from 'lib/icons'
import {LoadLatestBtn as LoadLatestBtnMobile} from './LoadLatestBtnMobile'
import {isMobileWeb} from 'platform/detection'
const HITSLOP = {left: 20, top: 20, right: 20, bottom: 20} const HITSLOP = {left: 20, top: 20, right: 20, bottom: 20}
@ -14,6 +16,9 @@ export const LoadLatestBtn = ({
label: string label: string
}) => { }) => {
const pal = usePalette('default') const pal = usePalette('default')
if (isMobileWeb) {
return <LoadLatestBtnMobile onPress={onPress} label={label} />
}
return ( return (
<TouchableOpacity <TouchableOpacity
style={[pal.view, pal.borderDark, styles.loadLatest]} style={[pal.view, pal.borderDark, styles.loadLatest]}

View File

@ -3,7 +3,7 @@ import {StyleSheet, TouchableOpacity} from 'react-native'
import {observer} from 'mobx-react-lite' import {observer} from 'mobx-react-lite'
import LinearGradient from 'react-native-linear-gradient' import LinearGradient from 'react-native-linear-gradient'
import {useSafeAreaInsets} from 'react-native-safe-area-context' import {useSafeAreaInsets} from 'react-native-safe-area-context'
import {Text} from './text/Text' import {Text} from '../text/Text'
import {colors, gradients} from 'lib/styles' import {colors, gradients} from 'lib/styles'
import {clamp} from 'lodash' import {clamp} from 'lodash'
import {useStores} from 'state/index' import {useStores} from 'state/index'

View File

@ -1,5 +1,5 @@
import React from 'react' import React from 'react'
import {FlatList, View, Platform} from 'react-native' import {FlatList, View} from 'react-native'
import {useFocusEffect, useIsFocused} from '@react-navigation/native' import {useFocusEffect, useIsFocused} from '@react-navigation/native'
import {observer} from 'mobx-react-lite' import {observer} from 'mobx-react-lite'
import useAppState from 'react-native-appstate-hook' import useAppState from 'react-native-appstate-hook'
@ -8,7 +8,7 @@ import {PostsFeedModel} from 'state/models/feeds/posts'
import {withAuthRequired} from 'view/com/auth/withAuthRequired' import {withAuthRequired} from 'view/com/auth/withAuthRequired'
import {Feed} from '../com/posts/Feed' import {Feed} from '../com/posts/Feed'
import {FollowingEmptyState} from 'view/com/posts/FollowingEmptyState' import {FollowingEmptyState} from 'view/com/posts/FollowingEmptyState'
import {LoadLatestBtn} from '../com/util/LoadLatestBtn' import {LoadLatestBtn} from '../com/util/load-latest/LoadLatestBtn'
import {FeedsTabBar} from '../com/pager/FeedsTabBar' import {FeedsTabBar} from '../com/pager/FeedsTabBar'
import {Pager, RenderTabBarFnProps} from 'view/com/pager/Pager' import {Pager, RenderTabBarFnProps} from 'view/com/pager/Pager'
import {FAB} from '../com/util/fab/FAB' import {FAB} from '../com/util/fab/FAB'
@ -17,9 +17,9 @@ import {s} from 'lib/styles'
import {useOnMainScroll} from 'lib/hooks/useOnMainScroll' import {useOnMainScroll} from 'lib/hooks/useOnMainScroll'
import {useAnalytics} from 'lib/analytics' import {useAnalytics} from 'lib/analytics'
import {ComposeIcon2} from 'lib/icons' import {ComposeIcon2} from 'lib/icons'
import {isDesktopWeb, isMobileWeb} from 'platform/detection' import {isDesktopWeb} from 'platform/detection'
const HEADER_OFFSET = isDesktopWeb ? 0 : isMobileWeb ? 20 : 40 const HEADER_OFFSET = isDesktopWeb ? 50 : 40
type Props = NativeStackScreenProps<HomeTabNavigatorParams, 'Home'> type Props = NativeStackScreenProps<HomeTabNavigatorParams, 'Home'>
export const HomeScreen = withAuthRequired((_opts: Props) => { export const HomeScreen = withAuthRequired((_opts: Props) => {
@ -191,7 +191,7 @@ const FeedPage = observer(
onPressTryAgain={onPressTryAgain} onPressTryAgain={onPressTryAgain}
onScroll={onMainScroll} onScroll={onMainScroll}
renderEmptyState={renderEmptyState} renderEmptyState={renderEmptyState}
headerOffset={Platform.OS === 'web' ? 0 : HEADER_OFFSET} // only offset on mobile headerOffset={HEADER_OFFSET}
/> />
{feed.hasNewLatest && !feed.isRefreshing && ( {feed.hasNewLatest && !feed.isRefreshing && (
<LoadLatestBtn onPress={onPressLoadLatest} label="posts" /> <LoadLatestBtn onPress={onPressLoadLatest} label="posts" />

View File

@ -10,7 +10,7 @@ import {withAuthRequired} from 'view/com/auth/withAuthRequired'
import {ViewHeader} from '../com/util/ViewHeader' import {ViewHeader} from '../com/util/ViewHeader'
import {Feed} from '../com/notifications/Feed' import {Feed} from '../com/notifications/Feed'
import {InvitedUsers} from '../com/notifications/InvitedUsers' import {InvitedUsers} from '../com/notifications/InvitedUsers'
import {LoadLatestBtn} from 'view/com/util/LoadLatestBtn' import {LoadLatestBtn} from 'view/com/util/load-latest/LoadLatestBtn'
import {useStores} from 'state/index' import {useStores} from 'state/index'
import {useOnMainScroll} from 'lib/hooks/useOnMainScroll' import {useOnMainScroll} from 'lib/hooks/useOnMainScroll'
import {s} from 'lib/styles' import {s} from 'lib/styles'