File tree 4 files changed +43
-7
lines changed
src/components/TextMessage
4 files changed +43
-7
lines changed Original file line number Diff line number Diff line change 35
35
},
36
36
"dependencies" : {
37
37
"@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 " ,
39
39
"dayjs" : " ^1.10.4" ,
40
40
"react-native-image-viewing" : " ^0.2.0" ,
41
41
"react-native-parsed-text" : " ^0.0.22"
Original file line number Diff line number Diff line change @@ -45,7 +45,11 @@ export const TextMessage = ({
45
45
onPreviewDataFetched ?.( { message, previewData : data } )
46
46
}
47
47
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
+ }
49
53
50
54
const renderPreviewDescription = ( description : string ) => {
51
55
return (
@@ -62,11 +66,11 @@ export const TextMessage = ({
62
66
parse = { [
63
67
{
64
68
onPress : handleUrlPress ,
69
+ pattern : REGEX_LINK ,
65
70
style : StyleSheet . flatten ( [
66
71
text ,
67
72
{ textDecorationLine : 'underline' } ,
68
73
] ) ,
69
- type : 'url' ,
70
74
} ,
71
75
] }
72
76
style = { text }
Original file line number Diff line number Diff line change @@ -38,4 +38,36 @@ describe('text message', () => {
38
38
getPreviewDataMock . mockRestore ( )
39
39
openUrlMock . mockRestore ( )
40
40
} )
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
+ } )
41
73
} )
Original file line number Diff line number Diff line change 765
765
resolved "https://registry.yarnpkg.com/@flyerhq/react-native-keyboard-accessory-view/-/react-native-keyboard-accessory-view-2.2.0.tgz#b9aa613d10541ff0a8a4984ee16ddb5627b75496"
766
766
integrity sha512-6tBsrLXJ6u2ChjVAmbMMiSJmLOQJ7aneroS8HTUzPhefBbZXKKODQjmZ+pVF2tXmwuZr+CjZSzOQrfKXeXd68A==
767
767
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 ==
772
772
dependencies :
773
773
html-entities "^2.3.2"
774
774
You can’t perform that action at this time.
0 commit comments