2024-04-19 00:35:50 +02:00
|
|
|
import { useState, useEffect, useMemo } from 'react';
|
|
|
|
import { Dimensions } from 'react-native';
|
|
|
|
import { isTablet } from 'react-native-device-info';
|
2024-04-24 00:53:14 +02:00
|
|
|
import { isDesktop } from '../blue_modules/environment';
|
2024-04-19 00:31:06 +02:00
|
|
|
|
|
|
|
// Custom hook to determine if the screen is large
|
|
|
|
export const useIsLargeScreen = () => {
|
|
|
|
const [windowWidth, setWindowWidth] = useState(Dimensions.get('window').width);
|
|
|
|
const screenWidth = useMemo(() => Dimensions.get('screen').width, []);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const updateScreenUsage = () => {
|
|
|
|
const newWindowWidth = Dimensions.get('window').width;
|
|
|
|
if (newWindowWidth !== windowWidth) {
|
2024-04-27 03:13:45 +02:00
|
|
|
console.debug(`Window width changed: ${newWindowWidth}`);
|
2024-04-19 00:31:06 +02:00
|
|
|
setWindowWidth(newWindowWidth);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Add event listener for dimension changes
|
|
|
|
const subscription = Dimensions.addEventListener('change', updateScreenUsage);
|
|
|
|
|
|
|
|
// Cleanup function to remove the event listener
|
|
|
|
return () => {
|
|
|
|
subscription.remove();
|
|
|
|
};
|
|
|
|
}, [windowWidth]);
|
|
|
|
|
|
|
|
// Determine if the window width is at least half of the screen width
|
|
|
|
const isLargeScreen = useMemo(() => {
|
2024-05-03 18:49:40 +02:00
|
|
|
const isRunningOnTablet = isTablet();
|
2024-04-19 00:31:06 +02:00
|
|
|
const halfScreenWidth = windowWidth >= screenWidth / 2;
|
2024-05-03 18:49:40 +02:00
|
|
|
const condition = (isRunningOnTablet && halfScreenWidth) || isDesktop;
|
2024-04-27 03:13:45 +02:00
|
|
|
console.debug(
|
2024-05-05 19:57:41 +02:00
|
|
|
`Window width: ${windowWidth}, Screen width: ${screenWidth}, Is tablet: ${isTablet()}, Is large screen: ${condition}, isDesktkop: ${isDesktop}`,
|
2024-04-19 00:31:06 +02:00
|
|
|
);
|
|
|
|
return condition;
|
|
|
|
}, [windowWidth, screenWidth]);
|
|
|
|
|
|
|
|
return isLargeScreen;
|
|
|
|
};
|