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

[IOPID-2142]: add check iOS version before rendering UIActivityIndicatorView, change linking listener removal #6

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 22 additions & 19 deletions example/src/screen/WebViewLoginScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,32 @@ const serviceProviderUrl =
export const WebViewLogin = () => {
React.useEffect(() => {
// https://reactnative.dev/docs/linking#open-links-and-deep-links-universal-links
Linking.addEventListener('url', ({ url }) => {
console.log('-- -->URL from Deep Liking', url);
// if the url is of this format: iologincie:https://idserver.servizicie.interno.gov.it/idp/login/livello2mobile?value=e1s2
// extract the part after iologincie: and dispatch the action to handle the login
if (url.startsWith('iologincie:')) {
const continueUrl = url.split('iologincie:')[1];

if (continueUrl) {
console.log('-- --> iOS continue URL', continueUrl);
// https://idserver.servizicie.interno.gov.it/cieiderror?cieid_error_message=Operazione_annullata_dall'utente
// We check if the continueUrl is an error
if (continueUrl.indexOf('cieiderror') !== -1) {
// And we extract the error message and show it in an alert
const errorMessage = continueUrl.split('cieid_error_message=')[1];
Alert.alert('Login error ❌', errorMessage ?? 'error');
} else {
setAuthenticatedUrl(continueUrl);
const urlListenerSubscription = Linking.addEventListener(
'url',
({ url }) => {
console.log('-- -->URL from Deep Liking', url);
// if the url is of this format: iologincie:https://idserver.servizicie.interno.gov.it/idp/login/livello2mobile?value=e1s2
// extract the part after iologincie: and dispatch the action to handle the login
if (url.startsWith('iologincie:')) {
const continueUrl = url.split('iologincie:')[1];

if (continueUrl) {
console.log('-- --> iOS continue URL', continueUrl);
// https://idserver.servizicie.interno.gov.it/cieiderror?cieid_error_message=Operazione_annullata_dall'utente
// We check if the continueUrl is an error
if (continueUrl.indexOf('cieiderror') !== -1) {
// And we extract the error message and show it in an alert
const errorMessage = continueUrl.split('cieid_error_message=')[1];
Alert.alert('Login error ❌', errorMessage ?? 'error');
} else {
setAuthenticatedUrl(continueUrl);
}
}
}
}
});
);

return () => Linking.removeAllListeners('url');
return () => urlListenerSubscription.remove();
}, []);

const webView = React.useRef<WebView>(null);
Expand Down
6 changes: 5 additions & 1 deletion ios/CieIDWKWebViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ class CieIDWKWebViewController: UIViewController, WKNavigationDelegate {

private func addActivityIndicatory() {

activityIndicator = UIActivityIndicatorView(style: .large)
if #available(iOS 13.0, *) {
activityIndicator = UIActivityIndicatorView(style: .large)
} else {
activityIndicator = UIActivityIndicatorView()
}
activityIndicator.color = UIColor.lightGray
activityIndicator.center = self.view.center
self.view.addSubview(activityIndicator)
Expand Down
Loading