fix(mobile): keep loading skeletons below headers #66
@@ -1,4 +1,4 @@
|
||||
import { useEffect, useRef } from "react"
|
||||
import { useEffect, useRef, type ReactNode } from "react"
|
||||
import {
|
||||
Animated,
|
||||
ScrollView,
|
||||
@@ -18,6 +18,30 @@ import {
|
||||
useTwoColumnCardWidth,
|
||||
} from "@/lib/theme"
|
||||
|
||||
/** Match the inset-adjusted lists used once screen data is available. */
|
||||
function SkeletonContent({
|
||||
children,
|
||||
embedded = false,
|
||||
}: {
|
||||
children: ReactNode
|
||||
embedded?: boolean
|
||||
}) {
|
||||
const colors = useThemeColors()
|
||||
if (embedded) return <>{children}</>
|
||||
|
||||
return (
|
||||
<ScrollView
|
||||
style={{ flex: 1, backgroundColor: colors.background }}
|
||||
contentContainerStyle={{ paddingBottom: contentBottomInset }}
|
||||
contentInsetAdjustmentBehavior="automatic"
|
||||
scrollEnabled={false}
|
||||
accessibilityLabel="Loading"
|
||||
>
|
||||
{children}
|
||||
</ScrollView>
|
||||
)
|
||||
}
|
||||
|
||||
export function Skeleton({ style }: { style?: StyleProp<ViewStyle> }) {
|
||||
const colors = useThemeColors()
|
||||
const opacity = useRef(new Animated.Value(1)).current
|
||||
@@ -74,13 +98,21 @@ export function SongRowSkeleton() {
|
||||
)
|
||||
}
|
||||
|
||||
export function SongListSkeleton({ rows = 10 }: { rows?: number }) {
|
||||
export function SongListSkeleton({
|
||||
rows = 10,
|
||||
embedded = false,
|
||||
}: {
|
||||
rows?: number
|
||||
embedded?: boolean
|
||||
}) {
|
||||
return (
|
||||
<View accessibilityLabel="Loading" accessibilityRole="progressbar">
|
||||
{Array.from({ length: rows }, (_, index) => (
|
||||
<SongRowSkeleton key={index} />
|
||||
))}
|
||||
</View>
|
||||
<SkeletonContent embedded={embedded}>
|
||||
<View accessibilityLabel="Loading" accessibilityRole="progressbar">
|
||||
{Array.from({ length: rows }, (_, index) => (
|
||||
<SongRowSkeleton key={index} />
|
||||
))}
|
||||
</View>
|
||||
</SkeletonContent>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -109,24 +141,28 @@ function CardSkeleton({
|
||||
export function MediaGridSkeleton({
|
||||
items = 6,
|
||||
contentInset = true,
|
||||
embedded = false,
|
||||
}: {
|
||||
items?: number
|
||||
contentInset?: boolean
|
||||
embedded?: boolean
|
||||
}) {
|
||||
const cardWidth = useTwoColumnCardWidth()
|
||||
return (
|
||||
<View
|
||||
accessibilityLabel="Loading"
|
||||
accessibilityRole="progressbar"
|
||||
style={[
|
||||
styles.grid,
|
||||
contentInset ? styles.gridInset : styles.gridRowInset,
|
||||
]}
|
||||
>
|
||||
{Array.from({ length: items }, (_, index) => (
|
||||
<CardSkeleton key={index} width={cardWidth} />
|
||||
))}
|
||||
</View>
|
||||
<SkeletonContent embedded={embedded}>
|
||||
<View
|
||||
accessibilityLabel="Loading"
|
||||
accessibilityRole="progressbar"
|
||||
style={[
|
||||
styles.grid,
|
||||
contentInset ? styles.gridInset : styles.gridRowInset,
|
||||
]}
|
||||
>
|
||||
{Array.from({ length: items }, (_, index) => (
|
||||
<CardSkeleton key={index} width={cardWidth} />
|
||||
))}
|
||||
</View>
|
||||
</SkeletonContent>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -192,9 +228,9 @@ export function CollectionDetailSkeleton({
|
||||
</View>
|
||||
</View>
|
||||
{round ? (
|
||||
<MediaGridSkeleton items={4} contentInset={false} />
|
||||
<MediaGridSkeleton items={4} contentInset={false} embedded />
|
||||
) : (
|
||||
<SongListSkeleton rows={8} />
|
||||
<SongListSkeleton rows={8} embedded />
|
||||
)}
|
||||
</ScrollView>
|
||||
)
|
||||
@@ -203,17 +239,19 @@ export function CollectionDetailSkeleton({
|
||||
export function ArtistListSkeleton({ rows = 12 }: { rows?: number }) {
|
||||
const colors = useThemeColors()
|
||||
return (
|
||||
<View accessibilityLabel="Loading" accessibilityRole="progressbar">
|
||||
{Array.from({ length: rows }, (_, index) => (
|
||||
<View
|
||||
key={index}
|
||||
style={[styles.artistRow, { borderBottomColor: colors.border }]}
|
||||
>
|
||||
<Skeleton style={styles.artistAvatar} />
|
||||
<TextLine width="50%" height={16} />
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
<SkeletonContent>
|
||||
<View accessibilityLabel="Loading" accessibilityRole="progressbar">
|
||||
{Array.from({ length: rows }, (_, index) => (
|
||||
<View
|
||||
key={index}
|
||||
style={[styles.artistRow, { borderBottomColor: colors.border }]}
|
||||
>
|
||||
<Skeleton style={styles.artistAvatar} />
|
||||
<TextLine width="50%" height={16} />
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
</SkeletonContent>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -233,7 +271,7 @@ const styles = StyleSheet.create({
|
||||
grid: { flexDirection: "row", flexWrap: "wrap", gap: spacing.md },
|
||||
gridInset: { padding: spacing.lg },
|
||||
gridRowInset: { paddingHorizontal: spacing.lg },
|
||||
carousel: { gap: spacing.md },
|
||||
carousel: { gap: spacing.md, overflow: "hidden" },
|
||||
carouselRow: { flexDirection: "row", gap: spacing.md },
|
||||
home: { padding: spacing.lg, gap: spacing.xl },
|
||||
hero: { alignItems: "center", padding: spacing.lg, gap: spacing.sm },
|
||||
|
||||
Reference in new issue
Block a user