mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import React, {useCallback} from 'react'
2import {ListRenderItemInfo, View} from 'react-native'
3import {AppBskyFeedDefs} from '@atproto/api'
4import {GeneratorView} from '@atproto/api/dist/client/types/app/bsky/feed/defs'
5
6import {useBottomBarOffset} from '#/lib/hooks/useBottomBarOffset'
7import {isNative, isWeb} from '#/platform/detection'
8import {List, ListRef} from '#/view/com/util/List'
9import {SectionRef} from '#/screens/Profile/Sections/types'
10import {atoms as a, useTheme} from '#/alf'
11import * as FeedCard from '#/components/FeedCard'
12
13function keyExtractor(item: AppBskyFeedDefs.GeneratorView) {
14 return item.uri
15}
16
17interface ProfilesListProps {
18 feeds: AppBskyFeedDefs.GeneratorView[]
19 headerHeight: number
20 scrollElRef: ListRef
21}
22
23export const FeedsList = React.forwardRef<SectionRef, ProfilesListProps>(
24 function FeedsListImpl({feeds, headerHeight, scrollElRef}, ref) {
25 const [initialHeaderHeight] = React.useState(headerHeight)
26 const bottomBarOffset = useBottomBarOffset(20)
27 const t = useTheme()
28
29 const onScrollToTop = useCallback(() => {
30 scrollElRef.current?.scrollToOffset({
31 animated: isNative,
32 offset: -headerHeight,
33 })
34 }, [scrollElRef, headerHeight])
35
36 React.useImperativeHandle(ref, () => ({
37 scrollToTop: onScrollToTop,
38 }))
39
40 const renderItem = ({item, index}: ListRenderItemInfo<GeneratorView>) => {
41 return (
42 <View
43 style={[
44 a.p_lg,
45 (isWeb || index !== 0) && a.border_t,
46 t.atoms.border_contrast_low,
47 ]}>
48 <FeedCard.Default view={item} />
49 </View>
50 )
51 }
52
53 return (
54 <List
55 data={feeds}
56 renderItem={renderItem}
57 keyExtractor={keyExtractor}
58 ref={scrollElRef}
59 headerOffset={headerHeight}
60 ListFooterComponent={
61 <View style={[{height: initialHeaderHeight + bottomBarOffset}]} />
62 }
63 showsVerticalScrollIndicator={false}
64 desktopFixedHeight={true}
65 />
66 )
67 },
68)