@kolking/react-native-parallax-swiper
Version:
React Native component for building an impressive horizontal swiper with a parallax effect.
13 lines (10 loc) • 454 B
text/typescript
import { Image, ImageSourcePropType, useWindowDimensions } from 'react-native';
export const useImageDimensions = (source: ImageSourcePropType) => {
const window = useWindowDimensions();
// TODO: check for external image source
const asset = Image.resolveAssetSource(source);
const ratio = asset.width / asset.height;
const width = Math.max(window.width, window.height * ratio);
const height = width / ratio;
return { width, height };
};