fix: cls issues

content layout shift
This commit is contained in:
Fredrik Burmester
2024-08-15 10:38:17 +02:00
parent f91a37ddc2
commit a8fef13aa8
2 changed files with 40 additions and 11 deletions

View File

@@ -2,6 +2,7 @@ import React from "react";
import { View } from "react-native"; import { View } from "react-native";
import { Text } from "./common/Text"; import { Text } from "./common/Text";
import { BaseItemDto } from "@jellyfin/sdk/lib/generated-client/models"; import { BaseItemDto } from "@jellyfin/sdk/lib/generated-client/models";
import { tc } from "@/utils/textTools";
type ItemCardProps = { type ItemCardProps = {
item: BaseItemDto; item: BaseItemDto;
@@ -20,14 +21,13 @@ function seasonNameToIndex(seasonName: string | null | undefined) {
export const ItemCardText: React.FC<ItemCardProps> = ({ item }) => { export const ItemCardText: React.FC<ItemCardProps> = ({ item }) => {
return ( return (
<View className="mt-2 flex flex-col grow-0"> <View className="mt-2 flex flex-col h-12">
{item.Type === "Episode" ? ( {item.Type === "Episode" ? (
<> <>
<Text className="">{item.SeriesName}</Text> <Text numberOfLines={2} className="">
<Text {item.SeriesName}
style={{ flexWrap: "wrap" }} </Text>
className="flex text-xs opacity-50 break-all" <Text numberOfLines={1} className="text-xs opacity-50">
>
{`S${seasonNameToIndex( {`S${seasonNameToIndex(
item?.SeasonName, item?.SeasonName,
)}:E${item.IndexNumber?.toString()}`}{" "} )}:E${item.IndexNumber?.toString()}`}{" "}

View File

@@ -1,4 +1,4 @@
import React from "react"; import React, { useEffect } from "react";
import { import {
ScrollView, ScrollView,
View, View,
@@ -6,6 +6,11 @@ import {
ActivityIndicator, ActivityIndicator,
ScrollViewProps, ScrollViewProps,
} from "react-native"; } from "react-native";
import Animated, {
useAnimatedStyle,
useSharedValue,
withTiming,
} from "react-native-reanimated";
interface HorizontalScrollProps<T> extends ScrollViewProps { interface HorizontalScrollProps<T> extends ScrollViewProps {
data?: T[] | null; data?: T[] | null;
@@ -13,6 +18,7 @@ interface HorizontalScrollProps<T> extends ScrollViewProps {
containerStyle?: ViewStyle; containerStyle?: ViewStyle;
contentContainerStyle?: ViewStyle; contentContainerStyle?: ViewStyle;
loadingContainerStyle?: ViewStyle; loadingContainerStyle?: ViewStyle;
height?: number;
} }
export function HorizontalScroll<T>({ export function HorizontalScroll<T>({
@@ -21,13 +27,19 @@ export function HorizontalScroll<T>({
containerStyle, containerStyle,
contentContainerStyle, contentContainerStyle,
loadingContainerStyle, loadingContainerStyle,
height = 164,
...props ...props
}: HorizontalScrollProps<T>): React.ReactElement { }: HorizontalScrollProps<T>): React.ReactElement {
if (!data) { if (!data) {
return ( return (
<View <View
style={[ style={[
{ flex: 1, justifyContent: "center", alignItems: "center" }, {
flex: 1,
justifyContent: "center",
alignItems: "center",
height,
},
loadingContainerStyle, loadingContainerStyle,
]} ]}
> >
@@ -36,6 +48,18 @@ export function HorizontalScroll<T>({
); );
} }
const opacity = useSharedValue(0);
const animatedStyle = useAnimatedStyle(() => {
return {
opacity: withTiming(opacity.value, { duration: 250 }),
};
});
useEffect(() => {
if (data && data.length > 0) opacity.value = 1;
}, [data]);
return ( return (
<ScrollView <ScrollView
horizontal horizontal
@@ -44,13 +68,18 @@ export function HorizontalScroll<T>({
showsHorizontalScrollIndicator={false} showsHorizontalScrollIndicator={false}
{...props} {...props}
> >
<View className="flex flex-row px-4"> <Animated.View
{data.map((item, index) => ( className={`
flex flex-row px-4
`}
style={[animatedStyle]}
>
{data?.map((item, index) => (
<View className="mr-2" key={index}> <View className="mr-2" key={index}>
<React.Fragment>{renderItem(item, index)}</React.Fragment> <React.Fragment>{renderItem(item, index)}</React.Fragment>
</View> </View>
))} ))}
</View> </Animated.View>
</ScrollView> </ScrollView>
); );
} }