@ionic/react-router 9.0.1-dev.11787177893.1979eb13 → 9.0.1-dev.11787589191.1e183b55
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +30 -7
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { useRef, useState, useEffect, useCallback } from 'react';
|
|
2
2
|
import { Route, matchPath as matchPath$1, Routes, Navigate, UNSAFE_RouteContext, matchRoutes, useLocation, useNavigate, BrowserRouter, useNavigationType, HashRouter } from 'react-router-dom';
|
|
3
|
-
import { IonRoute, ViewStacks, generateId, ViewLifeCycleManager, createDebugLogger, StackContext, RouteManagerContext, LocationHistory, NavManager
|
|
3
|
+
import { IonRoute, ViewStacks, generateId, ViewLifeCycleManager, createDebugLogger, StackContext, RouteManagerContext, getConfig, LocationHistory, NavManager } from '@ionic/react';
|
|
4
4
|
import { MemoryRouter, useLocation as useLocation$1, useNavigationType as useNavigationType$1 } from 'react-router';
|
|
5
5
|
|
|
6
6
|
const IonRouteInner = ({ path, index, caseSensitive, element }) => {
|
|
@@ -2577,8 +2577,31 @@ class StackManager extends React.PureComponent {
|
|
|
2577
2577
|
*/
|
|
2578
2578
|
async transitionPage(routeInfo, enteringViewItem, leavingViewItem, direction, progressAnimation = false, skipAnimation = false) {
|
|
2579
2579
|
const myGeneration = ++this.transitionGeneration;
|
|
2580
|
+
const routerOutlet = this.routerOutletElement;
|
|
2581
|
+
const routeInfoFallbackDirection = routeInfo.routeDirection === 'none' || routeInfo.routeDirection === 'root' ? undefined : routeInfo.routeDirection;
|
|
2582
|
+
const directionToUse = direction ?? routeInfoFallbackDirection;
|
|
2583
|
+
/**
|
|
2584
|
+
* The cases where we pass `commit()` a duration of 0. It's a function so each
|
|
2585
|
+
* caller reads `skipTransition` as of when it runs, since the swipe gesture can
|
|
2586
|
+
* set it after we get here.
|
|
2587
|
+
*/
|
|
2588
|
+
const isInstantCommit = () => this.skipTransition || skipAnimation || directionToUse === undefined;
|
|
2589
|
+
/**
|
|
2590
|
+
* Whether `commit()` will run an animation. Mirrors the check in core's
|
|
2591
|
+
* `router-outlet.tsx`, so keep the two in sync: an instant commit never
|
|
2592
|
+
* animates, and otherwise the outlet's `animated` prop and the global
|
|
2593
|
+
* `animated` config both have to allow it (`ionic:_testing` turns it off).
|
|
2594
|
+
*/
|
|
2595
|
+
const willCommitAnimate = () => {
|
|
2596
|
+
if (isInstantCommit()) {
|
|
2597
|
+
return false;
|
|
2598
|
+
}
|
|
2599
|
+
const config = getConfig();
|
|
2600
|
+
return !!routerOutlet.animated && (config ? config.getBoolean('animated', true) : true);
|
|
2601
|
+
};
|
|
2580
2602
|
const runCommit = async (enteringEl, leavingEl) => {
|
|
2581
2603
|
const skipTransition = this.skipTransition;
|
|
2604
|
+
const commitDuration = isInstantCommit() ? 0 : undefined;
|
|
2582
2605
|
/**
|
|
2583
2606
|
* If the transition was handled
|
|
2584
2607
|
* via the swipe to go back gesture,
|
|
@@ -2614,7 +2637,6 @@ class StackManager extends React.PureComponent {
|
|
|
2614
2637
|
enteringEl.classList.add('ion-page-invisible');
|
|
2615
2638
|
}
|
|
2616
2639
|
}
|
|
2617
|
-
const commitDuration = skipTransition || skipAnimation || directionToUse === undefined ? 0 : undefined;
|
|
2618
2640
|
// Race commit against a timeout to recover from hangs
|
|
2619
2641
|
const commitPromise = routerOutlet.commit(enteringEl, leavingEl, {
|
|
2620
2642
|
duration: commitDuration,
|
|
@@ -2646,15 +2668,12 @@ class StackManager extends React.PureComponent {
|
|
|
2646
2668
|
enteringEl.classList.remove('ion-page-invisible');
|
|
2647
2669
|
}
|
|
2648
2670
|
};
|
|
2649
|
-
const routerOutlet = this.routerOutletElement;
|
|
2650
|
-
const routeInfoFallbackDirection = routeInfo.routeDirection === 'none' || routeInfo.routeDirection === 'root' ? undefined : routeInfo.routeDirection;
|
|
2651
|
-
const directionToUse = direction ?? routeInfoFallbackDirection;
|
|
2652
2671
|
if (enteringViewItem && enteringViewItem.ionPageElement && this.routerOutletElement) {
|
|
2653
2672
|
this.transitionEnteringElement = enteringViewItem.ionPageElement;
|
|
2654
2673
|
if (leavingViewItem && leavingViewItem.ionPageElement && enteringViewItem === leavingViewItem) {
|
|
2655
2674
|
// Clone page for same-view transitions (e.g., /user/1 → /user/2)
|
|
2656
2675
|
const match = matchComponent(leavingViewItem.reactElement, routeInfo.pathname, undefined, this.outletMountPath);
|
|
2657
|
-
if (match) {
|
|
2676
|
+
if (match && willCommitAnimate()) {
|
|
2658
2677
|
const newLeavingElement = clonePageElement(leavingViewItem.ionPageElement.outerHTML);
|
|
2659
2678
|
if (newLeavingElement) {
|
|
2660
2679
|
this.routerOutletElement.appendChild(newLeavingElement);
|
|
@@ -2663,7 +2682,11 @@ class StackManager extends React.PureComponent {
|
|
|
2663
2682
|
}
|
|
2664
2683
|
}
|
|
2665
2684
|
else {
|
|
2666
|
-
|
|
2685
|
+
/**
|
|
2686
|
+
* Either the route no longer matches (e.g., /user/1 → /settings), or
|
|
2687
|
+
* nothing will animate, so the clone would duplicate the page in the
|
|
2688
|
+
* DOM for no benefit.
|
|
2689
|
+
*/
|
|
2667
2690
|
await runCommit(enteringViewItem.ionPageElement, undefined);
|
|
2668
2691
|
}
|
|
2669
2692
|
}
|