-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CP-9314: Set up dynamic app switch (#2016)
- Loading branch information
Showing
17 changed files
with
231 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import React, { useState, useCallback, useMemo } from 'react' | ||
import { Alert, View, PanResponder } from 'react-native' | ||
import OldApp from 'ContextApp' | ||
import NewApp from 'new/ContextApp' | ||
import { commonStorage } from 'utils/mmkv' | ||
import { StorageKey } from 'resources/Constants' | ||
import DeviceInfoService from 'services/deviceInfo/DeviceInfoService' | ||
import DevDebuggingConfig from 'utils/debugging/DevDebuggingConfig' | ||
|
||
const bundleId = DeviceInfoService.getBundleId() | ||
const isInternalBuild = | ||
bundleId === 'org.avalabs.avaxwallet.internal' || | ||
bundleId === 'com.avaxwallet.internal' | ||
|
||
export const AppSwitcher = (): React.JSX.Element => { | ||
const [isNewApp, setIsNewApp] = useState( | ||
commonStorage.getBoolean(StorageKey.K2_ALPINE) | ||
) | ||
|
||
const switchApp = useCallback(() => { | ||
const newValue = !isNewApp | ||
commonStorage.set(StorageKey.K2_ALPINE, newValue) | ||
setIsNewApp(newValue) | ||
}, [isNewApp, setIsNewApp]) | ||
|
||
const panResponder = useMemo( | ||
() => | ||
PanResponder.create({ | ||
onStartShouldSetPanResponder: (evt, gestureState) => { | ||
if (gestureState.numberActiveTouches === 2) { | ||
Alert.alert('Switch App Experience?', '', [ | ||
{ | ||
text: 'Cancel', | ||
style: 'cancel' | ||
}, | ||
{ text: 'OK', onPress: switchApp } | ||
]) | ||
} | ||
|
||
return true | ||
} | ||
}), | ||
[switchApp] | ||
) | ||
|
||
// only allow switching to new app on internal builds | ||
if (!isInternalBuild) return <OldApp /> | ||
|
||
return ( | ||
<View style={{ flex: 1 }} {...panResponder.panHandlers}> | ||
{DevDebuggingConfig.K2_ALPINE || isNewApp ? <NewApp /> : <OldApp />} | ||
</View> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { ExpoRoot } from 'expo-router' | ||
import React from 'react' | ||
|
||
export const App = () => { | ||
const ctx = require.context('./routes') | ||
|
||
return <ExpoRoot context={ctx} /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/** | ||
* Context wrapper for App | ||
**/ | ||
import React, { FC, PropsWithChildren, useEffect, useState } from 'react' | ||
import * as Sentry from '@sentry/react-native' | ||
import Toast from 'react-native-toast-notifications' | ||
import JailMonkey from 'jail-monkey' | ||
import { RootSiblingParent } from 'react-native-root-siblings' | ||
import JailbrokenWarning from 'screens/onboarding/JailbrokenWarning' | ||
import { PosthogContextProvider } from 'contexts/PosthogContext' | ||
import { StatusBar } from 'react-native' | ||
import { EncryptedStoreProvider } from 'contexts/EncryptedStoreProvider' | ||
import { TopLevelErrorFallback } from 'components/TopLevelErrorFallback' | ||
import { GestureHandlerRootView } from 'react-native-gesture-handler' | ||
import { ReactQueryProvider } from 'contexts/ReactQueryProvider' | ||
import SentryService from 'services/sentry/SentryService' | ||
import { App } from './App' | ||
|
||
function setToast(toast: Toast): void { | ||
global.toast = toast | ||
} | ||
|
||
/** | ||
* Aggregate all the top-level context providers for better readability. | ||
*/ | ||
// TODO: add DeeplinkContextProvider | ||
const ContextProviders: FC<PropsWithChildren> = ({ children }) => ( | ||
<EncryptedStoreProvider> | ||
<ReactQueryProvider> | ||
<PosthogContextProvider>{children}</PosthogContextProvider> | ||
</ReactQueryProvider> | ||
</EncryptedStoreProvider> | ||
) | ||
|
||
const ContextApp = (): JSX.Element => { | ||
// TODO: convert TopLevelErrorFallback to new design | ||
return ( | ||
<Sentry.ErrorBoundary fallback={<TopLevelErrorFallback />}> | ||
<StatusBar barStyle={'light-content'} backgroundColor="black" /> | ||
<ContextProviders> | ||
<JailBrokenCheck> | ||
<GestureHandlerRootView style={{ flex: 1 }}> | ||
<RootSiblingParent> | ||
<App /> | ||
</RootSiblingParent> | ||
</GestureHandlerRootView> | ||
</JailBrokenCheck> | ||
<Toast | ||
ref={ref => { | ||
ref && setToast(ref) | ||
}} | ||
offsetTop={30} | ||
normalColor={'00FFFFFF'} | ||
/> | ||
</ContextProviders> | ||
</Sentry.ErrorBoundary> | ||
) | ||
} | ||
|
||
const JailBrokenCheck: FC<PropsWithChildren> = ({ children }) => { | ||
const [showJailBroken, setShowJailBroken] = useState(false) | ||
|
||
useEffect(() => { | ||
if (!__DEV__ && JailMonkey.isJailBroken()) { | ||
setShowJailBroken(true) | ||
} | ||
}, []) | ||
|
||
if (showJailBroken) { | ||
// TODO: convert JailbrokenWarning to new design | ||
return <JailbrokenWarning onOK={() => setShowJailBroken(false)} /> | ||
} | ||
|
||
return <>{children}</> | ||
} | ||
|
||
export default SentryService.isAvailable ? Sentry.wrap(ContextApp) : ContextApp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.