Fix grid layout trailing single item

This commit is contained in:
Eric Bailey
2025-01-17 12:46:08 -06:00
parent 378224a056
commit 2f3ac892c5
2 changed files with 71 additions and 9 deletions
+59
View File
@@ -0,0 +1,59 @@
import {createContext, useContext,useMemo} from 'react'
import {View} from 'react-native'
import {atoms as a, ViewStyleProp} from '#/alf'
const Context = createContext({
gap: 0,
})
export function Row({
children,
gap = 0,
style,
}: ViewStyleProp & {
children: React.ReactNode
gap?: number
}) {
return (
<Context.Provider value={useMemo(() => ({gap}), [gap])}>
<View
style={[
a.flex_row,
a.flex_1,
{
marginLeft: -gap / 2,
marginRight: -gap / 2,
},
style,
]}>
{children}
</View>
</Context.Provider>
)
}
export function Col({
children,
width = 1,
style,
}: ViewStyleProp & {
children: React.ReactNode
width?: number
}) {
const {gap} = useContext(Context)
return (
<View
style={[
a.flex_col,
{
paddingLeft: gap / 2,
paddingRight: gap / 2,
width: `${width * 100}%`,
},
style,
]}>
{children}
</View>
)
}
+12 -9
View File
@@ -4,6 +4,7 @@ import {AppBskyEmbedVideo} from '@atproto/api'
import {FeedPostSliceItem} from '#/state/queries/post-feed'
import {VideoFeedSourceContext} from '#/screens/VideoFeed/types'
import {atoms as a, useGutters} from '#/alf'
import * as Grid from '#/components/Grid'
import {
VideoPostCard,
VideoPostCardPlaceholder,
@@ -33,15 +34,17 @@ export function PostFeedVideoGridRow({
return (
<View style={[gutters]}>
<View style={[a.flex_row, a.gap_sm]}>
{posts.map(post => (
<View key={post.post.uri} style={[a.flex_1]}>
<VideoPostCard
post={post.post}
sourceContext={sourceContext}
moderation={post.moderation}
/>
</View>
))}
<Grid.Row gap={a.gap_sm.gap}>
{posts.map(post => (
<Grid.Col key={post.post.uri} width={1 / 2}>
<VideoPostCard
post={post.post}
sourceContext={sourceContext}
moderation={post.moderation}
/>
</Grid.Col>
))}
</Grid.Row>
</View>
</View>
)