mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
feat(transitions): support zIndex on ios shared elements + support page props on android (#10261)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { PageTransition, SharedTransition, SharedTransitionHelper, Transition } from '@nativescript/core';
|
||||
import { PageTransition, SharedTransition, SharedTransitionAnimationType, SharedTransitionHelper, Transition, Utils } from '@nativescript/core';
|
||||
import { CORE_ANIMATION_DEFAULTS } from '@nativescript/core/utils';
|
||||
|
||||
export class CustomTransition extends Transition {
|
||||
constructor(duration: number, curve: any) {
|
||||
@@ -72,9 +73,24 @@ class PageTransitionController extends NSObject implements UIViewControllerAnima
|
||||
transitionDuration(transitionContext: UIViewControllerContextTransitioning): number {
|
||||
const owner = this.owner.deref();
|
||||
if (owner) {
|
||||
return owner.getDuration();
|
||||
const state = SharedTransition.getState(owner.id);
|
||||
switch (state?.activeType) {
|
||||
case SharedTransitionAnimationType.present:
|
||||
if (Utils.isNumber(state?.pageEnd?.duration)) {
|
||||
return state.pageEnd?.duration / 1000;
|
||||
} else {
|
||||
return Utils.getDurationWithDampingFromSpring(state.pageEnd?.spring).duration;
|
||||
}
|
||||
|
||||
case SharedTransitionAnimationType.dismiss:
|
||||
if (Utils.isNumber(state?.pageReturn?.duration)) {
|
||||
return state.pageReturn?.duration / 1000;
|
||||
} else {
|
||||
return Utils.getDurationWithDampingFromSpring(state.pageReturn?.spring).duration;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0.35;
|
||||
return CORE_ANIMATION_DEFAULTS.duration;
|
||||
}
|
||||
|
||||
animateTransition(transitionContext: UIViewControllerContextTransitioning): void {
|
||||
|
||||
@@ -52,8 +52,8 @@ export function test_Transitions() {
|
||||
// helper.navigateWithEntry({ create: mainPageFactory, clearHistory: true, animated: false });
|
||||
}
|
||||
|
||||
export function test_SharedElementTransitions() {
|
||||
helper.navigate(() => {
|
||||
export function test_SharedElementTransitions(done) {
|
||||
const mainPage = helper.navigate(() => {
|
||||
const page = new Page();
|
||||
page.id = 'SharedelementTransitionsTestPage_MAIN';
|
||||
page.style.backgroundColor = new Color(255, Math.round(Math.random() * 255), Math.round(Math.random() * 255), Math.round(Math.random() * 255));
|
||||
@@ -76,12 +76,12 @@ export function test_SharedElementTransitions() {
|
||||
|
||||
const navigationTransition = SharedTransition.custom(new CustomSharedElementPageTransition());
|
||||
|
||||
var testId = `SharedElementTransition[${JSON.stringify(navigationTransition)}]`;
|
||||
const testId = `SharedElementTransition[${JSON.stringify(navigationTransition)}]`;
|
||||
if (Trace.isEnabled()) {
|
||||
Trace.write(`Testing ${testId}`, Trace.categories.Test);
|
||||
}
|
||||
var navigationEntry: NavigationEntry = {
|
||||
create: function (): Page {
|
||||
const navigationEntry: NavigationEntry = {
|
||||
create(): Page {
|
||||
let page = new Page();
|
||||
page.id = testId;
|
||||
page.style.backgroundColor = new Color(255, Math.round(Math.random() * 255), Math.round(Math.random() * 255), Math.round(Math.random() * 255));
|
||||
@@ -99,11 +99,16 @@ export function test_SharedElementTransitions() {
|
||||
grid.addChild(sharedElement);
|
||||
|
||||
page.content = grid;
|
||||
|
||||
page.once('navigatedTo', () => {
|
||||
done();
|
||||
});
|
||||
|
||||
return page;
|
||||
},
|
||||
animated: true,
|
||||
transition: navigationTransition,
|
||||
};
|
||||
|
||||
helper.navigateWithEntry(navigationEntry);
|
||||
mainPage.frame.navigate(navigationEntry);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user