Skip to content

Commit

Permalink
Handle opening http and https urls in webview
Browse files Browse the repository at this point in the history
  • Loading branch information
Shreyaschorge committed Mar 30, 2024
1 parent f14f3ee commit 9583ff4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion react-native-sign-in-with-neynar/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@neynar/react-native-signin",
"version": "0.2.4",
"version": "0.2.5",
"keywords": [
"react-native",
"neynar",
Expand Down
14 changes: 12 additions & 2 deletions react-native-sign-in-with-neynar/src/NeynarSigninButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
}}
/>
)}
Expand Down

0 comments on commit 9583ff4

Please sign in to comment.