UNPKG

9.45 kBTypeScriptView Raw
1import type { Transition, TransitionNavigationType, SharedTransitionTagPropertiesToMatch } from '.';
2import { Observable } from '../../data/observable';
3import { ViewBase } from '../core/view-base';
4import type { View } from '../core/view';
5import type { PanGestureEventData } from '../gestures';
6export declare enum SharedTransitionAnimationType {
7 present = 0,
8 dismiss = 1
9}
10type SharedTransitionEventAction = 'present' | 'dismiss' | 'interactiveStart' | 'interactiveFinish';
11export type SharedTransitionEventDataPayload = {
12 id: number;
13 type: TransitionNavigationType;
14 action?: SharedTransitionEventAction;
15 percent?: number;
16};
17export type SharedTransitionEventData = {
18 eventName: string;
19 data: SharedTransitionEventDataPayload;
20};
21export type SharedRect = {
22 x?: number;
23 y?: number;
24 width?: number;
25 height?: number;
26};
27export type SharedProperties = SharedRect & {
28 opacity?: number;
29 scale?: {
30 x?: number;
31 y?: number;
32 };
33};
34/**
35 * Properties which can be set on individual Shared Elements
36 */
37export type SharedTransitionTagProperties = SharedProperties & {
38 /**
39 * The visual stacking order where 0 is at the bottom.
40 * Shared elements are stacked one on top of the other during each transition.
41 * By default they are not ordered in any particular fashion.
42 */
43 zIndex?: number;
44 /**
45 * Collection of properties to match and animate on each shared element.
46 *
47 * Defaults to: 'backgroundColor', 'cornerRadius', 'borderWidth', 'borderColor'
48 *
49 * Tip: Using an empty array, [], for view or layer will avoid copying any properties if desired.
50 */
51 propertiesToMatch?: SharedTransitionTagPropertiesToMatch;
52 /**
53 *
54 */
55 callback?: (view: View, action: SharedTransitionEventAction) => Promise<void>;
56};
57export type SharedSpringProperties = {
58 tension?: number;
59 friction?: number;
60 mass?: number;
61 delay?: number;
62 velocity?: number;
63 animateOptions?: any;
64};
65type SharedTransitionPageProperties = SharedProperties & {
66 /**
67 * (iOS Only) Allow "independent" elements found only on one of the screens to take part in the animation.
68 * Note: This feature will be brought to Android in a future release.
69 */
70 sharedTransitionTags?: {
71 [key: string]: SharedTransitionTagProperties;
72 };
73 /**
74 * Spring animation settings.
75 * Defaults to 140 tension with 10 friction.
76 */
77 spring?: SharedSpringProperties;
78};
79type SharedTransitionPageWithDurationProperties = SharedTransitionPageProperties & {
80 /**
81 * Linear duration in milliseconds
82 * Note: When this is defined, it will override spring options and use only linear animation.
83 */
84 duration?: number | undefined | null;
85};
86export interface SharedTransitionInteractiveOptions {
87 /**
88 * When the pan exceeds this percentage and you let go, finish the transition.
89 * Default 0.5
90 */
91 finishThreshold?: number;
92 /**
93 * You can create your own percent formula used for determing the interactive value.
94 * By default, we handle this via a formula like this for an interactive page back transition:
95 * - return eventData.deltaX / (eventData.ios.view.bounds.size.width / 2);
96 * @param eventData PanGestureEventData
97 * @returns The percentage value to be used as the finish/cancel threshold
98 */
99 percentFormula?: (eventData: PanGestureEventData) => number;
100}
101export interface SharedTransitionConfig {
102 /**
103 * Interactive transition settings. (iOS only at the moment)
104 */
105 interactive?: {
106 /**
107 * Whether you want to allow interactive dismissal.
108 * Defaults to using 'pan' gesture for dismissal however you can customize your own.
109 */
110 dismiss?: SharedTransitionInteractiveOptions;
111 };
112 /**
113 * View settings applied to the incoming page to start your transition with.
114 */
115 pageStart?: SharedTransitionPageProperties;
116 /**
117 * View settings applied to the incoming page to end your transition with.
118 */
119 pageEnd?: SharedTransitionPageWithDurationProperties;
120 /**
121 * View settings applied to the outgoing page in your transition.
122 */
123 pageOut?: SharedTransitionPageWithDurationProperties;
124 /**
125 * View settings to return to the original page with.
126 */
127 pageReturn?: SharedTransitionPageWithDurationProperties & {
128 /**
129 * In some cases you may want the returning animation to start with the original opacity,
130 * instead of beginning where it ended up on pageEnd.
131 * Note: you can try enabling this property in cases where your return animation doesn't appear correct.
132 */
133 useStartOpacity?: boolean;
134 };
135}
136export interface SharedTransitionState extends SharedTransitionConfig {
137 /**
138 * (Internally used) Preconfigured transition or your own custom configured one.
139 */
140 instance?: Transition;
141 /**
142 * Page which will start the transition.
143 */
144 page?: ViewBase;
145 activeType?: SharedTransitionAnimationType;
146 toPage?: ViewBase;
147 /**
148 * Whether interactive transition has began.
149 */
150 interactiveBegan?: boolean;
151 /**
152 * Whether interactive transition was cancelled.
153 */
154 interactiveCancelled?: boolean;
155}
156declare class SharedTransitionObservable extends Observable {
157 on(eventNames: string, callback: (data: SharedTransitionEventData) => void, thisArg?: any): void;
158}
159/**
160 * Shared Element Transitions (preview)
161 * Allows you to auto animate between shared elements on two different screesn to create smooth navigational experiences.
162 * View components can define sharedTransitionTag="name" alone with a transition through this API.
163 */
164export declare class SharedTransition {
165 /**
166 * Configure a custom transition with presentation/dismissal options.
167 * @param transition The custom Transition instance.
168 * @param options
169 * @returns a configured SharedTransition instance for use with navigational APIs.
170 */
171 static custom(transition: Transition, options?: SharedTransitionConfig): {
172 instance: Transition;
173 };
174 /**
175 * Whether a transition is in progress or not.
176 * Note: used internally however exposed in case custom state ordering is needed.
177 * Updated when transitions start/end/cancel.
178 */
179 static inProgress: boolean;
180 /**
181 * Listen to various shared element transition events.
182 * @returns Observable
183 */
184 static events(): SharedTransitionObservable;
185 /**
186 * When the transition starts.
187 */
188 static startedEvent: string;
189 /**
190 * When the transition finishes.
191 */
192 static finishedEvent: string;
193 /**
194 * When the interactive transition cancels.
195 */
196 static interactiveCancelledEvent: string;
197 /**
198 * When the interactive transition updates with the percent value.
199 */
200 static interactiveUpdateEvent: string;
201 /**
202 * Notify a Shared Transition event.
203 * @param id transition instance id
204 * @param eventName Shared Transition event name
205 * @param type TransitionNavigationType
206 * @param action SharedTransitionEventAction
207 */
208 static notifyEvent(eventName: string, data: SharedTransitionEventDataPayload): void;
209 /**
210 * Enable to see various console logging output of Shared Element Transition behavior.
211 */
212 static DEBUG: boolean;
213 /**
214 * Update transition state.
215 * @param id Transition instance id
216 * @param state SharedTransitionState
217 */
218 static updateState(id: number, state: SharedTransitionState): void;
219 /**
220 * Get current state for any transition.
221 * @param id Transition instance id
222 */
223 static getState(id: number): SharedTransitionState;
224 /**
225 * Finish transition state.
226 * @param id Transition instance id
227 */
228 static finishState(id: number): void;
229 /**
230 * Gather view collections based on sharedTransitionTag details.
231 * @param fromPage Page moving away from
232 * @param toPage Page moving to
233 * @returns Collections of views pertaining to shared elements or particular pages
234 */
235 static getSharedElements(fromPage: ViewBase, toPage: ViewBase): {
236 sharedElements: Array<View>;
237 presented: Array<View>;
238 presenting: Array<View>;
239 };
240}
241/**
242 * Get dimensional rectangle (x,y,width,height) from properties with fallbacks for any undefined values.
243 * @param props combination of properties conformed to SharedTransitionPageProperties
244 * @param defaults fallback properties when props doesn't contain a value for it
245 * @returns { x,y,width,height }
246 */
247export declare function getRectFromProps(props: SharedTransitionPageProperties, defaults?: SharedRect): SharedRect;
248/**
249 * Get spring properties with default fallbacks for any undefined values.
250 * @param props various spring related properties conforming to SharedSpringProperties
251 * @returns
252 */
253export declare function getSpringFromProps(props: SharedSpringProperties): {
254 tension: number;
255 friction: number;
256 mass: number;
257 velocity: number;
258 delay: number;
259};
260/**
261 * Page starting defaults for provided type.
262 * @param type TransitionNavigationType
263 * @returns { x,y,width,height }
264 */
265export declare function getPageStartDefaultsForType(type: TransitionNavigationType): {
266 x: number;
267 y: number;
268 width: number;
269 height: number;
270};
271export {};