-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
164 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import React from 'react' | ||
import {BlueskyBottomSheetPressable} from '@haileyok/bluesky-bottom-sheet' | ||
import {StackActions, useNavigation} from '@react-navigation/native' | ||
|
||
import {NavigationProp} from '#/lib/routes/types' | ||
import {flatten, useTheme} from '#/alf' | ||
import {useDialogContext} from '#/components/Dialog' | ||
import {useInteractionState} from '#/components/hooks/useInteractionState' | ||
import {InlineLinkProps, useLink} from '#/components/Link' | ||
import {Text} from '#/components/Typography' | ||
import {router} from '#/routes' | ||
|
||
export function BottomSheetInlineLinkText({ | ||
children, | ||
to, | ||
action = 'push', | ||
disableMismatchWarning, | ||
style, | ||
onPress: outerOnPress, | ||
label, | ||
shareOnLongPress, | ||
disableUnderline, | ||
...rest | ||
}: InlineLinkProps) { | ||
const t = useTheme() | ||
const stringChildren = typeof children === 'string' | ||
const navigation = useNavigation<NavigationProp>() | ||
const dialog = useDialogContext() | ||
|
||
const {href, isExternal, onLongPress} = useLink({ | ||
to, | ||
displayText: stringChildren ? children : '', | ||
action, | ||
disableMismatchWarning, | ||
onPress: outerOnPress, | ||
shareOnLongPress, | ||
}) | ||
const { | ||
state: pressed, | ||
onIn: onPressIn, | ||
onOut: onPressOut, | ||
} = useInteractionState() | ||
|
||
const onPress = () => { | ||
if (isExternal) { | ||
return | ||
} | ||
|
||
dialog.close() | ||
|
||
if (action === 'push') { | ||
navigation.dispatch(StackActions.push(...router.matchPath(href))) | ||
} else if (action === 'replace') { | ||
navigation.dispatch(StackActions.replace(...router.matchPath(href))) | ||
} else if (action === 'navigate') { | ||
// @ts-ignore | ||
navigation.navigate(...router.matchPath(href)) | ||
} else { | ||
throw Error('Unsupported navigator action.') | ||
} | ||
} | ||
|
||
const flattenedStyle = flatten(style) || {} | ||
|
||
// eslint-disable-next-line bsky-internal/avoid-unwrapped-text | ||
return ( | ||
<BlueskyBottomSheetPressable | ||
onPress={onPress} | ||
onLongPress={onLongPress} | ||
onPressIn={onPressIn} | ||
onPressOut={onPressOut} | ||
role="link" | ||
accessibilityLabel={label} | ||
accessibilityHint="" | ||
style={{flexDirection: 'row'}}> | ||
<Text | ||
{...rest} | ||
style={[ | ||
{color: t.palette.primary_500}, | ||
pressed && | ||
!disableUnderline && { | ||
textDecorationLine: 'underline', | ||
textDecorationColor: | ||
flattenedStyle.color ?? t.palette.primary_500, | ||
}, | ||
flattenedStyle, | ||
]}> | ||
{children} | ||
</Text> | ||
</BlueskyBottomSheetPressable> | ||
) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import {Link as BottomSheetLink} from './Link' | ||
|
||
export {BottomSheetLink} |
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