Мы внесли все необходимые изменения в файл info.plist. Тем не менее мы не можем получить значения windowWidth и windowHeight. значение в зависимости от ориентации устройства. Значения windowWidth и windowHeight все время остаются неизменными.
Ниже приведен код, который мы пробовали...
Код: Выделить всё
const windowWidth = Dimensions.get("window").width;
const windowHeight = Dimensions.get("window").height;
const isIpad = windowWidth >= 768;
const [orientation, setOrientation] = useState(getInitialOrientation());
useEffect(() => {
const updateOrientation = () => {
const newOrientation = getOrientation();
if (newOrientation !== orientation) {
setOrientation(newOrientation);
}
};
Dimensions.addEventListener('change', updateOrientation);
return () => {
Dimensions.removeEventListener('change', updateOrientation);
};
}, [orientation]);
const getInitialOrientation = () => {
return windowWidth < windowHeight ? 'PORTRAIT' : windowWidth > 768 ? 'LANDSCAPE' : 'PORTRAIT'; // Adjust the width condition as per your requirement
}
const getOrientation = () => {
return windowWidth < windowHeight ? 'PORTRAIT' : windowWidth > 768 ? 'LANDSCAPE' : 'PORTRAIT'; // Adjust the width condition as per your requirement
}
Подробнее здесь: https://stackoverflow.com/questions/781 ... ot-working
Мобильная версия