Injimob-3649: add delay before rendering WebView to prevent missing authorize call on Android BrowserStack (#2148)

* [INJIMOB-3649]: need INJI Mobile APK with network logs enabled

Signed-off-by: jaswanthkumarpolisetty <jaswanthkumar.p@thoughtworks.com>

* [INJIMOB-3649]: add delay before loading WebView to prevent eSignet auth page not rendering on BrowserStack

Signed-off-by: jaswanthkumarpolisetty <jaswanthkumar.p@thoughtworks.com>

* [INJIMOB-3649]: fix WebView initialization issue on Android BrowserStack

Signed-off-by: jaswanthkumarpolisetty <jaswanthkumar.p@thoughtworks.com>

* [INJIMOB-3649]: remove the delay completely

Signed-off-by: jaswanthkumarpolisetty <jaswanthkumar.p@thoughtworks.com>

* [INJIMOB-3649]: clear coderabbit review comments

Signed-off-by: jaswanthkumarpolisetty <jaswanthkumar.p@thoughtworks.com>

* [INJIMOB-3649]: clear review comments

Signed-off-by: jaswanthkumarpolisetty <jaswanthkumar.p@thoughtworks.com>

* [INJIMOB-3649]: clear coderabbit review comments

Signed-off-by: jaswanthkumarpolisetty <jaswanthkumar.p@thoughtworks.com>

---------

Signed-off-by: jaswanthkumarpolisetty <jaswanthkumar.p@thoughtworks.com>
This commit is contained in:
jaswanthkumartw
2025-12-02 16:43:49 +05:30
committed by GitHub
parent b7f8783905
commit bc1fdd130d

View File

@@ -14,12 +14,15 @@ import {Ionicons} from '@expo/vector-icons';
import VciClient from '../shared/vciClient/VciClient';
import {Theme} from '../components/ui/styleUtils';
import {useTranslation} from 'react-i18next';
import {isAndroid} from '../shared/constants';
const AuthWebViewScreen: React.FC<any> = ({route, navigation}) => {
const {authorizationURL, clientId, redirectUri, controller} = route.params;
const webViewRef = useRef<WebView>(null);
const [showWebView, setShowWebView] = useState(false);
const [shouldRenderWebView, setShouldRenderWebView] = useState(false);
const {t} = useTranslation('authWebView');
const WEBVIEW_INIT_DELAY_MS = 300;
const hostName = new URL(authorizationURL).hostname; // example.mosip.net
const parsed = psl.parse(hostName);
@@ -74,6 +77,22 @@ const AuthWebViewScreen: React.FC<any> = ({route, navigation}) => {
handleBackPress,
]);
useEffect(() => {
let timeoutId: NodeJS.Timeout | null = null;
if (isAndroid()) {
setShouldRenderWebView(true);
timeoutId = setTimeout(() => {
setShouldRenderWebView(false);
}, WEBVIEW_INIT_DELAY_MS);
}
return () => {
if (timeoutId) clearTimeout(timeoutId);
};
}, []);
const handleNavigationRequest = (request: any) => {
const {url} = request;
if (url.startsWith(redirectUri)) {
@@ -118,6 +137,9 @@ const AuthWebViewScreen: React.FC<any> = ({route, navigation}) => {
return (
<SafeAreaView style={{flex: 1}}>
<Header />
{shouldRenderWebView && !showWebView && (
<WebView style={{width: 0, height: 0}} source={{uri: 'about:blank'}} />
)}
{showWebView && (
<WebView
ref={webViewRef}