画面回転を固定するように組み込み

This commit is contained in:
harukin-expo-dev-env 2024-03-09 13:48:53 +00:00
parent e1e35168d6
commit 48e1ab7b26
4 changed files with 26 additions and 4 deletions

View File

@ -22,7 +22,13 @@
] ]
} }
], ],
"expo-font" "expo-font",
[
"expo-screen-orientation",
{
"initialOrientation": "DEFAULT"
}
]
], ],
"version": "5.0", "version": "5.0",
"orientation": "default", "orientation": "default",
@ -38,7 +44,7 @@
}, },
"assetBundlePatterns": ["**/*"], "assetBundlePatterns": ["**/*"],
"ios": { "ios": {
"buildNumber": "31", "buildNumber": "32",
"supportsTablet": true, "supportsTablet": true,
"bundleIdentifier": "jrshikokuinfo.xprocess.hrkn", "bundleIdentifier": "jrshikokuinfo.xprocess.hrkn",
"config": { "config": {
@ -57,7 +63,7 @@
}, },
"android": { "android": {
"package": "jrshikokuinfo.xprocess.hrkn", "package": "jrshikokuinfo.xprocess.hrkn",
"versionCode": 20, "versionCode": 21,
"permissions": ["ACCESS_FINE_LOCATION", "NFC"], "permissions": ["ACCESS_FINE_LOCATION", "NFC"],
"googleServicesFile": "./google-services.json", "googleServicesFile": "./google-services.json",
"config": { "config": {

View File

@ -22,6 +22,7 @@
"expo-font": "~11.10.3", "expo-font": "~11.10.3",
"expo-location": "~16.5.5", "expo-location": "~16.5.5",
"expo-notifications": "~0.27.6", "expo-notifications": "~0.27.6",
"expo-screen-orientation": "~6.4.1",
"expo-sharing": "~11.10.0", "expo-sharing": "~11.10.0",
"expo-updates": "~0.24.11", "expo-updates": "~0.24.11",
"expo-web-browser": "~12.8.2", "expo-web-browser": "~12.8.2",

View File

@ -1,5 +1,6 @@
import React, { createContext, useContext, useState, useEffect } from "react"; import React, { createContext, useContext, useState, useEffect } from "react";
import { useWindowDimensions } from "react-native"; import { useWindowDimensions } from "react-native";
import * as ScreenOrientation from "expo-screen-orientation";
const initialState = { isLandscape: false, setIsLandscape: () => {} }; const initialState = { isLandscape: false, setIsLandscape: () => {} };
const DeviceOrientationChange = createContext(initialState); const DeviceOrientationChange = createContext(initialState);
@ -11,13 +12,22 @@ export const useDeviceOrientationChange = () => {
export const DeviceOrientationChangeProvider = ({ children }) => { export const DeviceOrientationChangeProvider = ({ children }) => {
const [isLandscape, setIsLandscape] = useState(false); const [isLandscape, setIsLandscape] = useState(false);
const { height, width } = useWindowDimensions(); const { height, width } = useWindowDimensions();
const data = async () => {
await ScreenOrientation.lockAsync(
ScreenOrientation.OrientationLock.PORTRAIT_UP
);
};
useEffect(() => {
data();
//ScreenOrientation.unlockAsync();
}, []);
useEffect(() => { useEffect(() => {
if (height / width > 1.5) { if (height / width > 1.5) {
setIsLandscape(false); setIsLandscape(false);
} }
if (height / width < 1.5) { if (height / width < 1.5) {
setIsLandscape(true); //setIsLandscape(true);
} }
}, [height, width]); }, [height, width]);
return ( return (

View File

@ -5474,6 +5474,11 @@ expo-notifications@~0.27.6:
expo-constants "~15.4.0" expo-constants "~15.4.0"
fs-extra "^9.1.0" fs-extra "^9.1.0"
expo-screen-orientation@~6.4.1:
version "6.4.1"
resolved "https://registry.yarnpkg.com/expo-screen-orientation/-/expo-screen-orientation-6.4.1.tgz#1c4428a058921e48b5caa45367e626b8bec10e24"
integrity sha512-VM0C9ORNL1aT6Dr2OUeryzV519n0FjtXI2m+HlijOMi1QT2bPg4tBkCd7HLgywU4dZ1Esa46ewUudmk+fOqmMQ==
expo-sharing@~11.10.0: expo-sharing@~11.10.0:
version "11.10.0" version "11.10.0"
resolved "https://registry.yarnpkg.com/expo-sharing/-/expo-sharing-11.10.0.tgz#0e85197ee4d2634b00fe201e571fbdc64cf83eef" resolved "https://registry.yarnpkg.com/expo-sharing/-/expo-sharing-11.10.0.tgz#0e85197ee4d2634b00fe201e571fbdc64cf83eef"