diff options
Diffstat (limited to 'src/components/Link.tsx')
-rw-r--r-- | src/components/Link.tsx | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/src/components/Link.tsx b/src/components/Link.tsx index d8ac829b6..a8b478be7 100644 --- a/src/components/Link.tsx +++ b/src/components/Link.tsx @@ -1,5 +1,10 @@ import React from 'react' -import {GestureResponderEvent} from 'react-native' +import { + GestureResponderEvent, + Pressable, + StyleProp, + ViewStyle, +} from 'react-native' import {sanitizeUrl} from '@braintree/sanitize-url' import {StackActions, useLinkProps} from '@react-navigation/native' @@ -323,3 +328,45 @@ export function InlineLinkText({ </Text> ) } + +/** + * A Pressable that uses useLink to handle navigation. It is unstyled, so can be used in cases where the Button styles + * in Link are not desired. + * @param displayText + * @param style + * @param children + * @param rest + * @constructor + */ +export function BaseLink({ + displayText, + onPress: onPressOuter, + style, + children, + ...rest +}: { + style?: StyleProp<ViewStyle> + children: React.ReactNode + to: string + action: 'push' | 'replace' | 'navigate' + onPress?: () => false | void + shareOnLongPress?: boolean + label: string + displayText?: string +}) { + const {onPress, ...btnProps} = useLink({ + displayText: displayText ?? rest.to, + ...rest, + }) + return ( + <Pressable + style={style} + onPress={e => { + onPressOuter?.() + onPress(e) + }} + {...btnProps}> + {children} + </Pressable> + ) +} |