Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(IT Wallet): [SIW-1878] Loader before SPID Login Webview #6493

Merged
merged 7 commits into from
Dec 5, 2024
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { memo, useCallback, useMemo } from "react";
import React, { memo, useCallback, useMemo, useState } from "react";
import { Linking, StyleSheet, View } from "react-native";
import { WebView, WebViewNavigation } from "react-native-webview";
import * as O from "fp-ts/lib/Option";
Expand All @@ -8,7 +8,6 @@ import {
selectIsLoading
} from "../../../machine/eid/selectors";
import { ItwEidIssuanceMachineContext } from "../../../machine/provider";
import LoadingScreenContent from "../../../../../components/screens/LoadingScreenContent";
import I18n from "../../../../../i18n";
import { originSchemasWhiteList } from "../../../../../screens/authentication/originSchemasWhiteList";
import { itWalletIssuanceRedirectUri } from "../../../../../config";
Expand All @@ -17,15 +16,12 @@ import {
HeaderSecondLevelHookProps,
useHeaderSecondLevel
} from "../../../../../hooks/useHeaderSecondLevel";
import LoadingSpinnerOverlay from "../../../../../components/LoadingSpinnerOverlay";

const styles = StyleSheet.create({
webViewWrapper: { flex: 1 }
});

const LoadingSpinner = (
<LoadingScreenContent contentTitle={I18n.t("global.genericWaiting")} />
);

// To ensure the server recognizes the client as a valid mobile device, we use a custom user agent header.
const defaultUserAgent =
"Mozilla/5.0 (iPhone; CPU iPhone OS 14_0_1 like Mac OS X; Linux; Android 10) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0 Mobile/15E148 Safari/604.1";
Expand All @@ -41,6 +37,11 @@ const ItwSpidIdpLoginScreen = () => {
const spidAuthUrl =
ItwEidIssuanceMachineContext.useSelector(selectAuthUrlOption);
const machineRef = ItwEidIssuanceMachineContext.useActorRef();
const [isWebViewLoading, setWebViewLoading] = useState(true);

const onLoadEnd = useCallback(() => {
setWebViewLoading(false);
}, []);

const onError = useCallback(() => {
machineRef.send({ type: "error", scope: "spid-login" });
Expand Down Expand Up @@ -98,9 +99,10 @@ const ItwSpidIdpLoginScreen = () => {
const content = useMemo(
() =>
O.fold(
() => LoadingSpinner,
() => null,
(url: string) => (
<WebView
key={"spid_webview"}
cacheEnabled={false}
androidCameraAccessDisabled
androidMicrophoneAccessDisabled
Expand All @@ -115,22 +117,27 @@ const ItwSpidIdpLoginScreen = () => {
allowsInlineMediaPlayback
mediaPlaybackRequiresUserAction
userAgent={defaultUserAgent}
onLoadEnd={onLoadEnd}
/>
)
)(spidAuthUrl),
[
spidAuthUrl,
handleNavigationStateChange,
handleShouldStartLoading,
onError
onError,
onLoadEnd
]
);

if (isMachineLoading) {
return LoadingSpinner;
}

return <View style={styles.webViewWrapper}>{content}</View>;
return (
<LoadingSpinnerOverlay
isLoading={isWebViewLoading || isMachineLoading}
loadingOpacity={1.0}
>
<View style={styles.webViewWrapper}>{content}</View>
</LoadingSpinnerOverlay>
);
};

export default memo(ItwSpidIdpLoginScreen);
Loading