mirror of
https://github.com/streamyfin/streamyfin.git
synced 2026-01-15 23:59:08 +00:00
35 lines
719 B
TypeScript
35 lines
719 B
TypeScript
import { StyleSheet, View, ViewProps } from "react-native";
|
|
|
|
const getItemStyle = (index: number, numColumns: number) => {
|
|
const alignItems = (() => {
|
|
if (numColumns < 2 || index % numColumns === 0) return "flex-start";
|
|
if ((index + 1) % numColumns === 0) return "flex-end";
|
|
|
|
return "center";
|
|
})();
|
|
|
|
return {
|
|
alignItems,
|
|
width: "100%",
|
|
} as const;
|
|
};
|
|
|
|
type ColumnItemProps = ViewProps & {
|
|
children: React.ReactNode;
|
|
index: number;
|
|
numColumns: number;
|
|
};
|
|
export const ColumnItem = ({
|
|
children,
|
|
index,
|
|
numColumns,
|
|
...rest
|
|
}: ColumnItemProps) => (
|
|
<View
|
|
style={StyleSheet.flatten([getItemStyle(index, numColumns), rest.style])}
|
|
{...rest}
|
|
>
|
|
{children}
|
|
</View>
|
|
);
|