-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: default to web URLs for hashtag/mention links and remove webFal…
…lback prop Since `webFallback` has been disabled on iOS since the beginning and Android has potential upcoming changes that could require disabling there too, `webFallback` has been removed and services are instead linked to the web versions by default. The `useNativeSchemes` prop can be used to default to native URL schemes instead. But the recommended approach is to use the `onPress` and/or `matchers` props to customize behavior to your liking for hastag and mention links. BREAKING CHANGE: The webFallback prop has been removed and service links for hashtags/mentions default to web URLs. Use the `useNativeSchemes` to link directly to apps instead or use `onPress`/`onLongPress`/`matchers` to customize behavior.
- Loading branch information
Showing
5 changed files
with
100 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,61 @@ | ||
import { EmailMatch, HashtagMatch, MentionMatch, PhoneMatch } from 'autolinker/dist/es2015'; | ||
|
||
export const getEmailUrl = (match: EmailMatch): string[] => [ | ||
`mailto:${encodeURIComponent(match.getEmail())}`, | ||
]; | ||
export const getEmailUrl = (match: EmailMatch): string => | ||
`mailto:${encodeURIComponent(match.getEmail())}`; | ||
|
||
export const getHashtagUrl = ( | ||
match: HashtagMatch, | ||
service: 'facebook' | 'instagram' | 'twitter' | false = false, | ||
): string[] => { | ||
native = false, | ||
): string => { | ||
const tag = encodeURIComponent(match.getHashtag()); | ||
|
||
switch (service) { | ||
case 'facebook': | ||
return [`fb://hashtag/${tag}`, `https://www.facebook.com/hashtag/${tag}`]; | ||
return native ? `fb://hashtag/${tag}` : `https://www.facebook.com/hashtag/${tag}`; | ||
case 'instagram': | ||
return [`instagram://tag?name=${tag}`, `https://www.instagram.com/explore/tags/${tag}/`]; | ||
return native | ||
? `instagram://tag?name=${tag}` | ||
: `https://www.instagram.com/explore/tags/${tag}/`; | ||
case 'twitter': | ||
return [`twitter://search?query=%23${tag}`, `https://twitter.com/hashtag/${tag}`]; | ||
return native ? `twitter://search?query=%23${tag}` : `https://twitter.com/hashtag/${tag}`; | ||
default: | ||
return [match.getMatchedText()]; | ||
return match.getMatchedText(); | ||
} | ||
}; | ||
|
||
export const getMentionUrl = ( | ||
match: MentionMatch, | ||
service: 'instagram' | 'soundcloud' | 'twitter' | false = false, | ||
): string[] => { | ||
native = false, | ||
): string => { | ||
const username = match.getMention(); | ||
|
||
switch (service) { | ||
case 'instagram': | ||
return [`instagram://user?username=${username}`, `https://www.instagram.com/${username}/`]; | ||
return native | ||
? `instagram://user?username=${username}` | ||
: `https://www.instagram.com/${username}/`; | ||
case 'soundcloud': | ||
return [`https://soundcloud.com/${username}`]; | ||
return `https://soundcloud.com/${username}`; | ||
case 'twitter': | ||
return [`twitter://user?screen_name=${username}`, `https://twitter.com/${username}`]; | ||
return native ? `twitter://user?screen_name=${username}` : `https://twitter.com/${username}`; | ||
default: | ||
return [match.getMatchedText()]; | ||
return match.getMatchedText(); | ||
} | ||
}; | ||
|
||
export const getPhoneUrl = ( | ||
match: PhoneMatch, | ||
method: 'sms' | 'tel' | 'text' | boolean = 'tel', | ||
): string[] => { | ||
): string => { | ||
const number = (match as PhoneMatch).getNumber(); | ||
|
||
switch (method) { | ||
case 'sms': | ||
case 'text': | ||
return [`sms:${number}`]; | ||
return `sms:${number}`; | ||
default: | ||
return [`tel:${number}`]; | ||
return `tel:${number}`; | ||
} | ||
}; |