@rdlabo/ionic-theme-ios26 1.3.2 → 2.0.0
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/README.md +35 -55
- package/dist/css/components/ion-button.css +1 -1
- package/dist/css/components/ion-toolbar.css +1 -1
- package/dist/css/ionic-theme-ios26.css +1 -1
- package/dist/focus-controller /index.d.ts +6 -0
- package/dist/focus-controller /index.d.ts.map +1 -0
- package/dist/focus-controller /index.js +62 -0
- package/dist/popover/animations/ios.enter.js +1 -1
- package/dist/popover/utils.d.ts.map +1 -1
- package/dist/popover/utils.js +6 -0
- package/dist/sheets-of-glass/index.d.ts.map +1 -1
- package/dist/sheets-of-glass/index.js +6 -0
- package/dist/transition/index.d.ts +19 -0
- package/dist/transition/index.d.ts.map +1 -0
- package/dist/transition/index.js +219 -0
- package/dist/transition/ios.transition.d.ts +5 -0
- package/dist/transition/ios.transition.d.ts.map +1 -0
- package/dist/transition/ios.transition.js +496 -0
- package/dist/utils.d.ts +10 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +30 -0
- package/package.json +1 -1
- package/src/focus-controller /index.ts +123 -0
- package/src/popover/animations/ios.enter.ts +1 -1
- package/src/popover/utils.ts +6 -0
- package/src/sheets-of-glass/index.ts +8 -2
- package/src/styles/components/ion-button.scss +0 -4
- package/src/transition/index.ts +369 -0
- package/src/transition/ios.transition.ts +834 -0
- package/src/utils.ts +36 -0
- package/dist/gestures/animations.d.ts +0 -8
- package/dist/gestures/animations.d.ts.map +0 -1
- package/dist/gestures/animations.js +0 -97
- package/dist/gestures/gestures.d.ts +0 -3
- package/dist/gestures/gestures.d.ts.map +0 -1
- package/dist/gestures/gestures.js +0 -240
- package/dist/gestures/index.d.ts +0 -3
- package/dist/gestures/index.d.ts.map +0 -1
- package/dist/gestures/index.js +0 -160
- package/dist/gestures/interfaces.d.ts +0 -16
- package/dist/gestures/interfaces.d.ts.map +0 -1
- package/dist/gestures/interfaces.js +0 -1
- package/dist/gestures/utils.d.ts +0 -5
- package/dist/gestures/utils.d.ts.map +0 -1
- package/dist/gestures/utils.js +0 -27
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { config } from '../utils';
|
|
2
|
+
// import { printIonWarning} from '@ionic/core/dist/types/utils/logging';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Moves focus to a specified element. Note that we do not remove the tabindex
|
|
6
|
+
* because that can result in an unintentional blur. Non-focusables can't be
|
|
7
|
+
* focused, so the body will get focused again.
|
|
8
|
+
*/
|
|
9
|
+
const moveFocus = (el: HTMLElement) => {
|
|
10
|
+
el.tabIndex = -1;
|
|
11
|
+
el.focus();
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Elements that are hidden using `display: none` should not be focused even if
|
|
16
|
+
* they are present in the DOM.
|
|
17
|
+
*/
|
|
18
|
+
const isVisible = (el: HTMLElement) => {
|
|
19
|
+
return el.offsetParent !== null;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The focus controller allows us to manage focus within a view so assistive
|
|
24
|
+
* technologies can inform users of changes to the navigation state. Traditional
|
|
25
|
+
* native apps have a way of informing assistive technology about a navigation
|
|
26
|
+
* state change. Mobile browsers have this too, but only when doing a full page
|
|
27
|
+
* load. In a single page app we do not do that, so we need to build this
|
|
28
|
+
* integration ourselves.
|
|
29
|
+
*/
|
|
30
|
+
export const createFocusController = (): FocusController => {
|
|
31
|
+
const saveViewFocus = (referenceEl?: HTMLElement) => {
|
|
32
|
+
const focusManagerEnabled = config.get('focusManagerPriority', false);
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* When going back to a previously visited page focus should typically be moved
|
|
36
|
+
* back to the element that was last focused when the user was on this view.
|
|
37
|
+
*/
|
|
38
|
+
if (focusManagerEnabled) {
|
|
39
|
+
const activeEl = document.activeElement;
|
|
40
|
+
if (activeEl !== null && referenceEl?.contains(activeEl)) {
|
|
41
|
+
activeEl.setAttribute(LAST_FOCUS, 'true');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const setViewFocus = (referenceEl: HTMLElement) => {
|
|
47
|
+
const focusManagerPriorities = config.get('focusManagerPriority', false);
|
|
48
|
+
/**
|
|
49
|
+
* If the focused element is a descendant of the referenceEl then it's possible
|
|
50
|
+
* that the app developer manually moved focus, so we do not want to override that.
|
|
51
|
+
* This can happen with inputs the are focused when a view transitions in.
|
|
52
|
+
*/
|
|
53
|
+
if (Array.isArray(focusManagerPriorities) && !referenceEl.contains(document.activeElement)) {
|
|
54
|
+
/**
|
|
55
|
+
* When going back to a previously visited view focus should always be moved back
|
|
56
|
+
* to the element that the user was last focused on when they were on this view.
|
|
57
|
+
*/
|
|
58
|
+
const lastFocus = referenceEl.querySelector<HTMLElement>(`[${LAST_FOCUS}]`);
|
|
59
|
+
if (lastFocus && isVisible(lastFocus)) {
|
|
60
|
+
moveFocus(lastFocus);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
for (const priority of focusManagerPriorities) {
|
|
65
|
+
/**
|
|
66
|
+
* For each recognized case (excluding the default case) make sure to return
|
|
67
|
+
* so that the fallback focus behavior does not run.
|
|
68
|
+
*
|
|
69
|
+
* We intentionally query for specific roles/semantic elements so that the
|
|
70
|
+
* transition manager can work with both Ionic and non-Ionic UI components.
|
|
71
|
+
*
|
|
72
|
+
* If new selectors are added, be sure to remove the outline ring by adding
|
|
73
|
+
* new selectors to rule in core.scss.
|
|
74
|
+
*/
|
|
75
|
+
switch (priority) {
|
|
76
|
+
case 'content':
|
|
77
|
+
const content = referenceEl.querySelector<HTMLElement>('main, [role="main"]');
|
|
78
|
+
if (content && isVisible(content)) {
|
|
79
|
+
moveFocus(content);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
break;
|
|
83
|
+
case 'heading':
|
|
84
|
+
const headingOne = referenceEl.querySelector<HTMLElement>('h1, [role="heading"][aria-level="1"]');
|
|
85
|
+
if (headingOne && isVisible(headingOne)) {
|
|
86
|
+
moveFocus(headingOne);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
break;
|
|
90
|
+
case 'banner':
|
|
91
|
+
const header = referenceEl.querySelector<HTMLElement>('header, [role="banner"]');
|
|
92
|
+
if (header && isVisible(header)) {
|
|
93
|
+
moveFocus(header);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
break;
|
|
97
|
+
default:
|
|
98
|
+
// printIonWarning(`Unrecognized focus manager priority value ${priority}`);
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* If there is nothing to focus then focus the page so focus at least moves to
|
|
105
|
+
* the correct view. The browser will then determine where within the page to
|
|
106
|
+
* move focus to.
|
|
107
|
+
*/
|
|
108
|
+
moveFocus(referenceEl);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
return {
|
|
113
|
+
saveViewFocus,
|
|
114
|
+
setViewFocus,
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export type FocusController = {
|
|
119
|
+
saveViewFocus: (referenceEl?: HTMLElement) => void;
|
|
120
|
+
setViewFocus: (referenceEl: HTMLElement) => void;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const LAST_FOCUS = 'ion-last-focus';
|
|
@@ -43,7 +43,7 @@ export const iosEnterAnimation = (baseEl: HTMLElement, opts?: any): Animation =>
|
|
|
43
43
|
const results = getPopoverPosition(isRTL, contentWidth, contentHeight, reference, side, align, defaultPosition, trigger, ev);
|
|
44
44
|
|
|
45
45
|
const padding = size === 'cover' ? 0 : POPOVER_IOS_BODY_PADDING;
|
|
46
|
-
const margin = size === 'cover' ? 0 :
|
|
46
|
+
const margin = size === 'cover' ? 0 : POPOVER_IOS_BODY_MARGIN;
|
|
47
47
|
|
|
48
48
|
const { originX, originY, top, left, bottom, checkSafeAreaLeft, checkSafeAreaRight, addPopoverBottomClass } = calculateWindowAdjustment(
|
|
49
49
|
side,
|
package/src/popover/utils.ts
CHANGED
|
@@ -628,6 +628,9 @@ export const calculateWindowAdjustment = (
|
|
|
628
628
|
*/
|
|
629
629
|
if (left < bodyPadding + safeAreaMargin) {
|
|
630
630
|
left = !eventElementRect ? bodyPadding : eventElementRect.left;
|
|
631
|
+
if (left === 0) {
|
|
632
|
+
left = safeAreaMargin;
|
|
633
|
+
}
|
|
631
634
|
checkSafeAreaLeft = true;
|
|
632
635
|
originX = 'left';
|
|
633
636
|
/**
|
|
@@ -637,6 +640,9 @@ export const calculateWindowAdjustment = (
|
|
|
637
640
|
} else if (contentWidth + bodyPadding + left + safeAreaMargin > bodyWidth) {
|
|
638
641
|
checkSafeAreaRight = true;
|
|
639
642
|
left = !eventElementRect ? bodyWidth - contentWidth - bodyPadding : eventElementRect.right - contentWidth;
|
|
643
|
+
if (left + contentWidth === bodyWidth) {
|
|
644
|
+
left = left - safeAreaMargin;
|
|
645
|
+
}
|
|
640
646
|
originX = 'right';
|
|
641
647
|
}
|
|
642
648
|
|
|
@@ -103,10 +103,13 @@ export const registerEffect = (
|
|
|
103
103
|
}
|
|
104
104
|
})();
|
|
105
105
|
startAnimationPromise.then(() => {
|
|
106
|
+
if (!currentTouchedElement) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
106
109
|
moveAnimation = createMoveAnimation(effectElement, detail, tabSelectedElement, animationPosition!);
|
|
107
110
|
moveAnimation.progressStart(
|
|
108
111
|
true,
|
|
109
|
-
getStep(currentTouchedElement
|
|
112
|
+
getStep(currentTouchedElement.getBoundingClientRect().left + currentTouchedElement.clientWidth / 2, animationPosition!),
|
|
110
113
|
);
|
|
111
114
|
});
|
|
112
115
|
getScaleAnimation(effectElement).duration(200).to('opacity', 1).to('transform', scales.large).play();
|
|
@@ -167,7 +170,10 @@ export const registerEffect = (
|
|
|
167
170
|
}
|
|
168
171
|
|
|
169
172
|
setTimeout(() => {
|
|
170
|
-
|
|
173
|
+
if (!currentTouchedElement) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
const targetX = currentTouchedElement.getBoundingClientRect().left + currentTouchedElement.clientWidth / 2;
|
|
171
177
|
const step = getStep(targetX, animationPosition!);
|
|
172
178
|
moveAnimation!.progressStep(step);
|
|
173
179
|
});
|
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
import { config } from '../utils';
|
|
2
|
+
import { Build, writeTask } from '@stencil/core';
|
|
3
|
+
|
|
4
|
+
import { LIFECYCLE_DID_ENTER, LIFECYCLE_DID_LEAVE, LIFECYCLE_WILL_ENTER, LIFECYCLE_WILL_LEAVE } from '@ionic/core';
|
|
5
|
+
import type { NavOptions, NavDirection } from '@ionic/core';
|
|
6
|
+
import type { Animation, AnimationBuilder } from '@ionic/core';
|
|
7
|
+
import { createFocusController } from '../focus-controller ';
|
|
8
|
+
import { raf } from '../utils';
|
|
9
|
+
|
|
10
|
+
const iosTransitionAnimation = () => import('./ios.transition');
|
|
11
|
+
// const mdTransitionAnimation = () => import('./md.transition');
|
|
12
|
+
const focusController = createFocusController();
|
|
13
|
+
|
|
14
|
+
// TODO(FW-2832): types
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Executes the main page transition.
|
|
18
|
+
* It also manages the lifecycle of header visibility (if any)
|
|
19
|
+
* to prevent visual flickering in iOS. The flickering only
|
|
20
|
+
* occurs for a condensed header that is placed above the content.
|
|
21
|
+
*
|
|
22
|
+
* @param opts Options for the transition.
|
|
23
|
+
* @returns A promise that resolves when the transition is complete.
|
|
24
|
+
*/
|
|
25
|
+
export const transition = (opts: TransitionOptions): Promise<TransitionResult> => {
|
|
26
|
+
return new Promise((resolve, reject) => {
|
|
27
|
+
writeTask(() => {
|
|
28
|
+
const transitioningInactiveHeader = getIosIonHeader(opts);
|
|
29
|
+
beforeTransition(opts, transitioningInactiveHeader);
|
|
30
|
+
runTransition(opts)
|
|
31
|
+
.then(
|
|
32
|
+
(result) => {
|
|
33
|
+
if (result.animation) {
|
|
34
|
+
result.animation.destroy();
|
|
35
|
+
}
|
|
36
|
+
afterTransition(opts);
|
|
37
|
+
resolve(result);
|
|
38
|
+
},
|
|
39
|
+
(error) => {
|
|
40
|
+
afterTransition(opts);
|
|
41
|
+
reject(error);
|
|
42
|
+
},
|
|
43
|
+
)
|
|
44
|
+
.finally(() => {
|
|
45
|
+
// Ensure that the header is restored to its original state.
|
|
46
|
+
setHeaderTransitionClass(transitioningInactiveHeader, false);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const beforeTransition = (opts: TransitionOptions, transitioningInactiveHeader: HTMLElement | null) => {
|
|
53
|
+
const enteringEl = opts.enteringEl;
|
|
54
|
+
const leavingEl = opts.leavingEl;
|
|
55
|
+
|
|
56
|
+
focusController.saveViewFocus(leavingEl);
|
|
57
|
+
|
|
58
|
+
setZIndex(enteringEl, leavingEl, opts.direction);
|
|
59
|
+
// Prevent flickering of the header by adding a class.
|
|
60
|
+
setHeaderTransitionClass(transitioningInactiveHeader, true);
|
|
61
|
+
|
|
62
|
+
if (opts.showGoBack) {
|
|
63
|
+
enteringEl.classList.add('can-go-back');
|
|
64
|
+
} else {
|
|
65
|
+
enteringEl.classList.remove('can-go-back');
|
|
66
|
+
}
|
|
67
|
+
setPageHidden(enteringEl, false);
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* When transitioning, the page should not
|
|
71
|
+
* respond to click events. This resolves small
|
|
72
|
+
* issues like users double tapping the ion-back-button.
|
|
73
|
+
* These pointer events are removed in `afterTransition`.
|
|
74
|
+
*/
|
|
75
|
+
enteringEl.style.setProperty('pointer-events', 'none');
|
|
76
|
+
|
|
77
|
+
if (leavingEl) {
|
|
78
|
+
setPageHidden(leavingEl, false);
|
|
79
|
+
leavingEl.style.setProperty('pointer-events', 'none');
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const runTransition = async (opts: TransitionOptions): Promise<TransitionResult> => {
|
|
84
|
+
const animationBuilder = await getAnimationBuilder(opts);
|
|
85
|
+
|
|
86
|
+
const ani = animationBuilder && Build.isBrowser ? animation(animationBuilder, opts) : noAnimation(opts); // fast path for no animation
|
|
87
|
+
|
|
88
|
+
return ani;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const afterTransition = (opts: TransitionOptions) => {
|
|
92
|
+
const enteringEl = opts.enteringEl;
|
|
93
|
+
const leavingEl = opts.leavingEl;
|
|
94
|
+
enteringEl.classList.remove('ion-page-invisible');
|
|
95
|
+
enteringEl.style.removeProperty('pointer-events');
|
|
96
|
+
if (leavingEl !== undefined) {
|
|
97
|
+
leavingEl.classList.remove('ion-page-invisible');
|
|
98
|
+
leavingEl.style.removeProperty('pointer-events');
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
focusController.setViewFocus(enteringEl);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const getAnimationBuilder = async (opts: TransitionOptions): Promise<AnimationBuilder | undefined> => {
|
|
105
|
+
if (!opts.leavingEl || !opts.animated || opts.duration === 0) {
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (opts.animationBuilder) {
|
|
110
|
+
return opts.animationBuilder;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const getAnimation =
|
|
114
|
+
// opts.mode === 'ios'
|
|
115
|
+
(await iosTransitionAnimation()).iosTransitionAnimation;
|
|
116
|
+
// : (await mdTransitionAnimation()).mdTransitionAnimation;
|
|
117
|
+
|
|
118
|
+
return getAnimation;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const animation = async (animationBuilder: AnimationBuilder, opts: TransitionOptions): Promise<TransitionResult> => {
|
|
122
|
+
await waitForReady(opts, true);
|
|
123
|
+
|
|
124
|
+
const trans = animationBuilder(opts.baseEl, opts);
|
|
125
|
+
|
|
126
|
+
fireWillEvents(opts.enteringEl, opts.leavingEl);
|
|
127
|
+
|
|
128
|
+
const didComplete = await playTransition(trans, opts);
|
|
129
|
+
|
|
130
|
+
if (opts.progressCallback) {
|
|
131
|
+
opts.progressCallback(undefined);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (didComplete) {
|
|
135
|
+
fireDidEvents(opts.enteringEl, opts.leavingEl);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return {
|
|
139
|
+
hasCompleted: didComplete,
|
|
140
|
+
animation: trans,
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
const noAnimation = async (opts: TransitionOptions): Promise<TransitionResult> => {
|
|
145
|
+
const enteringEl = opts.enteringEl;
|
|
146
|
+
const leavingEl = opts.leavingEl;
|
|
147
|
+
const focusManagerEnabled = config.get('focusManagerPriority', false);
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* If the focus manager is enabled then we need to wait for Ionic components to be
|
|
151
|
+
* rendered otherwise the component to focus may not be focused because it is hidden.
|
|
152
|
+
*/
|
|
153
|
+
await waitForReady(opts, focusManagerEnabled);
|
|
154
|
+
|
|
155
|
+
fireWillEvents(enteringEl, leavingEl);
|
|
156
|
+
fireDidEvents(enteringEl, leavingEl);
|
|
157
|
+
|
|
158
|
+
return {
|
|
159
|
+
hasCompleted: true,
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
const waitForReady = async (opts: TransitionOptions, defaultDeep: boolean) => {
|
|
164
|
+
const deep = opts.deepWait !== undefined ? opts.deepWait : defaultDeep;
|
|
165
|
+
|
|
166
|
+
if (deep) {
|
|
167
|
+
await Promise.all([deepReady(opts.enteringEl), deepReady(opts.leavingEl)]);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
await notifyViewReady(opts.viewIsReady, opts.enteringEl);
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
const notifyViewReady = async (viewIsReady: undefined | ((enteringEl: HTMLElement) => Promise<any>), enteringEl: HTMLElement) => {
|
|
174
|
+
if (viewIsReady) {
|
|
175
|
+
await viewIsReady(enteringEl);
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
const playTransition = (trans: Animation, opts: TransitionOptions): Promise<boolean> => {
|
|
180
|
+
const progressCallback = opts.progressCallback;
|
|
181
|
+
|
|
182
|
+
const promise = new Promise<boolean>((resolve) => {
|
|
183
|
+
trans.onFinish((currentStep: any) => resolve(currentStep === 1));
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
// cool, let's do this, start the transition
|
|
187
|
+
if (progressCallback) {
|
|
188
|
+
// this is a swipe to go back, just get the transition progress ready
|
|
189
|
+
// kick off the swipe animation start
|
|
190
|
+
trans.progressStart(true);
|
|
191
|
+
progressCallback(trans);
|
|
192
|
+
} else {
|
|
193
|
+
// only the top level transition should actually start "play"
|
|
194
|
+
// kick it off and let it play through
|
|
195
|
+
// ******** DOM WRITE ****************
|
|
196
|
+
trans.play();
|
|
197
|
+
}
|
|
198
|
+
// create a callback for when the animation is done
|
|
199
|
+
return promise;
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
const fireWillEvents = (enteringEl: HTMLElement | undefined, leavingEl: HTMLElement | undefined) => {
|
|
203
|
+
lifecycle(leavingEl, LIFECYCLE_WILL_LEAVE);
|
|
204
|
+
lifecycle(enteringEl, LIFECYCLE_WILL_ENTER);
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
const fireDidEvents = (enteringEl: HTMLElement | undefined, leavingEl: HTMLElement | undefined) => {
|
|
208
|
+
lifecycle(enteringEl, LIFECYCLE_DID_ENTER);
|
|
209
|
+
lifecycle(leavingEl, LIFECYCLE_DID_LEAVE);
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
export const lifecycle = (el: HTMLElement | undefined, eventName: string) => {
|
|
213
|
+
if (el) {
|
|
214
|
+
const ev = new CustomEvent(eventName, {
|
|
215
|
+
bubbles: false,
|
|
216
|
+
cancelable: false,
|
|
217
|
+
});
|
|
218
|
+
el.dispatchEvent(ev);
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Wait two request animation frame loops.
|
|
224
|
+
* This allows the framework implementations enough time to mount
|
|
225
|
+
* the user-defined contents. This is often needed when using inline
|
|
226
|
+
* modals and popovers that accept user components. For popover,
|
|
227
|
+
* the contents must be mounted for the popover to be sized correctly.
|
|
228
|
+
* For modals, the contents must be mounted for iOS to run the
|
|
229
|
+
* transition correctly.
|
|
230
|
+
*
|
|
231
|
+
* On Angular and React, a single raf is enough time, but for Vue
|
|
232
|
+
* we need to wait two rafs. As a result we are using two rafs for
|
|
233
|
+
* all frameworks to ensure contents are mounted.
|
|
234
|
+
*/
|
|
235
|
+
export const waitForMount = (): Promise<void> => {
|
|
236
|
+
return new Promise((resolve) => raf(() => raf(() => resolve())));
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
export const deepReady = async (el: any | undefined): Promise<void> => {
|
|
240
|
+
const element = el as any;
|
|
241
|
+
if (element) {
|
|
242
|
+
if (element.componentOnReady != null) {
|
|
243
|
+
// eslint-disable-next-line custom-rules/no-component-on-ready-method
|
|
244
|
+
const stencilEl = await element.componentOnReady();
|
|
245
|
+
if (stencilEl != null) {
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Custom elements in Stencil will have __registerHost.
|
|
251
|
+
*/
|
|
252
|
+
} else if (element.__registerHost != null) {
|
|
253
|
+
/**
|
|
254
|
+
* Non-lazy loaded custom elements need to wait
|
|
255
|
+
* one frame for component to be loaded.
|
|
256
|
+
*/
|
|
257
|
+
const waitForCustomElement = new Promise((resolve) => raf(resolve));
|
|
258
|
+
await waitForCustomElement;
|
|
259
|
+
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
await Promise.all(Array.from(element.children).map(deepReady));
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
export const setPageHidden = (el: HTMLElement, hidden: boolean) => {
|
|
267
|
+
if (hidden) {
|
|
268
|
+
el.setAttribute('aria-hidden', 'true');
|
|
269
|
+
el.classList.add('ion-page-hidden');
|
|
270
|
+
} else {
|
|
271
|
+
el.hidden = false;
|
|
272
|
+
el.removeAttribute('aria-hidden');
|
|
273
|
+
el.classList.remove('ion-page-hidden');
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
const setZIndex = (enteringEl: HTMLElement | undefined, leavingEl: HTMLElement | undefined, direction: NavDirection | undefined) => {
|
|
278
|
+
if (enteringEl !== undefined) {
|
|
279
|
+
enteringEl.style.zIndex = direction === 'back' ? '99' : '101';
|
|
280
|
+
}
|
|
281
|
+
if (leavingEl !== undefined) {
|
|
282
|
+
leavingEl.style.zIndex = '100';
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Add a class to ensure that the header (if any)
|
|
288
|
+
* does not flicker during the transition. By adding the
|
|
289
|
+
* transitioning class, we ensure that the header has
|
|
290
|
+
* the necessary styles to prevent the following flickers:
|
|
291
|
+
* 1. When entering a page with a condensed header, the
|
|
292
|
+
* header should never be visible. However,
|
|
293
|
+
* it briefly renders the background color while
|
|
294
|
+
* the transition is occurring.
|
|
295
|
+
* 2. When leaving a page with a condensed header, the
|
|
296
|
+
* header has an opacity of 0 and the pages
|
|
297
|
+
* have a z-index which causes the entering page to
|
|
298
|
+
* briefly show it's content underneath the leaving page.
|
|
299
|
+
* 3. When entering a page or leaving a page with a fade
|
|
300
|
+
* header, the header should not have a background color.
|
|
301
|
+
* However, it briefly shows the background color while
|
|
302
|
+
* the transition is occurring.
|
|
303
|
+
*
|
|
304
|
+
* @param header The header element to modify.
|
|
305
|
+
* @param isTransitioning Whether the transition is occurring.
|
|
306
|
+
*/
|
|
307
|
+
const setHeaderTransitionClass = (header: HTMLElement | null, isTransitioning: boolean) => {
|
|
308
|
+
if (!header) {
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
const transitionClass = 'header-transitioning';
|
|
313
|
+
if (isTransitioning) {
|
|
314
|
+
header.classList.add(transitionClass);
|
|
315
|
+
} else {
|
|
316
|
+
header.classList.remove(transitionClass);
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
export const getIonPageElement = (element: HTMLElement) => {
|
|
321
|
+
if (element.classList.contains('ion-page')) {
|
|
322
|
+
return element;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
const ionPage = element.querySelector(':scope > .ion-page, :scope > ion-nav, :scope > ion-tabs');
|
|
326
|
+
if (ionPage) {
|
|
327
|
+
return ionPage;
|
|
328
|
+
}
|
|
329
|
+
// idk, return the original element so at least something animates and we don't have a null pointer
|
|
330
|
+
return element;
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* Retrieves the ion-header element from a page based on the
|
|
335
|
+
* direction of the transition.
|
|
336
|
+
*
|
|
337
|
+
* @param opts Options for the transition.
|
|
338
|
+
* @returns The ion-header element or null if not found or not in 'ios' mode.
|
|
339
|
+
*/
|
|
340
|
+
const getIosIonHeader = (opts: TransitionOptions): HTMLElement | null => {
|
|
341
|
+
const enteringEl = opts.enteringEl;
|
|
342
|
+
const leavingEl = opts.leavingEl;
|
|
343
|
+
const direction = opts.direction;
|
|
344
|
+
const mode = opts.mode;
|
|
345
|
+
|
|
346
|
+
if (mode !== 'ios') {
|
|
347
|
+
return null;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
const element = direction === 'back' ? leavingEl : enteringEl;
|
|
351
|
+
|
|
352
|
+
if (!element) {
|
|
353
|
+
return null;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
return element.querySelector('ion-header');
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
export interface TransitionOptions extends NavOptions {
|
|
360
|
+
progressCallback?: (ani: Animation | undefined) => void;
|
|
361
|
+
baseEl: any;
|
|
362
|
+
enteringEl: HTMLElement;
|
|
363
|
+
leavingEl: HTMLElement | undefined;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
export interface TransitionResult {
|
|
367
|
+
hasCompleted: boolean;
|
|
368
|
+
animation?: Animation;
|
|
369
|
+
}
|