From d9d73eda22e414a4172d5db5503b43db1fa3bec6 Mon Sep 17 00:00:00 2001 From: Matej Lubej Date: Tue, 21 May 2024 16:30:17 +0200 Subject: [PATCH] Add Android update wall --- src/app/components/Ionic/IonicProvider.tsx | 21 -------------- .../IonicNativePlatformProvider/index.tsx | 16 ++++++++++ .../Ionic/components/RequiresUpdate/index.tsx | 29 +++++++++++++++++++ ....tsx => useIonicAppStateChangeListener.ts} | 0 .../Ionic/hooks/useIonicRequiresUpdate.ts | 23 +++++++++++++++ .../Ionic/providers/IonicContext.ts | 17 +++++++++++ .../Ionic/providers/IonicProvider.tsx | 23 +++++++++++++++ .../Ionic/utils/capacitor-app-update.ts | 29 +++++++++++++++++++ src/app/index.tsx | 6 ++-- 9 files changed, 140 insertions(+), 24 deletions(-) delete mode 100644 src/app/components/Ionic/IonicProvider.tsx create mode 100644 src/app/components/Ionic/components/IonicNativePlatformProvider/index.tsx create mode 100644 src/app/components/Ionic/components/RequiresUpdate/index.tsx rename src/app/components/Ionic/hooks/{useIonicAppStateChangeListener.tsx => useIonicAppStateChangeListener.ts} (100%) create mode 100644 src/app/components/Ionic/hooks/useIonicRequiresUpdate.ts create mode 100644 src/app/components/Ionic/providers/IonicContext.ts create mode 100644 src/app/components/Ionic/providers/IonicProvider.tsx create mode 100644 src/app/components/Ionic/utils/capacitor-app-update.ts diff --git a/src/app/components/Ionic/IonicProvider.tsx b/src/app/components/Ionic/IonicProvider.tsx deleted file mode 100644 index 7e7b538230..0000000000 --- a/src/app/components/Ionic/IonicProvider.tsx +++ /dev/null @@ -1,21 +0,0 @@ -import { createContext, FC, PropsWithChildren } from 'react' -import { Capacitor } from '@capacitor/core' -import { useIonicBackButtonListener } from './hooks/useIonicBackButtonListener' -import { useIonicAppStateChangeListener } from './hooks/useIonicAppStateChangeListener' - -const IonicContext = createContext(undefined) - -const IonicContextProvider: FC = ({ children }) => { - useIonicBackButtonListener() - useIonicAppStateChangeListener() - - return {children} -} - -export const IonicProvider: FC = ({ children }) => { - if (Capacitor.isNativePlatform()) { - return {children} - } - - return children -} diff --git a/src/app/components/Ionic/components/IonicNativePlatformProvider/index.tsx b/src/app/components/Ionic/components/IonicNativePlatformProvider/index.tsx new file mode 100644 index 0000000000..6e02f301cf --- /dev/null +++ b/src/app/components/Ionic/components/IonicNativePlatformProvider/index.tsx @@ -0,0 +1,16 @@ +import { FC, PropsWithChildren } from 'react' +import { Capacitor } from '@capacitor/core' +import { IonicContextProvider } from '../../providers/IonicProvider' +import { RequiresUpdate } from '../RequiresUpdate' + +export const IonicNativePlatformProvider: FC = ({ children }) => { + if (Capacitor.isNativePlatform()) { + return + + {children} + + + } + + return children +} diff --git a/src/app/components/Ionic/components/RequiresUpdate/index.tsx b/src/app/components/Ionic/components/RequiresUpdate/index.tsx new file mode 100644 index 0000000000..51f0f62a70 --- /dev/null +++ b/src/app/components/Ionic/components/RequiresUpdate/index.tsx @@ -0,0 +1,29 @@ +import React, { FC, PropsWithChildren, useContext } from 'react' +import { IonicContext } from '../../providers/IonicContext' +import { Box } from 'grommet/es6/components/Box' +import { Button } from 'grommet/es6/components/Button' +import { navigateToAppStore } from '../../utils/capacitor-app-update' + +export const RequiresUpdate: FC = ({ children }) => { + const { state: { requiresUpdate } } = useContext(IonicContext) + + if (requiresUpdate === false) return children + + const handleNavigateToAppStore = () => { + navigateToAppStore() + } + + return ( + + {requiresUpdate === undefined && <>Loading...} + {requiresUpdate === true && <> + This app requires an update to the latest version in order to operate correctly. +