From 9583ff4e4d7e67111dbfc9ddbfb8c821ccd42fb4 Mon Sep 17 00:00:00 2001 From: Shreyaschorge Date: Sun, 31 Mar 2024 01:41:28 +0530 Subject: [PATCH] Handle opening http and https urls in webview --- react-native-sign-in-with-neynar/package.json | 2 +- .../src/NeynarSigninButton.tsx | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/react-native-sign-in-with-neynar/package.json b/react-native-sign-in-with-neynar/package.json index 519db84..d86d51a 100644 --- a/react-native-sign-in-with-neynar/package.json +++ b/react-native-sign-in-with-neynar/package.json @@ -1,6 +1,6 @@ { "name": "@neynar/react-native-signin", - "version": "0.2.4", + "version": "0.2.5", "keywords": [ "react-native", "neynar", diff --git a/react-native-sign-in-with-neynar/src/NeynarSigninButton.tsx b/react-native-sign-in-with-neynar/src/NeynarSigninButton.tsx index e670902..e8489e9 100644 --- a/react-native-sign-in-with-neynar/src/NeynarSigninButton.tsx +++ b/react-native-sign-in-with-neynar/src/NeynarSigninButton.tsx @@ -217,11 +217,21 @@ export const NeynarSigninButton = ({ onMessage={handleMessage} originWhitelist={["*"]} onShouldStartLoadWithRequest={(event) => { + // For URLs that start with "https://warpcast.com", attempt to open them externally if (event.url.startsWith("https://warpcast.com")) { Linking.openURL(event.url).catch((err) => errorCallback(err)); - return false; + return false; // Prevent WebView from loading this URL } - return true; + + // Allow URLs that start with "http://" or "https://" + if (event.url.match(/^(https:\/\/)|(http:\/\/)/)) { + return true; // Load these URLs within the WebView + } + + // Attempt to open all other URLs (not starting with "http://" or "https://") + // in the device's default browser. + Linking.openURL(event.url).catch((err) => errorCallback(err)); + return false; // Prevent WebView from loading these URLs }} /> )}