Some checks failed
forgejo/Procyon/procyon/pipeline/head There was a failure building this commit
22 lines
608 B
TypeScript
22 lines
608 B
TypeScript
import { useEffect, useState } from 'react';
|
|
import { Dimensions } from 'react-native';
|
|
|
|
export function useScreenDimensions(): { height: number; width: number } {
|
|
const initialDimensions = Dimensions.get('screen');
|
|
const [width, setWidth] = useState(initialDimensions.width);
|
|
const [height, setHeight] = useState(initialDimensions.height);
|
|
|
|
const handleChange = ({ screen }) => {
|
|
setWidth(screen.width);
|
|
setHeight(screen.height);
|
|
};
|
|
|
|
useEffect(() => {
|
|
const sub = Dimensions.addEventListener('change', handleChange);
|
|
return () => {
|
|
sub.remove();
|
|
};
|
|
}, []);
|
|
|
|
return { width, height };
|
|
}
|