1 | import type { NavigationAction } from '@react-navigation/core';
|
2 | import * as React from 'react';
|
3 | import { GestureResponderEvent, Platform, Text, TextProps } from 'react-native';
|
4 |
|
5 | import useLinkProps from './useLinkProps';
|
6 | import type { To } from './useLinkTo';
|
7 |
|
8 | type Props<ParamList extends ReactNavigation.RootParamList> = {
|
9 | to: To<ParamList>;
|
10 | action?: NavigationAction;
|
11 | target?: string;
|
12 | onPress?: (
|
13 | e: React.MouseEvent<HTMLAnchorElement, MouseEvent> | GestureResponderEvent
|
14 | ) => void;
|
15 | } & (TextProps & { children: React.ReactNode });
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | export default function Link<ParamList extends ReactNavigation.RootParamList>({
|
26 | to,
|
27 | action,
|
28 | ...rest
|
29 | }: Props<ParamList>) {
|
30 | const props = useLinkProps<ParamList>({ to, action });
|
31 |
|
32 | const onPress = (
|
33 | e: React.MouseEvent<HTMLAnchorElement, MouseEvent> | GestureResponderEvent
|
34 | ) => {
|
35 | if ('onPress' in rest) {
|
36 | rest.onPress?.(e);
|
37 | }
|
38 |
|
39 | props.onPress(e);
|
40 | };
|
41 |
|
42 | return React.createElement(Text, {
|
43 | ...props,
|
44 | ...rest,
|
45 | ...Platform.select({
|
46 | web: { onClick: onPress } as any,
|
47 | default: { onPress },
|
48 | }),
|
49 | });
|
50 | }
|