Add share bottom-sheet to feed and thread

This commit is contained in:
Paul Frazee
2022-07-25 18:31:42 -05:00
parent 3794eca88e
commit af55a89758
14 changed files with 574 additions and 34 deletions
+13 -2
View File
@@ -1,9 +1,10 @@
import React from 'react'
import React, {useRef} from 'react'
import {observer} from 'mobx-react-lite'
import {Text, View, FlatList} from 'react-native'
import {OnNavigateContent} from '../../routes/types'
import {FeedViewModel, FeedViewItemModel} from '../../../state/models/feed-view'
import {FeedItem} from './FeedItem'
import {ShareBottomSheet} from '../sheets/SharePost'
export const Feed = observer(function Feed({
feed,
@@ -12,12 +13,21 @@ export const Feed = observer(function Feed({
feed: FeedViewModel
onNavigateContent: OnNavigateContent
}) {
const shareSheetRef = useRef<{open: (uri: string) => void}>()
const onPressShare = (uri: string) => {
shareSheetRef.current?.open(uri)
}
// TODO optimize renderItem or FeedItem, we're getting this notice from RN: -prf
// VirtualizedList: You have a large list that is slow to update - make sure your
// renderItem function renders components that follow React performance best practices
// like PureComponent, shouldComponentUpdate, etc
const renderItem = ({item}: {item: FeedViewItemModel}) => (
<FeedItem item={item} onNavigateContent={onNavigateContent} />
<FeedItem
item={item}
onNavigateContent={onNavigateContent}
onPressShare={onPressShare}
/>
)
const onRefresh = () => {
feed.refresh().catch(err => console.error('Failed to refresh', err))
@@ -42,6 +52,7 @@ export const Feed = observer(function Feed({
/>
)}
{feed.isEmpty && <Text>This feed is empty!</Text>}
<ShareBottomSheet ref={shareSheetRef} />
</View>
)
})
+6 -2
View File
@@ -12,9 +12,11 @@ import {AVIS} from '../../lib/assets'
export const FeedItem = observer(function FeedItem({
item,
onNavigateContent,
onPressShare,
}: {
item: FeedViewItemModel
onNavigateContent: OnNavigateContent
onPressShare: (uri: string) => void
}) {
const record = item.record as unknown as bsky.Post.Record
@@ -118,12 +120,14 @@ export const FeedItem = observer(function FeedItem({
{item.likeCount}
</Text>
</TouchableOpacity>
<View style={styles.ctrl}>
<TouchableOpacity
style={styles.ctrl}
onPress={() => onPressShare(item.uri)}>
<FontAwesomeIcon
style={styles.ctrlIcon}
icon="share-from-square"
/>
</View>
</TouchableOpacity>
</View>
</View>
</View>