managarten/memoro/apps/mobile/hooks/useResponsive.ts
Till-JS e7f5f942f3 chore: initial commit - consolidate 4 projects into monorepo
Projects included:
- maerchenzauber (NestJS backend + Expo mobile + SvelteKit web + Astro landing)
- manacore (Expo mobile + SvelteKit web + Astro landing)
- manadeck (NestJS backend + Expo mobile + SvelteKit web)
- memoro (Expo mobile + SvelteKit web + Astro landing)

This commit preserves the current state before monorepo restructuring.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-22 23:38:24 +01:00

42 lines
No EOL
1.2 KiB
TypeScript

import { useState, useEffect } from 'react';
import { Dimensions, Platform } from 'react-native';
const BREAKPOINTS = {
mobile: 640,
tablet: 768,
desktop: 1024,
wide: 1440,
} as const;
export function useResponsive() {
const [dimensions, setDimensions] = useState(() => {
const { width, height } = Dimensions.get('window');
return { width, height };
});
useEffect(() => {
if (Platform.OS !== 'web') return;
const updateDimensions = () => {
const { width, height } = Dimensions.get('window');
setDimensions({ width, height });
};
const subscription = Dimensions.addEventListener('change', updateDimensions);
return () => subscription?.remove();
}, []);
const { width } = dimensions;
return {
width,
height: dimensions.height,
isMobile: width < BREAKPOINTS.tablet,
isTablet: width >= BREAKPOINTS.tablet && width < BREAKPOINTS.desktop,
isDesktop: width >= BREAKPOINTS.desktop,
isWide: width >= BREAKPOINTS.wide,
breakpoint: width < BREAKPOINTS.tablet ? 'mobile' :
width < BREAKPOINTS.desktop ? 'tablet' :
width < BREAKPOINTS.wide ? 'desktop' : 'wide'
};
}