Skip to content

Commit 56f15f7

Browse files
Tim Girouxmarkharding
authored andcommitted
#80 Thread Topbar Bug and Related Improvements
Changelog: fix
1 parent 96696b3 commit 56f15f7

2 files changed

Lines changed: 18 additions & 6 deletions

File tree

apps/polycentric/src/features/post/ThreadList.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useCallback, useState } from 'react';
1+
import { useCallback, useMemo, useState } from 'react';
22
import { RefreshControl, useWindowDimensions, View } from 'react-native';
33
import { type PostData } from '@/src/common/lib/polycentric-hooks';
44
import { Post } from './Post';
@@ -17,8 +17,18 @@ export function ThreadList({ post, ...rest }: ThreadListProps) {
1717

1818
const { thread } = useThread(post);
1919

20-
// Fall back to rendering just the subject until the server response lands.
21-
const items = thread.length > 0 ? thread : [post];
20+
// Mount the subject by itself first.
21+
// Other items may or may not be available.
22+
// This is a reliable way to keep the subject at its intended scroll
23+
// position via FlashList maintainVisibleContentPosition.
24+
// Before this, we had issues with FlashList behaving differently with
25+
// cold vs warm caches at the call site.
26+
const [isFirstLayoutComplete, setIsFirstLayoutComplete] = useState(false);
27+
28+
const items = useMemo(() => {
29+
if (!isFirstLayoutComplete) return [post];
30+
return thread.length > 0 ? thread : [post];
31+
}, [isFirstLayoutComplete, thread, post]);
2232

2333
const subjectIndex = items.findIndex((p) => p.id === post.id);
2434

@@ -32,6 +42,7 @@ export function ThreadList({ post, ...rest }: ThreadListProps) {
3242
{...rest}
3343
data={items}
3444
initialScrollIndex={subjectIndex > 0 ? subjectIndex : undefined}
45+
onLoad={() => setIsFirstLayoutComplete(true)}
3546
keyExtractor={(p) => p.id}
3647
renderItem={({ item, index }) => {
3748
const above = index > 0 ? items[index - 1] : null;

apps/polycentric/src/features/profile/ProfileHeader.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
truncateName,
1111
useUsername,
1212
} from '@/src/common/lib/polycentric-hooks';
13-
import { Atoms } from '@/src/common/theme';
13+
import { Atoms, useTheme } from '@/src/common/theme';
1414
import { useProfile } from '@/src/features/profile/hooks/useProfile';
1515
import { FetchMode } from '@polycentric/react-native';
1616
import { router } from 'expo-router';
@@ -27,6 +27,7 @@ export interface ProfileHeaderProps {
2727
}
2828

2929
function ProfileHeaderInner({ bannerColors, onBack }: ProfileHeaderProps) {
30+
const { theme } = useTheme();
3031
const { identityKey, isSelf, activeFeed, setActiveFeed } =
3132
useProfileContext();
3233

@@ -44,7 +45,7 @@ function ProfileHeaderInner({ bannerColors, onBack }: ProfileHeaderProps) {
4445
if (profile.isLoading && !profile.name) return undefined;
4546

4647
return (
47-
<>
48+
<View style={{ backgroundColor: theme.palette.neutral_0 }}>
4849
<View style={{ position: 'relative' }}>
4950
<View
5051
style={{
@@ -122,7 +123,7 @@ function ProfileHeaderInner({ bannerColors, onBack }: ProfileHeaderProps) {
122123
)}
123124
</View>
124125
</View>
125-
</>
126+
</View>
126127
);
127128
}
128129

0 commit comments

Comments
 (0)