Skip to content

Commit

Permalink
Prune build errors
Browse files Browse the repository at this point in the history
  • Loading branch information
chunlaw committed Jun 1, 2024
1 parent edc7f29 commit d939eb8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 19 deletions.
1 change: 0 additions & 1 deletion src/components/layout/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ const Header = () => {

const relocateGeolocation = useCallback(() => {
try {
// @ts-expect-error don't use geolocation navigator for Webview
if (window.iOSRNWebView === true) return;
navigator.geolocation.getCurrentPosition(
({ coords: { latitude, longitude } }) => {
Expand Down
2 changes: 0 additions & 2 deletions src/context/AppContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,6 @@ export const AppContextProvider = ({ children }: AppContextProviderProps) => {
const onVisibilityChange = () => {
if (geoPermission === "granted") {
try {
// @ts-expect-error don't use geolocation navigator for Webview
if (window.iOSRNWebView === true) return;
const _geoWatcherId = navigator.geolocation.watchPosition(
({ coords: { latitude, longitude } }) => {
Expand Down Expand Up @@ -347,7 +346,6 @@ export const AppContextProvider = ({ children }: AppContextProviderProps) => {
(geoPermission: AppState["geoPermission"], deniedCallback?: () => void) => {
if (geoPermission === "opening") {
setGeoPermission("opening");
// @ts-expect-error iOSRNWebView is defined in mobile app
if (window.iOSRNWebView !== true) {
geoWatcherId.current = navigator.geolocation.watchPosition(
({ coords: { latitude, longitude } }) => {
Expand Down
27 changes: 11 additions & 16 deletions src/context/ReactNativeContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ import { useTranslation } from "react-i18next";
import useLanguage from "../hooks/useTranslation";
import DbContext from "./DbContext";

declare global {
interface Window {
ReactNativeWebView?: any;
iOSRNWebView?: boolean;
}
}

interface ReactNativeContextState {
alarmStopId: string;
debug: boolean;
Expand Down Expand Up @@ -48,9 +55,7 @@ export const ReactNativeContextProvider = ({
}, []);

const os = useMemo<ReactNativeContextValue["os"]>(() => {
// @ts-expect-error iOSRNWebView is defined in the mobile app
if (window?.iOSRNWebView === true) return "ios";
// @ts-expect-error iOSRNWebView is defined in the mobile app
else if (window?.iOSRNWebView === false) return "android";
return null;
}, []);
Expand Down Expand Up @@ -108,7 +113,6 @@ export const ReactNativeContextProvider = ({
(stopId: string) => {
const stop = stopList[stopId];
if (!stop) return;
// @ts-expect-error ReactNativeWebView is defined in the mobile app
window.ReactNativeWebView?.postMessage(
JSON.stringify({
type: "stop-alarm",
Expand All @@ -126,22 +130,19 @@ export const ReactNativeContextProvider = ({

// Use mobile geolocation
useEffect(() => {
// @ts-expect-error ReactNativeWebView is defined in the mobile app
if (window.ReactNativeWebView !== undefined) {
// react native web view
if (
geoPermission === null ||
geoPermission === "opening" ||
geoPermission === "granted"
) {
// @ts-expect-error ReactNativeWebView is defined in the mobile app
window.ReactNativeWebView?.postMessage(
JSON.stringify({
type: "start-geolocation",
})
);
} else if (geoPermission === "closed") {
// @ts-expect-error ReactNativeWebView is defined in the mobile app
window.ReactNativeWebView?.postMessage(
JSON.stringify({
type: "stop-geolocation",
Expand All @@ -158,14 +159,12 @@ export const ReactNativeContextProvider = ({
// for iOS, override localStorage to use expo Async storage
useEffect(() => {
setTimeout(() => {
// @ts-expect-error ReactNativeWebView is in the mobile app
if (window.ReactNativeWebView && window?.iOSRNWebView === true) {
if (window.ReactNativeWebView && window.iOSRNWebView === true) {
// overwrite localstorage setItem
const { setItem, removeItem, clear } = localStorage;
localStorage.setItem = function (key: string, value: string) {
setItem.call(this, key, value);
// @ts-expect-error ReactNativeWebView is in the mobile app
window.ReactNativeWebView!.postMessage(
window.ReactNativeWebView.postMessage(
JSON.stringify({
type: "setItem",
value: {
Expand All @@ -177,8 +176,7 @@ export const ReactNativeContextProvider = ({
};
localStorage.removeItem = function (key: string) {
removeItem.call(this, key);
// @ts-expect-error ReactNativeWebView is in the mobile app
window.ReactNativeWebView!.postMessage(
window.ReactNativeWebView.postMessage(
JSON.stringify({
type: "removeItem",
value: key,
Expand All @@ -187,7 +185,6 @@ export const ReactNativeContextProvider = ({
};
localStorage.clear = function () {
clear.call(this);
// @ts-expect-error ReactNativeWebView is in the mobile app
window.ReactNativeWebView!.postMessage(
JSON.stringify({
type: "clear",
Expand All @@ -197,13 +194,11 @@ export const ReactNativeContextProvider = ({
}
}, 10000);
// obtain all values from storage
// @ts-expect-error ReactNativeWebView is in the mobile app
if (
window.ReactNativeWebView &&
window?.iOSRNWebView === true &&
window.iOSRNWebView === true &&
localStorage.getItem("iOSInit") !== "true"
) {
// @ts-expect-error ReactNativeWebView is in the mobile app
window.ReactNativeWebView!.postMessage(
JSON.stringify({
type: "multiGet",
Expand Down

0 comments on commit d939eb8

Please sign in to comment.