File tree Expand file tree Collapse file tree
src/components/TextMessage Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3535 },
3636 "dependencies" : {
3737 "@flyerhq/react-native-keyboard-accessory-view" : " ^2.2.0" ,
38- "@flyerhq/react-native-link-preview" : " ^1.3.0 " ,
38+ "@flyerhq/react-native-link-preview" : " ^1.3.1 " ,
3939 "dayjs" : " ^1.10.4" ,
4040 "react-native-image-viewing" : " ^0.2.0" ,
4141 "react-native-parsed-text" : " ^0.0.22"
Original file line number Diff line number Diff line change @@ -45,7 +45,11 @@ export const TextMessage = ({
4545 onPreviewDataFetched ?.( { message, previewData : data } )
4646 }
4747
48- const handleUrlPress = ( url : string ) => Linking . openURL ( url )
48+ const handleUrlPress = ( url : string ) => {
49+ const uri = url . toLowerCase ( ) . startsWith ( 'http' ) ? url : `https://${ url } `
50+
51+ Linking . openURL ( uri )
52+ }
4953
5054 const renderPreviewDescription = ( description : string ) => {
5155 return (
@@ -62,11 +66,11 @@ export const TextMessage = ({
6266 parse = { [
6367 {
6468 onPress : handleUrlPress ,
69+ pattern : REGEX_LINK ,
6570 style : StyleSheet . flatten ( [
6671 text ,
6772 { textDecorationLine : 'underline' } ,
6873 ] ) ,
69- type : 'url' ,
7074 } ,
7175 ] }
7276 style = { text }
Original file line number Diff line number Diff line change @@ -38,4 +38,36 @@ describe('text message', () => {
3838 getPreviewDataMock . mockRestore ( )
3939 openUrlMock . mockRestore ( )
4040 } )
41+
42+ it ( 'renders preview image without https and handles link press' , async ( ) => {
43+ expect . assertions ( 2 )
44+ const link = 'github.com/flyerhq/'
45+ const getPreviewDataMock = jest
46+ . spyOn ( utils , 'getPreviewData' )
47+ . mockResolvedValue ( {
48+ description : 'description' ,
49+ image : {
50+ height : 460 ,
51+ url : 'https://avatars2.githubusercontent.com/u/59206044' ,
52+ width : 460 ,
53+ } ,
54+ link,
55+ title : 'title' ,
56+ } )
57+ const openUrlMock = jest . spyOn ( Linking , 'openURL' )
58+ const { getByRole, getByText } = render (
59+ < TextMessage
60+ message = { { ...textMessage , text : link } }
61+ messageWidth = { 440 }
62+ />
63+ )
64+ await waitFor ( ( ) => getByRole ( 'image' ) )
65+ const image = getByRole ( 'image' )
66+ expect ( image ) . toBeDefined ( )
67+ const text = getByText ( link )
68+ fireEvent . press ( text )
69+ expect ( openUrlMock ) . toHaveBeenCalledWith ( 'https://' + link )
70+ getPreviewDataMock . mockRestore ( )
71+ openUrlMock . mockRestore ( )
72+ } )
4173} )
Original file line number Diff line number Diff line change 765765 resolved "https://registry.yarnpkg.com/@flyerhq/react-native-keyboard-accessory-view/-/react-native-keyboard-accessory-view-2.2.0.tgz#b9aa613d10541ff0a8a4984ee16ddb5627b75496"
766766 integrity sha512-6tBsrLXJ6u2ChjVAmbMMiSJmLOQJ7aneroS8HTUzPhefBbZXKKODQjmZ+pVF2tXmwuZr+CjZSzOQrfKXeXd68A==
767767
768- " @flyerhq/react-native-link-preview@^1.3.0 " :
769- version "1.3.0 "
770- resolved "https://registry.yarnpkg.com/@flyerhq/react-native-link-preview/-/react-native-link-preview-1.3.0 .tgz#c54dd41861a07ef8e5c69d5dcd9b3ccfd77178ca "
771- integrity sha512-nQgmYbfyfFkD2pJMe3EqtYiHMcDYA8gZ9pevhXZ16Stn1EwWvd7s14bd9h2B63g67TFoyVr/fiQrbH0rm8dryA ==
768+ " @flyerhq/react-native-link-preview@^1.3.1 " :
769+ version "1.3.1 "
770+ resolved "https://registry.yarnpkg.com/@flyerhq/react-native-link-preview/-/react-native-link-preview-1.3.1 .tgz#620c5405ce3b51084673b963125e65db8fb92c0b "
771+ integrity sha512-b6kExHnWt4Shwbgtv11MClVFl1v46RDciS/fAv3+Aw8RVbk12HgMkCDLGbXCcYpXAzp3iiTqtAyUHQOj70/Qag ==
772772 dependencies :
773773 html-entities "^2.3.2"
774774
You can’t perform that action at this time.
0 commit comments