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

[No QA][TS migration] Migrate 'asyncOpenURL' lib to TypeScript #26884

Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import {Linking} from 'react-native';
import AsyncOpenURL from './types';

export default function asyncOpenURL(promise, url) {
const asyncOpenURL: AsyncOpenURL = (promise, url) => {
if (!url) {
return;
}

promise.then((params) => {
Linking.openURL(typeof url === 'string' ? url : url(params));
});
}
};

export default asyncOpenURL;
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import {Linking} from 'react-native';
import AsyncOpenURL from './types';

/**
* Prevents Safari from blocking pop-up window when opened within async call.
*
* @param {Promise} promise
* @param {string} url
* @param {Boolean} shouldSkipCustomSafariLogic When true, we will use `Linking.openURL` even if the browser is Safari.
kowczarz marked this conversation as resolved.
Show resolved Hide resolved
*/
export default function asyncOpenURL(promise, url, shouldSkipCustomSafariLogic) {
const asyncOpenURL: AsyncOpenURL = (promise, url, shouldSkipCustomSafariLogic) => {
if (!url) {
return;
}
Expand All @@ -22,8 +19,13 @@ export default function asyncOpenURL(promise, url, shouldSkipCustomSafariLogic)
const windowRef = window.open();
promise
.then((params) => {
windowRef.location = typeof url === 'string' ? url : url(params);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @luacmartins! I see you're the last person who modified this line. Is there a reason why you skipped href here? There was a type error without, so I added it and I couldn't spot any regression, but I would like you to cross check it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @kowczarz , did you try this? It's working for me.

            .then((params) => {
                if (!windowRef) {
                    return;
                }
                windowRef.location = typeof url === 'string' ? url : url(params);
            })

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kowczarz bump

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that must have been some typescript caches left, because now it works flawlessly.

if (!windowRef) {
return;
}
windowRef.location.href = typeof url === 'string' ? url : url(params);
})
.catch(() => windowRef.close());
.catch(() => windowRef?.close());
}
}
};

export default asyncOpenURL;
3 changes: 3 additions & 0 deletions src/libs/asyncOpenURL/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
type AsyncOpenURL = <T>(promise: Promise<T>, url: string | ((params: T) => string), shouldSkipCustomSafariLogic?: boolean) => void;

export default AsyncOpenURL;
Loading