Skip to content

Commit

Permalink
fix: url without http/s opening issue
Browse files Browse the repository at this point in the history
  • Loading branch information
khushal87 committed Apr 27, 2022
1 parent 5654c39 commit 9c67d44
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
19 changes: 13 additions & 6 deletions package/src/components/Attachment/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,20 @@ const styles = StyleSheet.create({

const goToURL = (url?: string) => {
if (!url) return;
Linking.canOpenURL(url).then((supported) => {
if (supported) {
Linking.openURL(url);
} else {
console.log(`Don't know how to open URI: ${url}`);
else {
let finalUrl = url;
const pattern = new RegExp(/^.+\/\//);
if (!pattern.test(url)) {
finalUrl = 'http://' + url;
}
});
Linking.canOpenURL(finalUrl).then((supported) => {
if (supported) {
Linking.openURL(finalUrl);
} else {
console.log(`Don't know how to open URI: ${finalUrl}`);
}
});
}
};

export type CardPropsWithContext<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,16 @@ export const renderText = <
},
};

const onLink = (url: string) =>
onLinkParams
const onLink = (url: string) => {
const pattern = new RegExp(/^.+\/\//);
if (!pattern.test(url)) {
url = 'http://' + url;
}

return onLinkParams
? onLinkParams(url)
: Linking.canOpenURL(url).then((canOpenUrl) => canOpenUrl && Linking.openURL(url));
};

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

0 comments on commit 9c67d44

Please sign in to comment.