Skip to content

Commit f8bd850

Browse files
authored
Fix labeler header scroll and loading/error states (#8088)
* add forwardRef to Layout.Content * lift scrollview up out of inner component * fix scrolling on android (#8188)
1 parent 238b00d commit f8bd850

File tree

3 files changed

+184
-182
lines changed

3 files changed

+184
-182
lines changed

src/components/Layout/index.tsx

Lines changed: 57 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import React, {useContext, useMemo} from 'react'
2-
import {StyleSheet, View, ViewProps, ViewStyle} from 'react-native'
3-
import {StyleProp} from 'react-native'
1+
import {forwardRef, memo, useContext, useMemo} from 'react'
2+
import {StyleSheet, View, type ViewProps, type ViewStyle} from 'react-native'
3+
import {type StyleProp} from 'react-native'
44
import {
55
KeyboardAwareScrollView,
6-
KeyboardAwareScrollViewProps,
6+
type KeyboardAwareScrollViewProps,
77
} from 'react-native-keyboard-controller'
88
import Animated, {
9-
AnimatedScrollViewProps,
9+
type AnimatedScrollViewProps,
1010
useAnimatedProps,
1111
} from 'react-native-reanimated'
1212
import {useSafeAreaInsets} from 'react-native-safe-area-context'
@@ -35,7 +35,7 @@ export type ScreenProps = React.ComponentProps<typeof View> & {
3535
/**
3636
* Outermost component of every screen
3737
*/
38-
export const Screen = React.memo(function Screen({
38+
export const Screen = memo(function Screen({
3939
style,
4040
noInsetTop,
4141
...props
@@ -61,49 +61,55 @@ export type ContentProps = AnimatedScrollViewProps & {
6161
/**
6262
* Default scroll view for simple pages
6363
*/
64-
export const Content = React.memo(function Content({
65-
children,
66-
style,
67-
contentContainerStyle,
68-
ignoreTabletLayoutOffset,
69-
...props
70-
}: ContentProps) {
71-
const t = useTheme()
72-
const {footerHeight} = useShellLayout()
73-
const animatedProps = useAnimatedProps(() => {
74-
return {
75-
scrollIndicatorInsets: {
76-
bottom: footerHeight.get(),
77-
top: 0,
78-
right: 1,
79-
},
80-
} satisfies AnimatedScrollViewProps
81-
})
64+
export const Content = memo(
65+
forwardRef<Animated.ScrollView, ContentProps>(function Content(
66+
{
67+
children,
68+
style,
69+
contentContainerStyle,
70+
ignoreTabletLayoutOffset,
71+
...props
72+
},
73+
ref,
74+
) {
75+
const t = useTheme()
76+
const {footerHeight} = useShellLayout()
77+
const animatedProps = useAnimatedProps(() => {
78+
return {
79+
scrollIndicatorInsets: {
80+
bottom: footerHeight.get(),
81+
top: 0,
82+
right: 1,
83+
},
84+
} satisfies AnimatedScrollViewProps
85+
})
8286

83-
return (
84-
<Animated.ScrollView
85-
id="content"
86-
automaticallyAdjustsScrollIndicatorInsets={false}
87-
indicatorStyle={t.scheme === 'dark' ? 'white' : 'black'}
88-
// sets the scroll inset to the height of the footer
89-
animatedProps={animatedProps}
90-
style={[scrollViewStyles.common, style]}
91-
contentContainerStyle={[
92-
scrollViewStyles.contentContainer,
93-
contentContainerStyle,
94-
]}
95-
{...props}>
96-
{isWeb ? (
97-
<Center ignoreTabletLayoutOffset={ignoreTabletLayoutOffset}>
98-
{/* @ts-expect-error web only -esb */}
99-
{children}
100-
</Center>
101-
) : (
102-
children
103-
)}
104-
</Animated.ScrollView>
105-
)
106-
})
87+
return (
88+
<Animated.ScrollView
89+
ref={ref}
90+
id="content"
91+
automaticallyAdjustsScrollIndicatorInsets={false}
92+
indicatorStyle={t.scheme === 'dark' ? 'white' : 'black'}
93+
// sets the scroll inset to the height of the footer
94+
animatedProps={animatedProps}
95+
style={[scrollViewStyles.common, style]}
96+
contentContainerStyle={[
97+
scrollViewStyles.contentContainer,
98+
contentContainerStyle,
99+
]}
100+
{...props}>
101+
{isWeb ? (
102+
<Center ignoreTabletLayoutOffset={ignoreTabletLayoutOffset}>
103+
{/* @ts-expect-error web only -esb */}
104+
{children}
105+
</Center>
106+
) : (
107+
children
108+
)}
109+
</Animated.ScrollView>
110+
)
111+
}),
112+
)
107113

108114
const scrollViewStyles = StyleSheet.create({
109115
common: {
@@ -124,7 +130,7 @@ export type KeyboardAwareContentProps = KeyboardAwareScrollViewProps & {
124130
*
125131
* BE SURE TO TEST THIS WHEN USING, it's untested as of writing this comment.
126132
*/
127-
export const KeyboardAwareContent = React.memo(function LayoutScrollView({
133+
export const KeyboardAwareContent = memo(function LayoutKeyboardAwareContent({
128134
children,
129135
style,
130136
contentContainerStyle,
@@ -147,7 +153,7 @@ export const KeyboardAwareContent = React.memo(function LayoutScrollView({
147153
/**
148154
* Utility component to center content within the screen
149155
*/
150-
export const Center = React.memo(function LayoutContent({
156+
export const Center = memo(function LayoutCenter({
151157
children,
152158
style,
153159
ignoreTabletLayoutOffset,
@@ -192,7 +198,7 @@ export const Center = React.memo(function LayoutContent({
192198
/**
193199
* Only used within `Layout.Screen`, not for reuse
194200
*/
195-
const WebCenterBorders = React.memo(function LayoutContent() {
201+
const WebCenterBorders = memo(function LayoutWebCenterBorders() {
196202
const t = useTheme()
197203
const {gtMobile} = useBreakpoints()
198204
const {centerColumnOffset} = useLayoutBreakpoints()

src/screens/Profile/Sections/Feed.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ import {useQueryClient} from '@tanstack/react-query'
77
import {useInitialNumToRender} from '#/lib/hooks/useInitialNumToRender'
88
import {usePalette} from '#/lib/hooks/usePalette'
99
import {isNative} from '#/platform/detection'
10-
import {FeedDescriptor} from '#/state/queries/post-feed'
10+
import {type FeedDescriptor} from '#/state/queries/post-feed'
1111
import {RQKEY as FEED_RQKEY} from '#/state/queries/post-feed'
1212
import {truncateAndInvalidate} from '#/state/queries/util'
1313
import {PostFeed} from '#/view/com/posts/PostFeed'
1414
import {EmptyState} from '#/view/com/util/EmptyState'
15-
import {ListRef} from '#/view/com/util/List'
15+
import {type ListRef} from '#/view/com/util/List'
1616
import {LoadLatestBtn} from '#/view/com/util/load-latest/LoadLatestBtn'
1717
import {Text} from '#/view/com/util/text/Text'
1818
import {ios} from '#/alf'
19-
import {SectionRef} from './types'
19+
import {type SectionRef} from './types'
2020

2121
interface FeedSectionProps {
2222
feed: FeedDescriptor
@@ -58,6 +58,7 @@ export const ProfileFeedSection = React.forwardRef<
5858
truncateAndInvalidate(queryClient, FEED_RQKEY(feed))
5959
setHasNew(false)
6060
}, [scrollElRef, headerHeight, queryClient, feed, setHasNew])
61+
6162
React.useImperativeHandle(ref, () => ({
6263
scrollToTop: onScrollToTop,
6364
}))

0 commit comments

Comments
 (0)