Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 32 additions & 32 deletions packages/stack/src/common/types.ts
Original file line number Diff line number Diff line change
@@ -1,77 +1,77 @@
import { PlainObject, RoutePropBase, RouterBaseEventMap } from "@react-motion-router/core";
import { ScreenProps } from "../Screen";
import { RefObject } from "react";
import { BackEvent, ForwardEvent, GestureCancelEvent, GestureEndEvent, GestureStartEvent, NavigateEvent } from "./events";
import { PlainObject, RoutePropBase, RouterBaseEventMap } from '@react-motion-router/core';
import { ScreenProps } from '../Screen';
import { RefObject } from 'react';
import { BackEvent, ForwardEvent, GestureCancelEvent, GestureEndEvent, GestureStartEvent, NavigateEvent } from './events';

export interface NavigationBaseOptions {
signal?: AbortSignal;
}

export interface NavigateOptions extends NavigationBaseOptions {
type?: "push" | "replace";
type?: 'push' | 'replace';
}

export interface GoBackOptions extends NavigationBaseOptions { }
export interface GoForwardOptions extends NavigationBaseOptions { }

export interface NavigationProps {
params?: Record<any, any>;
config?: ScreenProps["config"]
config?: ScreenProps['config']
}

export type Without<T, U> = { [P in Exclude<keyof T, keyof U>]?: never };

export type XOR<T, U> = (T | U) extends object ? (Without<T, U> & U) | (Without<U, T> & T) : T | U;

export interface HistoryEntryState {
config?: ScreenProps["config"];
config?: ScreenProps['config'];
params?: PlainObject;
}

export function isRefObject<T>(value?: React.LegacyRef<T>): value is RefObject<T> {
if (
value !== null
if (
value !== null
&& typeof value === 'object'
&& value.hasOwnProperty('current')
) return true;
return false;
) return true;
return false;
}

export interface RouterEventMap extends RouterBaseEventMap {
"navigate": NavigateEvent;
"back": BackEvent;
"forward": ForwardEvent;
"gesture-start": GestureStartEvent;
"gesture-end": GestureEndEvent;
"gesture-cancel": GestureCancelEvent;
'navigate': NavigateEvent;
'back': BackEvent;
'forward': ForwardEvent;
'gesture-start': GestureStartEvent;
'gesture-end': GestureEndEvent;
'gesture-cancel': GestureCancelEvent;
}

export interface RouteProp<T extends PlainObject = {}> extends RoutePropBase<ScreenProps["config"], T> { }
export interface RouteProp<T extends PlainObject = {}> extends RoutePropBase<ScreenProps['config'], T> { }

export type SwipeDirection = 'up' | 'down' | 'left' | 'right' | 'horizontal' | 'vertical';
export type Direction = Exclude<SwipeDirection, "horizontal" | "vertical">;
export type Direction = Exclude<SwipeDirection, 'horizontal' | 'vertical'>;

const directions: Record<SwipeDirection, Direction[]> = {
"horizontal": ["left", "right"] as const,
"vertical": ["up", "down"] as const,
"up": ["up"] as const,
"down": ["down"] as const,
"left": ["left"] as const,
"right": ["right"] as const
'horizontal': ['left', 'right'] as const,
'vertical': ['up', 'down'] as const,
'up': ['up'] as const,
'down': ['down'] as const,
'left': ['left'] as const,
'right': ['right'] as const,
};
export function isSupportedDirection(direction: Exclude<SwipeDirection, "horizontal" | "vertical">, supported: SwipeDirection) {
return directions[supported].includes(direction);
export function isSupportedDirection(direction: Exclude<SwipeDirection, 'horizontal' | 'vertical'>, supported: SwipeDirection) {
return directions[supported].includes(direction);
}

export function isOutOfBounds(direction: SwipeDirection, { x, y }: { x: number, y: number }, clientRect: DOMRect, gestureAreaWidth: number) {
if (direction === "right" && Math.abs(x - clientRect.left) >= gestureAreaWidth) return false;
if (direction === "left" && Math.abs(x - clientRect.right) >= gestureAreaWidth) return false;
if (direction === "down" && Math.abs(y - clientRect.top) >= gestureAreaWidth) return false;
if (direction === "up" && Math.abs(y - clientRect.bottom) >= gestureAreaWidth) return false;
if (direction === 'right' && Math.abs(x - clientRect.left) >= gestureAreaWidth) return false;
if (direction === 'left' && Math.abs(x - clientRect.right) >= gestureAreaWidth) return false;
if (direction === 'down' && Math.abs(y - clientRect.top) >= gestureAreaWidth) return false;
if (direction === 'up' && Math.abs(y - clientRect.bottom) >= gestureAreaWidth) return false;
}

export function isHorizontalDirection(direction: SwipeDirection): direction is 'left' | 'right' | 'horizontal' {
return direction === 'left' || direction === 'right' || direction === 'horizontal';
return direction === 'left' || direction === 'right' || direction === 'horizontal';
}

export interface ScreenInternalProps {
Expand Down
1 change: 1 addition & 0 deletions packages/stack/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ export * from './animation-configs/keyframe-presets';
export * from './animation-configs/keyframe-options-presets';
export * from './animation-configs/animation-presets';
export * from './common/hooks';
export * from './common/types';
export * from './GestureRegion';
export * from './HistoryEntry';