Skip to content

Commit 9c67d44

Browse files
committed
fix: url without http/s opening issue
1 parent 5654c39 commit 9c67d44

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

package/src/components/Attachment/Card.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,20 @@ const styles = StyleSheet.create({
6969

7070
const goToURL = (url?: string) => {
7171
if (!url) return;
72-
Linking.canOpenURL(url).then((supported) => {
73-
if (supported) {
74-
Linking.openURL(url);
75-
} else {
76-
console.log(`Don't know how to open URI: ${url}`);
72+
else {
73+
let finalUrl = url;
74+
const pattern = new RegExp(/^.+\/\//);
75+
if (!pattern.test(url)) {
76+
finalUrl = 'http://' + url;
7777
}
78-
});
78+
Linking.canOpenURL(finalUrl).then((supported) => {
79+
if (supported) {
80+
Linking.openURL(finalUrl);
81+
} else {
82+
console.log(`Don't know how to open URI: ${finalUrl}`);
83+
}
84+
});
85+
}
7986
};
8087

8188
export type CardPropsWithContext<

package/src/components/Message/MessageSimple/utils/renderText.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,16 @@ export const renderText = <
147147
},
148148
};
149149

150-
const onLink = (url: string) =>
151-
onLinkParams
150+
const onLink = (url: string) => {
151+
const pattern = new RegExp(/^.+\/\//);
152+
if (!pattern.test(url)) {
153+
url = 'http://' + url;
154+
}
155+
156+
return onLinkParams
152157
? onLinkParams(url)
153158
: Linking.canOpenURL(url).then((canOpenUrl) => canOpenUrl && Linking.openURL(url));
159+
};
154160

155161
const link: ReactNodeOutput = (node, output, { ...state }) => {
156162
const onPress = (event: GestureResponderEvent) => {

0 commit comments

Comments
 (0)