(optional) In app browser (#2490)
* add expo web browser + modal * add in app browser option to settings * don't show toggle on web * Tweak browser-choice UIs --------- Co-authored-by: Samuel Newman <mozzius@protonmail.com>
This commit is contained in:
parent
b147f7ae8a
commit
998ee29986
11 changed files with 299 additions and 22 deletions
|
@ -1,6 +1,5 @@
|
|||
import React, {ComponentProps, memo, useMemo} from 'react'
|
||||
import {
|
||||
Linking,
|
||||
GestureResponderEvent,
|
||||
Platform,
|
||||
StyleProp,
|
||||
|
@ -31,6 +30,7 @@ import {sanitizeUrl} from '@braintree/sanitize-url'
|
|||
import {PressableWithHover} from './PressableWithHover'
|
||||
import FixedTouchableHighlight from '../pager/FixedTouchableHighlight'
|
||||
import {useModalControls} from '#/state/modals'
|
||||
import {useOpenLink} from '#/state/preferences/in-app-browser'
|
||||
|
||||
type Event =
|
||||
| React.MouseEvent<HTMLAnchorElement, MouseEvent>
|
||||
|
@ -65,6 +65,7 @@ export const Link = memo(function Link({
|
|||
const {closeModal} = useModalControls()
|
||||
const navigation = useNavigation<NavigationProp>()
|
||||
const anchorHref = asAnchor ? sanitizeUrl(href) : undefined
|
||||
const openLink = useOpenLink()
|
||||
|
||||
const onPress = React.useCallback(
|
||||
(e?: Event) => {
|
||||
|
@ -74,11 +75,12 @@ export const Link = memo(function Link({
|
|||
navigation,
|
||||
sanitizeUrl(href),
|
||||
navigationAction,
|
||||
openLink,
|
||||
e,
|
||||
)
|
||||
}
|
||||
},
|
||||
[closeModal, navigation, navigationAction, href],
|
||||
[closeModal, navigation, navigationAction, href, openLink],
|
||||
)
|
||||
|
||||
if (noFeedback) {
|
||||
|
@ -172,6 +174,7 @@ export const TextLink = memo(function TextLink({
|
|||
const {...props} = useLinkProps({to: sanitizeUrl(href)})
|
||||
const navigation = useNavigation<NavigationProp>()
|
||||
const {openModal, closeModal} = useModalControls()
|
||||
const openLink = useOpenLink()
|
||||
|
||||
if (warnOnMismatchingLabel && typeof text !== 'string') {
|
||||
console.error('Unable to detect mismatching label')
|
||||
|
@ -200,6 +203,7 @@ export const TextLink = memo(function TextLink({
|
|||
navigation,
|
||||
sanitizeUrl(href),
|
||||
navigationAction,
|
||||
openLink,
|
||||
e,
|
||||
)
|
||||
},
|
||||
|
@ -212,6 +216,7 @@ export const TextLink = memo(function TextLink({
|
|||
text,
|
||||
warnOnMismatchingLabel,
|
||||
navigationAction,
|
||||
openLink,
|
||||
],
|
||||
)
|
||||
const hrefAttrs = useMemo(() => {
|
||||
|
@ -317,6 +322,7 @@ function onPressInner(
|
|||
navigation: NavigationProp,
|
||||
href: string,
|
||||
navigationAction: 'push' | 'replace' | 'navigate' = 'push',
|
||||
openLink: (href: string) => void,
|
||||
e?: Event,
|
||||
) {
|
||||
let shouldHandle = false
|
||||
|
@ -345,7 +351,7 @@ function onPressInner(
|
|||
if (shouldHandle) {
|
||||
href = convertBskyAppUrlIfNeeded(href)
|
||||
if (newTab || href.startsWith('http') || href.startsWith('mailto')) {
|
||||
Linking.openURL(href)
|
||||
openLink(href)
|
||||
} else {
|
||||
closeModal() // close any active modals
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue