chore: handle safe area insets better on android (skip e2e)

This commit is contained in:
Aman Harwara
2025-05-03 00:37:25 +05:30
parent a1d6a02c87
commit 2a3dd79da0
13 changed files with 152 additions and 11 deletions

View File

@@ -1,10 +1,11 @@
import React from 'react'
import { MobileWebAppContainer } from './MobileWebAppContainer'
const AppComponent: React.FC = () => {
return <MobileWebAppContainer />
}
import { SafeAreaProvider } from 'react-native-safe-area-context'
export const MobileWebApp = () => {
return <AppComponent />
return (
<SafeAreaProvider>
<MobileWebAppContainer />
</SafeAreaProvider>
)
}

View File

@@ -15,6 +15,7 @@ import { IsDev } from './Lib/Utils'
import { ReceivedSharedItemsHandler } from './ReceivedSharedItemsHandler'
import { ReviewService } from './ReviewService'
import notifee, { EventType } from '@notifee/react-native'
import { useSafeAreaInsets } from 'react-native-safe-area-context'
const LoggingEnabled = IsDev
@@ -96,6 +97,12 @@ const MobileWebAppContents = ({ destroyAndReload }: { destroyAndReload: () => vo
// iOS handles this using the `willChangeFrame` event instead
if (Platform.OS === 'android') {
fireKeyboardSizeChangeEvent(e)
webViewRef.current?.postMessage(
JSON.stringify({
reactNativeEvent: ReactNativeToWebEvent.KeyboardDidShow,
messageType: 'event',
}),
)
}
device.reloadStatusBarStyle(false)
})
@@ -344,14 +351,31 @@ const MobileWebAppContents = ({ destroyAndReload }: { destroyAndReload: () => vo
receivedSharedItemsHandlerInstance.deinit()
}
}, [])
const [didAppLaunch, setDidAppLaunch] = useState(false)
useEffect(() => {
return device.addApplicationEventReceiver((event) => {
if (event === ApplicationEvent.Launched) {
receivedSharedItemsHandler.current.setIsApplicationLaunched(true)
setDidAppLaunch(true)
}
})
}, [device])
const insets = useSafeAreaInsets()
useEffect(() => {
if (!didAppLaunch) {
return
}
webViewRef.current?.postMessage(
JSON.stringify({
reactNativeEvent: ReactNativeToWebEvent.UpdateSafeAreaInsets,
messageType: 'event',
messageData: insets,
}),
)
}, [didAppLaunch, insets])
const [didLoadEnd, setDidLoadEnd] = useState(false)
if (showAndroidWebviewUpdatePrompt) {