mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-03-06 22:39:41 +08:00
refactor: remove onLink prop for now
This commit is contained in:
@@ -119,6 +119,7 @@ export default function BottomTabBarItem({
|
||||
style,
|
||||
onPress,
|
||||
href,
|
||||
accessibilityRole,
|
||||
...rest
|
||||
}: BottomTabBarButtonProps) => {
|
||||
if (Platform.OS === 'web' && href) {
|
||||
@@ -127,18 +128,28 @@ export default function BottomTabBarItem({
|
||||
return (
|
||||
<Link
|
||||
{...rest}
|
||||
// @ts-ignore
|
||||
accessibilityRole="link"
|
||||
onLink={onPress}
|
||||
to={href}
|
||||
style={[styles.button, style]}
|
||||
onPress={(e: any) => {
|
||||
if (
|
||||
!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey) && // ignore clicks with modifier keys
|
||||
(e.button == null || e.button === 0) // ignore everything but left clicks
|
||||
) {
|
||||
e.preventDefault();
|
||||
onPress?.(e);
|
||||
}
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</Link>
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
<TouchableWithoutFeedback {...rest} onPress={onPress}>
|
||||
<TouchableWithoutFeedback
|
||||
{...rest}
|
||||
accessibilityRole={accessibilityRole}
|
||||
onPress={onPress}
|
||||
>
|
||||
<View style={style}>{children}</View>
|
||||
</TouchableWithoutFeedback>
|
||||
);
|
||||
|
||||
@@ -71,6 +71,7 @@ const Touchable = ({
|
||||
style,
|
||||
onPress,
|
||||
href,
|
||||
accessibilityRole,
|
||||
delayPressIn,
|
||||
...rest
|
||||
}: TouchableWithoutFeedbackProps & {
|
||||
@@ -84,18 +85,29 @@ const Touchable = ({
|
||||
return (
|
||||
<Link
|
||||
{...rest}
|
||||
// @ts-ignore
|
||||
accessibilityRole="link"
|
||||
onLink={onPress}
|
||||
to={href}
|
||||
style={[styles.button, style]}
|
||||
onPress={(e: any) => {
|
||||
if (
|
||||
!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey) && // ignore clicks with modifier keys
|
||||
(e.button == null || e.button === 0) // ignore everything but left clicks
|
||||
) {
|
||||
e.preventDefault();
|
||||
onPress?.(e);
|
||||
}
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</Link>
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
<TouchableItem {...rest} delayPressIn={delayPressIn} onPress={onPress}>
|
||||
<TouchableItem
|
||||
{...rest}
|
||||
accessibilityRole={accessibilityRole}
|
||||
delayPressIn={delayPressIn}
|
||||
onPress={onPress}
|
||||
>
|
||||
<View style={style}>{children}</View>
|
||||
</TouchableItem>
|
||||
);
|
||||
|
||||
@@ -5,12 +5,9 @@ import useLinkTo from './useLinkTo';
|
||||
type Props = {
|
||||
to: string;
|
||||
target?: string;
|
||||
onLink?: (
|
||||
e: React.MouseEvent<HTMLAnchorElement, MouseEvent> | GestureResponderEvent
|
||||
) => void;
|
||||
} & (TextProps & { children: React.ReactNode });
|
||||
|
||||
export default function Link({ to, children, onLink, ...rest }: Props) {
|
||||
export default function Link({ to, children, ...rest }: Props) {
|
||||
const linkTo = useLinkTo();
|
||||
|
||||
const onPress = (
|
||||
@@ -24,13 +21,13 @@ export default function Link({ to, children, onLink, ...rest }: Props) {
|
||||
let shouldHandle = false;
|
||||
|
||||
if (Platform.OS !== 'web' || !event) {
|
||||
shouldHandle = event ? !event.defaultPrevented : true;
|
||||
shouldHandle = event ? !e.defaultPrevented : true;
|
||||
} else if (
|
||||
!event.defaultPrevented && // onPress prevented default
|
||||
!e.defaultPrevented && // onPress prevented default
|
||||
// @ts-ignore
|
||||
!(event.metaKey || event.altKey || event.ctrlKey || event.shiftKey) && // ignore clicks with modifier keys
|
||||
!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey) && // ignore clicks with modifier keys
|
||||
// @ts-ignore
|
||||
(event.button == null || event.button === 0) && // ignore everything but left clicks
|
||||
(e.button == null || e.button === 0) && // ignore everything but left clicks
|
||||
(rest.target == null || rest.target === '_self') // let browser handle "target=_blank" etc.
|
||||
) {
|
||||
event.preventDefault();
|
||||
@@ -38,11 +35,7 @@ export default function Link({ to, children, onLink, ...rest }: Props) {
|
||||
}
|
||||
|
||||
if (shouldHandle) {
|
||||
if (onLink) {
|
||||
onLink(e);
|
||||
} else {
|
||||
linkTo(to);
|
||||
}
|
||||
linkTo(to);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user