Skip to content

Commit

Permalink
wire in feed context again...
Browse files Browse the repository at this point in the history
  • Loading branch information
haileyok committed Jan 19, 2025
1 parent d83a627 commit c8f276b
Showing 1 changed file with 37 additions and 4 deletions.
41 changes: 37 additions & 4 deletions src/screens/VideoFeed/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ type CurrentSource = {
moderation?: ModerationDecision
} | null

type VideoItem = {
moderation: ModerationDecision
post: AppBskyFeedDefs.PostView
feedContext: string | undefined
}

function Feed() {
const {params} = useRoute<RouteProp<CommonNavigatorParams, 'VideoFeed'>>()
const isFocused = useIsFocused()
Expand All @@ -186,7 +192,20 @@ function Feed() {
const videos = useMemo(() => {
let vids =
data?.pages
.flatMap(page => page.slices.flatMap(slice => slice.items))
.map(page => {
const items = []
for (const slice of page.slices) {
for (const i of slice.items) {
items.push({
moderation: i.moderation,
post: i.post,
feedContext: slice.feedContext,
})
}
}
return items
})
.flatMap(items => items)
.filter(item => AppBskyEmbedVideo.isView(item.post.embed)) || []
const startingVideoIndex = vids?.findIndex(video => {
return video.post.uri === params.initialPostUri
Expand All @@ -209,7 +228,7 @@ function Feed() {

const scrollGesture = useMemo(() => Gesture.Native(), [])

const renderItem: ListRenderItem<FeedPostSliceItem> = useCallback(
const renderItem: ListRenderItem<VideoItem> = useCallback(
({item, index}) => {
const {post} = item

Expand All @@ -233,6 +252,7 @@ function Feed() {
}
moderation={currentSource?.moderation}
scrollGesture={scrollGesture}
feedContext={item.feedContext}
/>
)
},
Expand Down Expand Up @@ -438,13 +458,15 @@ function VideoItem({
active,
scrollGesture,
moderation,
feedContext,
}: {
player?: VideoPlayer
post: AppBskyFeedDefs.PostView
embed: AppBskyEmbedVideo.View
active: boolean
scrollGesture: NativeGesture
moderation?: ModerationDecision
feedContext: string | undefined
}) {
const postShadow = usePostShadow(post)
const {width, height} = useSafeAreaFrame()
Expand All @@ -457,12 +479,13 @@ function VideoItem({
sendInteraction({
item: post.uri,
event: 'app.bsky.feed.defs#interactionSeen',
feedContext,
})
}, 1000)
} else if (!active && to) {
clearTimeout(to)
}
}, [active, post, sendInteraction])
}, [active, post, feedContext, sendInteraction])

return (
<View style={[a.relative, {height, width}]}>
Expand Down Expand Up @@ -502,6 +525,7 @@ function VideoItem({
active={active}
scrollGesture={scrollGesture}
moderation={moderation}
feedContext={feedContext}
/>
)}
</>
Expand Down Expand Up @@ -641,13 +665,15 @@ function Overlay({
active,
scrollGesture,
moderation,
feedContext,
}: {
player?: VideoPlayer
post: Shadow<AppBskyFeedDefs.PostView>
embed: AppBskyEmbedVideo.View
active: boolean
scrollGesture: NativeGesture
moderation: ModerationDecision
feedContext: string | undefined
}) {
const {_} = useLingui()
const t = useTheme()
Expand Down Expand Up @@ -683,7 +709,11 @@ function Overlay({
<Hider.Content>
<View style={[a.absolute, a.inset_0, a.z_20]}>
<View style={[a.flex_1]}>
<PlayPauseTapArea player={player} post={post} />
<PlayPauseTapArea
player={player}
post={post}
feedContext={feedContext}
/>
</View>

<LinearGradient
Expand Down Expand Up @@ -898,9 +928,11 @@ function VideoItemPlaceholder({
function PlayPauseTapArea({
player,
post,
feedContext,
}: {
player?: VideoPlayer
post: Shadow<AppBskyFeedDefs.PostView>
feedContext: string | undefined
}) {
const doubleTapRef = useRef<ReturnType<typeof setTimeout> | null>(null)
const playHaptic = useHaptics()
Expand All @@ -927,6 +959,7 @@ function PlayPauseTapArea({
sendInteraction({
item: post.uri,
event: 'app.bsky.feed.defs#interactionLike',
feedContext,
})
} else {
doubleTapRef.current = setTimeout(togglePlayPause, 200)
Expand Down

0 comments on commit c8f276b

Please sign in to comment.