修复webview处理重定向时的bug,适配微信H5支付;为webview增加打开浏览器功能

This commit is contained in:
yezian 2024-02-27 00:24:27 +08:00
parent 00092db4c4
commit 1207a4407a
2 changed files with 24 additions and 10 deletions

View File

@ -82,7 +82,12 @@ export default function WebWithHeader({ navigation, route }) {
});
};
//
//
const openBrowser = async (data) => {
Linking.openURL(data);
};
//
const handleUrlRedirect = (event) => {
const { url } = event;
@ -108,7 +113,7 @@ export default function WebWithHeader({ navigation, route }) {
{ cancelable: false }
);
});
return true; // URL
return false; // URL
} catch (error) {
// URL
console.error(error);
@ -116,9 +121,9 @@ export default function WebWithHeader({ navigation, route }) {
}
// weixin:scheme
if (url.startsWith("weixin:")) {
if (url.startsWith("weixin:") || url.startsWith("weixin")) {
try {
//
//
Linking.openURL(url).catch(() => {
//
Alert.alert(
@ -128,7 +133,7 @@ export default function WebWithHeader({ navigation, route }) {
{ cancelable: false }
);
});
return true; // URL
return false; // URL
} catch (error) {
// URL
console.error(error);
@ -155,6 +160,8 @@ export default function WebWithHeader({ navigation, route }) {
copy(msg.data);
} else if (msg.type === "NAVIGATE") {
navigation.navigate(msg.data.page, { ...msg.data.params });
} else if (msg.type === "OPEN_BROWSER") {
openBrowser(msg.data);
}
}}
injectedJavaScript={setCookieScript}

View File

@ -75,7 +75,12 @@ export default function WebWithoutHeader({ navigation, route }) {
});
};
//
//
const openBrowser = async (data) => {
Linking.openURL(data);
};
//
const handleUrlRedirect = (event) => {
const { url } = event;
@ -101,7 +106,7 @@ export default function WebWithoutHeader({ navigation, route }) {
{ cancelable: false }
);
});
return true; // URL
return false; // URL
} catch (error) {
// URL
console.error(error);
@ -109,9 +114,9 @@ export default function WebWithoutHeader({ navigation, route }) {
}
// weixin:scheme
if (url.startsWith("weixin:")) {
if (url.startsWith("weixin:") || url.startsWith("weixin")) {
try {
//
//
Linking.openURL(url).catch(() => {
//
Alert.alert(
@ -121,7 +126,7 @@ export default function WebWithoutHeader({ navigation, route }) {
{ cancelable: false }
);
});
return true; // URL
return false; // URL
} catch (error) {
// URL
console.error(error);
@ -148,6 +153,8 @@ export default function WebWithoutHeader({ navigation, route }) {
copy(msg.data);
} else if (msg.type === "NAVIGATE") {
navigation.navigate(msg.data.page, { ...msg.data.params });
} else if (msg.type === "OPEN_BROWSER") {
openBrowser(msg.data);
}
}}
injectedJavaScript={setCookieScript}