-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Add asyncOpenURL wrapper #3764
Merged
Merged
Add asyncOpenURL wrapper #3764
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import {Linking} from 'react-native'; | ||
|
||
export default function asyncOpenURL(promise, url) { | ||
if (!url) { | ||
return; | ||
} | ||
|
||
promise.then(() => { | ||
Linking.openURL(url); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import {Linking} from 'react-native'; | ||
|
||
/** | ||
* Prevents Safari from blocking pop-up window when opened within async call. | ||
* | ||
* @param {Promise} promise | ||
* @param {string} url | ||
*/ | ||
export default function asyncOpenURL(promise, url) { | ||
if (!url) { | ||
return; | ||
} | ||
|
||
const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent); | ||
|
||
if (!isSafari) { | ||
promise.then(() => { | ||
Linking.openURL(url); | ||
}); | ||
} else { | ||
const windowRef = window.open(); | ||
promise | ||
.then(() => { | ||
windowRef.location = url; | ||
}) | ||
.catch(() => windowRef.close()); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain why are you doing a negative patten match for chrome or android here? Is there some case when the user agent would be formatted like 'chrome-xxx-safari' or something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@roryabraham
The negative pattern match is to exclude chrome, edge, and android.
All of them like to include Safari in their UA
Edge and Chrome's userAgent:
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36"
Also, I think all third party browsers on iOS are just skins for safari.
So chrome on iOS has this issue too. And this pattern detects that in my testing :)
Chrome on iOS detected as Safari
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for answering this @rushatgabhane! Yes, that is the reason I used the negative pattern match. @roryabraham Do we have any other preferred method?