react-native-sortables
Version:
Powerful Sortable Components for Flexible Content Reordering in React Native
22 lines (17 loc) • 594 B
text/typescript
'worklet';
import type { Dimensions, ItemSizes } from '../types';
export const resolveDimension = (dimension: ItemSizes, key: string) =>
dimension &&
(typeof dimension === 'number' ? dimension : (dimension[key] ?? null));
export const getItemDimensions = (
key: string,
itemWidths: ItemSizes,
itemHeights: ItemSizes
): Dimensions | null => {
const itemWidth = resolveDimension(itemWidths, key);
const itemHeight = resolveDimension(itemHeights, key);
if (itemWidth === null || itemHeight === null) {
return null;
}
return { height: itemHeight, width: itemWidth };
};