refactor(mobile): intial addin of dockdoor scanning on mobile
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import axios from "axios";
|
||||
import Constants from "expo-constants";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { setApiConfig } from "../lib/apiHelper";
|
||||
import { devDelay } from "../lib/devMode";
|
||||
import { versionCheck } from "../lib/versionValidation";
|
||||
import { useAppStore } from "./useAppStore";
|
||||
@@ -26,6 +27,11 @@ export function useAppStartup() {
|
||||
const serverPort = useAppStore((s) => s.serverPort);
|
||||
const serverIp = useAppStore((s) => s.serverIp);
|
||||
|
||||
setApiConfig({
|
||||
serverIp,
|
||||
serverPort,
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (!hasHydrated) {
|
||||
setStatus("loading");
|
||||
|
||||
32
lstMobile/src/hooks/useDeviceOrientationLock.ts
Normal file
32
lstMobile/src/hooks/useDeviceOrientationLock.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import * as Device from "expo-device";
|
||||
import * as ScreenOrientation from "expo-screen-orientation";
|
||||
import { useEffect } from "react";
|
||||
|
||||
const LANDSCAPE_MODELS = ["ET45", "ET40"]; // tablets
|
||||
const PORTRAIT_MODELS = ["TC21", "TC26", "TC8300"]; // scanners
|
||||
|
||||
const isTabletModel = (modelName?: string | null) => {
|
||||
const model = modelName?.toUpperCase() ?? "";
|
||||
|
||||
return LANDSCAPE_MODELS.some((m) => model.includes(m));
|
||||
};
|
||||
|
||||
export function useDeviceOrientationLock() {
|
||||
useEffect(() => {
|
||||
async function lockOrientation() {
|
||||
try {
|
||||
const model = Device.modelName;
|
||||
|
||||
await ScreenOrientation.lockAsync(
|
||||
isTabletModel(model)
|
||||
? ScreenOrientation.OrientationLock.LANDSCAPE
|
||||
: ScreenOrientation.OrientationLock.PORTRAIT_UP,
|
||||
);
|
||||
} catch (err) {
|
||||
console.warn("Failed to lock orientation", err);
|
||||
}
|
||||
}
|
||||
|
||||
void lockOrientation();
|
||||
}, []);
|
||||
}
|
||||
Reference in New Issue
Block a user