mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
chore: format
This commit is contained in:
@@ -1,31 +1,35 @@
|
||||
import { Transition, AndroidTransitionType } from ".";
|
||||
|
||||
export class FadeTransition extends Transition {
|
||||
public createAndroidAnimator(transitionType: string): android.animation.AnimatorSet {
|
||||
const animatorSet = new android.animation.AnimatorSet();
|
||||
const alphaValues = Array.create("float", 2);
|
||||
switch (transitionType) {
|
||||
case AndroidTransitionType.enter:
|
||||
case AndroidTransitionType.popEnter:
|
||||
alphaValues[0] = 0;
|
||||
alphaValues[1] = 1;
|
||||
break;
|
||||
case AndroidTransitionType.exit:
|
||||
case AndroidTransitionType.popExit:
|
||||
alphaValues[0] = 1;
|
||||
alphaValues[1] = 0;
|
||||
break;
|
||||
}
|
||||
public createAndroidAnimator(
|
||||
transitionType: string
|
||||
): android.animation.AnimatorSet {
|
||||
const animatorSet = new android.animation.AnimatorSet();
|
||||
const alphaValues = Array.create("float", 2);
|
||||
switch (transitionType) {
|
||||
case AndroidTransitionType.enter:
|
||||
case AndroidTransitionType.popEnter:
|
||||
alphaValues[0] = 0;
|
||||
alphaValues[1] = 1;
|
||||
break;
|
||||
case AndroidTransitionType.exit:
|
||||
case AndroidTransitionType.popExit:
|
||||
alphaValues[0] = 1;
|
||||
alphaValues[1] = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
const animator = <android.animation.Animator>android.animation.ObjectAnimator.ofFloat(null, "alpha", alphaValues);
|
||||
const duration = this.getDuration();
|
||||
if (duration !== undefined) {
|
||||
animator.setDuration(duration);
|
||||
}
|
||||
const animator = <android.animation.Animator>(
|
||||
android.animation.ObjectAnimator.ofFloat(null, "alpha", alphaValues)
|
||||
);
|
||||
const duration = this.getDuration();
|
||||
if (duration !== undefined) {
|
||||
animator.setDuration(duration);
|
||||
}
|
||||
|
||||
animator.setInterpolator(this.getCurve());
|
||||
animatorSet.play(animator);
|
||||
|
||||
return animatorSet;
|
||||
}
|
||||
animator.setInterpolator(this.getCurve());
|
||||
animatorSet.play(animator);
|
||||
|
||||
return animatorSet;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Transition } from ".";
|
||||
|
||||
export class FadeTransition extends Transition {
|
||||
constructor(duration: number, nativeCurve: any);
|
||||
constructor(duration: number, nativeCurve: any);
|
||||
}
|
||||
|
||||
@@ -1,32 +1,42 @@
|
||||
import { Transition } from ".";
|
||||
|
||||
export class FadeTransition extends Transition {
|
||||
public animateIOSTransition(containerView: UIView, fromView: UIView, toView: UIView, operation: UINavigationControllerOperation, completion: (finished: boolean) => void): void {
|
||||
let originalToViewAlpha = toView.alpha;
|
||||
let originalFromViewAlpha = fromView.alpha;
|
||||
public animateIOSTransition(
|
||||
containerView: UIView,
|
||||
fromView: UIView,
|
||||
toView: UIView,
|
||||
operation: UINavigationControllerOperation,
|
||||
completion: (finished: boolean) => void
|
||||
): void {
|
||||
let originalToViewAlpha = toView.alpha;
|
||||
let originalFromViewAlpha = fromView.alpha;
|
||||
|
||||
toView.alpha = 0.0;
|
||||
fromView.alpha = 1.0;
|
||||
toView.alpha = 0.0;
|
||||
fromView.alpha = 1.0;
|
||||
|
||||
switch (operation) {
|
||||
case UINavigationControllerOperation.Push:
|
||||
containerView.insertSubviewAboveSubview(toView, fromView);
|
||||
break;
|
||||
case UINavigationControllerOperation.Pop:
|
||||
containerView.insertSubviewBelowSubview(toView, fromView);
|
||||
break;
|
||||
}
|
||||
switch (operation) {
|
||||
case UINavigationControllerOperation.Push:
|
||||
containerView.insertSubviewAboveSubview(toView, fromView);
|
||||
break;
|
||||
case UINavigationControllerOperation.Pop:
|
||||
containerView.insertSubviewBelowSubview(toView, fromView);
|
||||
break;
|
||||
}
|
||||
|
||||
let duration = this.getDuration();
|
||||
let curve = this.getCurve();
|
||||
UIView.animateWithDurationAnimationsCompletion(duration, () => {
|
||||
UIView.setAnimationCurve(curve);
|
||||
toView.alpha = 1.0;
|
||||
fromView.alpha = 0.0;
|
||||
}, (finished: boolean) => {
|
||||
toView.alpha = originalToViewAlpha;
|
||||
fromView.alpha = originalFromViewAlpha;
|
||||
completion(finished);
|
||||
});
|
||||
}
|
||||
let duration = this.getDuration();
|
||||
let curve = this.getCurve();
|
||||
UIView.animateWithDurationAnimationsCompletion(
|
||||
duration,
|
||||
() => {
|
||||
UIView.setAnimationCurve(curve);
|
||||
toView.alpha = 1.0;
|
||||
fromView.alpha = 0.0;
|
||||
},
|
||||
(finished: boolean) => {
|
||||
toView.alpha = originalToViewAlpha;
|
||||
fromView.alpha = originalFromViewAlpha;
|
||||
completion(finished);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,103 +2,153 @@ import { Transition, AndroidTransitionType } from ".";
|
||||
|
||||
//http://developer.android.com/training/animation/cardflip.html
|
||||
export class FlipTransition extends Transition {
|
||||
private _direction: string;
|
||||
private _direction: string;
|
||||
|
||||
constructor(direction: string, duration: number, curve: any) {
|
||||
super(duration, curve);
|
||||
this._direction = direction;
|
||||
}
|
||||
constructor(direction: string, duration: number, curve: any) {
|
||||
super(duration, curve);
|
||||
this._direction = direction;
|
||||
}
|
||||
|
||||
public createAndroidAnimator(transitionType: string): android.animation.AnimatorSet {
|
||||
let objectAnimators;
|
||||
let values;
|
||||
let animator: android.animation.Animator; //android.animation.ObjectAnimator;
|
||||
const animatorSet = new android.animation.AnimatorSet();
|
||||
const fullDuration = this.getDuration() || 300;
|
||||
const interpolator = this.getCurve();
|
||||
const rotationY = this._direction === "right" ? 180 : -180;
|
||||
public createAndroidAnimator(
|
||||
transitionType: string
|
||||
): android.animation.AnimatorSet {
|
||||
let objectAnimators;
|
||||
let values;
|
||||
let animator: android.animation.Animator; //android.animation.ObjectAnimator;
|
||||
const animatorSet = new android.animation.AnimatorSet();
|
||||
const fullDuration = this.getDuration() || 300;
|
||||
const interpolator = this.getCurve();
|
||||
const rotationY = this._direction === "right" ? 180 : -180;
|
||||
|
||||
switch (transitionType) {
|
||||
case AndroidTransitionType.enter: // card_flip_right_in
|
||||
objectAnimators = Array.create(android.animation.Animator, 2);
|
||||
switch (transitionType) {
|
||||
case AndroidTransitionType.enter: // card_flip_right_in
|
||||
objectAnimators = Array.create(android.animation.Animator, 2);
|
||||
|
||||
values = Array.create("float", 2);
|
||||
values[0] = rotationY;
|
||||
values[1] = 0.0;
|
||||
animator = <android.animation.Animator>android.animation.ObjectAnimator.ofFloat(null, "rotationY", values);
|
||||
animator.setInterpolator(interpolator);
|
||||
animator.setDuration(fullDuration);
|
||||
objectAnimators[0] = animator;
|
||||
values = Array.create("float", 2);
|
||||
values[0] = rotationY;
|
||||
values[1] = 0.0;
|
||||
animator = <android.animation.Animator>(
|
||||
android.animation.ObjectAnimator.ofFloat(
|
||||
null,
|
||||
"rotationY",
|
||||
values
|
||||
)
|
||||
);
|
||||
animator.setInterpolator(interpolator);
|
||||
animator.setDuration(fullDuration);
|
||||
objectAnimators[0] = animator;
|
||||
|
||||
values = Array.create("float", 3);
|
||||
values[0] = 0.0;
|
||||
values[1] = 0.0;
|
||||
values[2] = 255.0;
|
||||
animator = <android.animation.Animator>android.animation.ObjectAnimator.ofFloat(null, "alpha", values);
|
||||
animator.setDuration(fullDuration / 2);
|
||||
objectAnimators[1] = animator;
|
||||
break;
|
||||
case AndroidTransitionType.exit: // card_flip_right_out
|
||||
objectAnimators = Array.create(android.animation.Animator, 2);
|
||||
values = Array.create("float", 3);
|
||||
values[0] = 0.0;
|
||||
values[1] = 0.0;
|
||||
values[2] = 255.0;
|
||||
animator = <android.animation.Animator>(
|
||||
android.animation.ObjectAnimator.ofFloat(
|
||||
null,
|
||||
"alpha",
|
||||
values
|
||||
)
|
||||
);
|
||||
animator.setDuration(fullDuration / 2);
|
||||
objectAnimators[1] = animator;
|
||||
break;
|
||||
case AndroidTransitionType.exit: // card_flip_right_out
|
||||
objectAnimators = Array.create(android.animation.Animator, 2);
|
||||
|
||||
values = Array.create("float", 2);
|
||||
values[0] = 0.0;
|
||||
values[1] = -rotationY;
|
||||
animator = <android.animation.Animator>android.animation.ObjectAnimator.ofFloat(null, "rotationY", values);
|
||||
animator.setInterpolator(interpolator);
|
||||
animator.setDuration(fullDuration);
|
||||
objectAnimators[0] = animator;
|
||||
values = Array.create("float", 2);
|
||||
values[0] = 0.0;
|
||||
values[1] = -rotationY;
|
||||
animator = <android.animation.Animator>(
|
||||
android.animation.ObjectAnimator.ofFloat(
|
||||
null,
|
||||
"rotationY",
|
||||
values
|
||||
)
|
||||
);
|
||||
animator.setInterpolator(interpolator);
|
||||
animator.setDuration(fullDuration);
|
||||
objectAnimators[0] = animator;
|
||||
|
||||
values = Array.create("float", 3);
|
||||
values[0] = 255.0;
|
||||
values[1] = 0.0;
|
||||
values[2] = 0.0;
|
||||
animator = <android.animation.Animator>android.animation.ObjectAnimator.ofFloat(null, "alpha", values);
|
||||
animator.setDuration(fullDuration / 2);
|
||||
objectAnimators[1] = animator;
|
||||
break;
|
||||
case AndroidTransitionType.popEnter: // card_flip_left_in
|
||||
objectAnimators = Array.create(android.animation.Animator, 2);
|
||||
values = Array.create("float", 3);
|
||||
values[0] = 255.0;
|
||||
values[1] = 0.0;
|
||||
values[2] = 0.0;
|
||||
animator = <android.animation.Animator>(
|
||||
android.animation.ObjectAnimator.ofFloat(
|
||||
null,
|
||||
"alpha",
|
||||
values
|
||||
)
|
||||
);
|
||||
animator.setDuration(fullDuration / 2);
|
||||
objectAnimators[1] = animator;
|
||||
break;
|
||||
case AndroidTransitionType.popEnter: // card_flip_left_in
|
||||
objectAnimators = Array.create(android.animation.Animator, 2);
|
||||
|
||||
values = Array.create("float", 2);
|
||||
values[0] = -rotationY;
|
||||
values[1] = 0.0;
|
||||
animator = <android.animation.Animator>android.animation.ObjectAnimator.ofFloat(null, "rotationY", values);
|
||||
animator.setInterpolator(interpolator);
|
||||
animator.setDuration(fullDuration);
|
||||
objectAnimators[0] = animator;
|
||||
values = Array.create("float", 2);
|
||||
values[0] = -rotationY;
|
||||
values[1] = 0.0;
|
||||
animator = <android.animation.Animator>(
|
||||
android.animation.ObjectAnimator.ofFloat(
|
||||
null,
|
||||
"rotationY",
|
||||
values
|
||||
)
|
||||
);
|
||||
animator.setInterpolator(interpolator);
|
||||
animator.setDuration(fullDuration);
|
||||
objectAnimators[0] = animator;
|
||||
|
||||
values = Array.create("float", 3);
|
||||
values[0] = 0.0;
|
||||
values[1] = 0.0;
|
||||
values[2] = 255.0;
|
||||
animator = <android.animation.Animator>android.animation.ObjectAnimator.ofFloat(null, "alpha", values);
|
||||
animator.setDuration(fullDuration / 2);
|
||||
objectAnimators[1] = animator;
|
||||
break;
|
||||
case AndroidTransitionType.popExit: // card_flip_left_out
|
||||
objectAnimators = Array.create(android.animation.Animator, 2);
|
||||
values = Array.create("float", 3);
|
||||
values[0] = 0.0;
|
||||
values[1] = 0.0;
|
||||
values[2] = 255.0;
|
||||
animator = <android.animation.Animator>(
|
||||
android.animation.ObjectAnimator.ofFloat(
|
||||
null,
|
||||
"alpha",
|
||||
values
|
||||
)
|
||||
);
|
||||
animator.setDuration(fullDuration / 2);
|
||||
objectAnimators[1] = animator;
|
||||
break;
|
||||
case AndroidTransitionType.popExit: // card_flip_left_out
|
||||
objectAnimators = Array.create(android.animation.Animator, 2);
|
||||
|
||||
values = Array.create("float", 2);
|
||||
values[0] = 0.0;
|
||||
values[1] = rotationY;
|
||||
animator = <android.animation.Animator>android.animation.ObjectAnimator.ofFloat(null, "rotationY", values);
|
||||
animator.setInterpolator(interpolator);
|
||||
animator.setDuration(fullDuration);
|
||||
objectAnimators[0] = animator;
|
||||
values = Array.create("float", 2);
|
||||
values[0] = 0.0;
|
||||
values[1] = rotationY;
|
||||
animator = <android.animation.Animator>(
|
||||
android.animation.ObjectAnimator.ofFloat(
|
||||
null,
|
||||
"rotationY",
|
||||
values
|
||||
)
|
||||
);
|
||||
animator.setInterpolator(interpolator);
|
||||
animator.setDuration(fullDuration);
|
||||
objectAnimators[0] = animator;
|
||||
|
||||
values = Array.create("float", 3);
|
||||
values[0] = 255.0;
|
||||
values[1] = 0.0;
|
||||
values[2] = 0.0;
|
||||
animator = <android.animation.Animator>android.animation.ObjectAnimator.ofFloat(null, "alpha", values);
|
||||
animator.setDuration(fullDuration / 2);
|
||||
objectAnimators[1] = animator;
|
||||
break;
|
||||
}
|
||||
values = Array.create("float", 3);
|
||||
values[0] = 255.0;
|
||||
values[1] = 0.0;
|
||||
values[2] = 0.0;
|
||||
animator = <android.animation.Animator>(
|
||||
android.animation.ObjectAnimator.ofFloat(
|
||||
null,
|
||||
"alpha",
|
||||
values
|
||||
)
|
||||
);
|
||||
animator.setDuration(fullDuration / 2);
|
||||
objectAnimators[1] = animator;
|
||||
break;
|
||||
}
|
||||
|
||||
animatorSet.playTogether(objectAnimators);
|
||||
animatorSet.playTogether(objectAnimators);
|
||||
|
||||
return animatorSet;
|
||||
}
|
||||
return animatorSet;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Transition } from ".";
|
||||
|
||||
export class FlipTransition extends Transition {
|
||||
constructor(direction: string, duration: number, curve: any);
|
||||
constructor(direction: string, duration: number, curve: any);
|
||||
}
|
||||
|
||||
@@ -2,44 +2,56 @@
|
||||
import { _resolveAnimationCurve } from "../animation";
|
||||
import lazy from "../../utils/lazy";
|
||||
|
||||
const _defaultInterpolator = lazy(() => new android.view.animation.AccelerateDecelerateInterpolator());
|
||||
const _defaultInterpolator = lazy(
|
||||
() => new android.view.animation.AccelerateDecelerateInterpolator()
|
||||
);
|
||||
|
||||
export module AndroidTransitionType {
|
||||
export const enter = "enter";
|
||||
export const exit = "exit";
|
||||
export const popEnter = "popEnter";
|
||||
export const popExit = "popExit";
|
||||
export const enter = "enter";
|
||||
export const exit = "exit";
|
||||
export const popEnter = "popEnter";
|
||||
export const popExit = "popExit";
|
||||
}
|
||||
|
||||
let transitionId = 0;
|
||||
export class Transition {
|
||||
private _duration: number;
|
||||
private _interpolator: android.view.animation.Interpolator;
|
||||
private _id: number;
|
||||
private _duration: number;
|
||||
private _interpolator: android.view.animation.Interpolator;
|
||||
private _id: number;
|
||||
|
||||
constructor(duration: number, curve: any) {
|
||||
this._duration = duration;
|
||||
this._interpolator = curve ? _resolveAnimationCurve(curve) : _defaultInterpolator();
|
||||
this._id = transitionId++;
|
||||
}
|
||||
constructor(duration: number, curve: any) {
|
||||
this._duration = duration;
|
||||
this._interpolator = curve
|
||||
? _resolveAnimationCurve(curve)
|
||||
: _defaultInterpolator();
|
||||
this._id = transitionId++;
|
||||
}
|
||||
|
||||
public getDuration(): number {
|
||||
return this._duration;
|
||||
}
|
||||
public getDuration(): number {
|
||||
return this._duration;
|
||||
}
|
||||
|
||||
public getCurve(): android.view.animation.Interpolator {
|
||||
return this._interpolator;
|
||||
}
|
||||
public getCurve(): android.view.animation.Interpolator {
|
||||
return this._interpolator;
|
||||
}
|
||||
|
||||
public animateIOSTransition(containerView: any, fromView: any, toView: any, operation: any, completion: (finished: boolean) => void): void {
|
||||
throw new Error("Abstract method call");
|
||||
}
|
||||
public animateIOSTransition(
|
||||
containerView: any,
|
||||
fromView: any,
|
||||
toView: any,
|
||||
operation: any,
|
||||
completion: (finished: boolean) => void
|
||||
): void {
|
||||
throw new Error("Abstract method call");
|
||||
}
|
||||
|
||||
public createAndroidAnimator(transitionType: string): android.animation.Animator {
|
||||
throw new Error("Abstract method call");
|
||||
}
|
||||
public createAndroidAnimator(
|
||||
transitionType: string
|
||||
): android.animation.Animator {
|
||||
throw new Error("Abstract method call");
|
||||
}
|
||||
|
||||
public toString(): string {
|
||||
return `Transition@${this._id}`;
|
||||
}
|
||||
public toString(): string {
|
||||
return `Transition@${this._id}`;
|
||||
}
|
||||
}
|
||||
|
||||
26
nativescript-core/ui/transition/index.d.ts
vendored
26
nativescript-core/ui/transition/index.d.ts
vendored
@@ -1,15 +1,21 @@
|
||||
export module AndroidTransitionType {
|
||||
export const enter: string;
|
||||
export const exit: string;
|
||||
export const popEnter: string;
|
||||
export const popExit: string;
|
||||
export const enter: string;
|
||||
export const exit: string;
|
||||
export const popEnter: string;
|
||||
export const popExit: string;
|
||||
}
|
||||
|
||||
export class Transition {
|
||||
constructor(duration: number, nativeCurve: any);
|
||||
public getDuration(): number;
|
||||
public getCurve(): any;
|
||||
public animateIOSTransition(containerView: any, fromView: any, toView: any, operation: any, completion: (finished: boolean) => void): void;
|
||||
public createAndroidAnimator(transitionType: string): any;
|
||||
public toString(): string;
|
||||
constructor(duration: number, nativeCurve: any);
|
||||
public getDuration(): number;
|
||||
public getCurve(): any;
|
||||
public animateIOSTransition(
|
||||
containerView: any,
|
||||
fromView: any,
|
||||
toView: any,
|
||||
operation: any,
|
||||
completion: (finished: boolean) => void
|
||||
): void;
|
||||
public createAndroidAnimator(transitionType: string): any;
|
||||
public toString(): string;
|
||||
}
|
||||
|
||||
@@ -1,32 +1,41 @@
|
||||
let transitionId = 0;
|
||||
export class Transition {
|
||||
private _duration: number;
|
||||
private _curve: UIViewAnimationCurve;
|
||||
private _id: number;
|
||||
private _duration: number;
|
||||
private _curve: UIViewAnimationCurve;
|
||||
private _id: number;
|
||||
|
||||
constructor(duration: number, curve: UIViewAnimationCurve = UIViewAnimationCurve.EaseInOut) {
|
||||
this._duration = duration ? (duration / 1000) : 0.35;
|
||||
this._curve = curve;
|
||||
this._id = transitionId++;
|
||||
}
|
||||
constructor(
|
||||
duration: number,
|
||||
curve: UIViewAnimationCurve = UIViewAnimationCurve.EaseInOut
|
||||
) {
|
||||
this._duration = duration ? duration / 1000 : 0.35;
|
||||
this._curve = curve;
|
||||
this._id = transitionId++;
|
||||
}
|
||||
|
||||
public getDuration(): number {
|
||||
return this._duration;
|
||||
}
|
||||
public getDuration(): number {
|
||||
return this._duration;
|
||||
}
|
||||
|
||||
public getCurve(): UIViewAnimationCurve {
|
||||
return this._curve;
|
||||
}
|
||||
public getCurve(): UIViewAnimationCurve {
|
||||
return this._curve;
|
||||
}
|
||||
|
||||
public animateIOSTransition(containerView: UIView, fromView: UIView, toView: UIView, operation: UINavigationControllerOperation, completion: (finished: boolean) => void): void {
|
||||
throw new Error("Abstract method call");
|
||||
}
|
||||
public animateIOSTransition(
|
||||
containerView: UIView,
|
||||
fromView: UIView,
|
||||
toView: UIView,
|
||||
operation: UINavigationControllerOperation,
|
||||
completion: (finished: boolean) => void
|
||||
): void {
|
||||
throw new Error("Abstract method call");
|
||||
}
|
||||
|
||||
public createAndroidAnimator(transitionType: string): any {
|
||||
throw new Error("Abstract method call");
|
||||
}
|
||||
public createAndroidAnimator(transitionType: string): any {
|
||||
throw new Error("Abstract method call");
|
||||
}
|
||||
|
||||
public toString(): string {
|
||||
return `Transition@${this._id}`;
|
||||
}
|
||||
public toString(): string {
|
||||
return `Transition@${this._id}`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,118 +6,123 @@ const screenWidth = lazy(() => platform.screen.mainScreen.widthPixels);
|
||||
const screenHeight = lazy(() => platform.screen.mainScreen.heightPixels);
|
||||
|
||||
export class SlideTransition extends transition.Transition {
|
||||
private _direction: string;
|
||||
private _direction: string;
|
||||
|
||||
constructor(direction: string, duration: number, curve: any) {
|
||||
super(duration, curve);
|
||||
this._direction = direction;
|
||||
}
|
||||
constructor(direction: string, duration: number, curve: any) {
|
||||
super(duration, curve);
|
||||
this._direction = direction;
|
||||
}
|
||||
|
||||
public createAndroidAnimator(transitionType: string): android.animation.Animator {
|
||||
const translationValues = Array.create("float", 2);
|
||||
switch (this._direction) {
|
||||
case "left":
|
||||
switch (transitionType) {
|
||||
case transition.AndroidTransitionType.enter:
|
||||
translationValues[0] = screenWidth();
|
||||
translationValues[1] = 0;
|
||||
break;
|
||||
case transition.AndroidTransitionType.exit:
|
||||
translationValues[0] = 0;
|
||||
translationValues[1] = -screenWidth();
|
||||
break;
|
||||
case transition.AndroidTransitionType.popEnter:
|
||||
translationValues[0] = -screenWidth();
|
||||
translationValues[1] = 0;
|
||||
break;
|
||||
case transition.AndroidTransitionType.popExit:
|
||||
translationValues[0] = 0;
|
||||
translationValues[1] = screenWidth();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "right":
|
||||
switch (transitionType) {
|
||||
case transition.AndroidTransitionType.enter:
|
||||
translationValues[0] = -screenWidth();
|
||||
translationValues[1] = 0;
|
||||
break;
|
||||
case transition.AndroidTransitionType.exit:
|
||||
translationValues[0] = 0;
|
||||
translationValues[1] = screenWidth();
|
||||
break;
|
||||
case transition.AndroidTransitionType.popEnter:
|
||||
translationValues[0] = screenWidth();
|
||||
translationValues[1] = 0;
|
||||
break;
|
||||
case transition.AndroidTransitionType.popExit:
|
||||
translationValues[0] = 0;
|
||||
translationValues[1] = -screenWidth();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "top":
|
||||
switch (transitionType) {
|
||||
case transition.AndroidTransitionType.enter:
|
||||
translationValues[0] = screenHeight();
|
||||
translationValues[1] = 0;
|
||||
break;
|
||||
case transition.AndroidTransitionType.exit:
|
||||
translationValues[0] = 0;
|
||||
translationValues[1] = -screenHeight();
|
||||
break;
|
||||
case transition.AndroidTransitionType.popEnter:
|
||||
translationValues[0] = -screenHeight();
|
||||
translationValues[1] = 0;
|
||||
break;
|
||||
case transition.AndroidTransitionType.popExit:
|
||||
translationValues[0] = 0;
|
||||
translationValues[1] = screenHeight();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "bottom":
|
||||
switch (transitionType) {
|
||||
case transition.AndroidTransitionType.enter:
|
||||
translationValues[0] = -screenHeight();
|
||||
translationValues[1] = 0;
|
||||
break;
|
||||
case transition.AndroidTransitionType.exit:
|
||||
translationValues[0] = 0;
|
||||
translationValues[1] = screenHeight();
|
||||
break;
|
||||
case transition.AndroidTransitionType.popEnter:
|
||||
translationValues[0] = screenHeight();
|
||||
translationValues[1] = 0;
|
||||
break;
|
||||
case transition.AndroidTransitionType.popExit:
|
||||
translationValues[0] = 0;
|
||||
translationValues[1] = -screenHeight();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
public createAndroidAnimator(
|
||||
transitionType: string
|
||||
): android.animation.Animator {
|
||||
const translationValues = Array.create("float", 2);
|
||||
switch (this._direction) {
|
||||
case "left":
|
||||
switch (transitionType) {
|
||||
case transition.AndroidTransitionType.enter:
|
||||
translationValues[0] = screenWidth();
|
||||
translationValues[1] = 0;
|
||||
break;
|
||||
case transition.AndroidTransitionType.exit:
|
||||
translationValues[0] = 0;
|
||||
translationValues[1] = -screenWidth();
|
||||
break;
|
||||
case transition.AndroidTransitionType.popEnter:
|
||||
translationValues[0] = -screenWidth();
|
||||
translationValues[1] = 0;
|
||||
break;
|
||||
case transition.AndroidTransitionType.popExit:
|
||||
translationValues[0] = 0;
|
||||
translationValues[1] = screenWidth();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "right":
|
||||
switch (transitionType) {
|
||||
case transition.AndroidTransitionType.enter:
|
||||
translationValues[0] = -screenWidth();
|
||||
translationValues[1] = 0;
|
||||
break;
|
||||
case transition.AndroidTransitionType.exit:
|
||||
translationValues[0] = 0;
|
||||
translationValues[1] = screenWidth();
|
||||
break;
|
||||
case transition.AndroidTransitionType.popEnter:
|
||||
translationValues[0] = screenWidth();
|
||||
translationValues[1] = 0;
|
||||
break;
|
||||
case transition.AndroidTransitionType.popExit:
|
||||
translationValues[0] = 0;
|
||||
translationValues[1] = -screenWidth();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "top":
|
||||
switch (transitionType) {
|
||||
case transition.AndroidTransitionType.enter:
|
||||
translationValues[0] = screenHeight();
|
||||
translationValues[1] = 0;
|
||||
break;
|
||||
case transition.AndroidTransitionType.exit:
|
||||
translationValues[0] = 0;
|
||||
translationValues[1] = -screenHeight();
|
||||
break;
|
||||
case transition.AndroidTransitionType.popEnter:
|
||||
translationValues[0] = -screenHeight();
|
||||
translationValues[1] = 0;
|
||||
break;
|
||||
case transition.AndroidTransitionType.popExit:
|
||||
translationValues[0] = 0;
|
||||
translationValues[1] = screenHeight();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "bottom":
|
||||
switch (transitionType) {
|
||||
case transition.AndroidTransitionType.enter:
|
||||
translationValues[0] = -screenHeight();
|
||||
translationValues[1] = 0;
|
||||
break;
|
||||
case transition.AndroidTransitionType.exit:
|
||||
translationValues[0] = 0;
|
||||
translationValues[1] = screenHeight();
|
||||
break;
|
||||
case transition.AndroidTransitionType.popEnter:
|
||||
translationValues[0] = screenHeight();
|
||||
translationValues[1] = 0;
|
||||
break;
|
||||
case transition.AndroidTransitionType.popExit:
|
||||
translationValues[0] = 0;
|
||||
translationValues[1] = -screenHeight();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
let prop;
|
||||
let prop;
|
||||
|
||||
if (this._direction === "left" || this._direction === "right") {
|
||||
prop = "translationX";
|
||||
}
|
||||
else {
|
||||
prop = "translationY";
|
||||
}
|
||||
if (this._direction === "left" || this._direction === "right") {
|
||||
prop = "translationX";
|
||||
} else {
|
||||
prop = "translationY";
|
||||
}
|
||||
|
||||
const animator = android.animation.ObjectAnimator.ofFloat(null, prop, translationValues);
|
||||
const duration = this.getDuration();
|
||||
if (duration !== undefined) {
|
||||
animator.setDuration(duration);
|
||||
}
|
||||
animator.setInterpolator(this.getCurve());
|
||||
const animator = android.animation.ObjectAnimator.ofFloat(
|
||||
null,
|
||||
prop,
|
||||
translationValues
|
||||
);
|
||||
const duration = this.getDuration();
|
||||
if (duration !== undefined) {
|
||||
animator.setDuration(duration);
|
||||
}
|
||||
animator.setInterpolator(this.getCurve());
|
||||
|
||||
return animator;
|
||||
}
|
||||
return animator;
|
||||
}
|
||||
|
||||
public toString(): string {
|
||||
return `${super.toString()} ${this._direction}`;
|
||||
}
|
||||
public toString(): string {
|
||||
return `${super.toString()} ${this._direction}`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Transition } from ".";
|
||||
|
||||
export class SlideTransition extends Transition {
|
||||
constructor(direction: string, duration: number, nativeCurve: any);
|
||||
constructor(direction: string, duration: number, nativeCurve: any);
|
||||
}
|
||||
|
||||
@@ -9,62 +9,72 @@ let topEdge = CGAffineTransformMakeTranslation(0, -screenHeight);
|
||||
let bottomEdge = CGAffineTransformMakeTranslation(0, screenHeight);
|
||||
|
||||
export class SlideTransition extends Transition {
|
||||
private _direction: string;
|
||||
private _direction: string;
|
||||
|
||||
constructor(direction: string, duration: number, curve: any) {
|
||||
super(duration, curve);
|
||||
this._direction = direction;
|
||||
}
|
||||
constructor(direction: string, duration: number, curve: any) {
|
||||
super(duration, curve);
|
||||
this._direction = direction;
|
||||
}
|
||||
|
||||
public animateIOSTransition(containerView: UIView, fromView: UIView, toView: UIView, operation: UINavigationControllerOperation, completion: (finished: boolean) => void): void {
|
||||
let originalToViewTransform = toView.transform;
|
||||
let originalFromViewTransform = fromView.transform;
|
||||
public animateIOSTransition(
|
||||
containerView: UIView,
|
||||
fromView: UIView,
|
||||
toView: UIView,
|
||||
operation: UINavigationControllerOperation,
|
||||
completion: (finished: boolean) => void
|
||||
): void {
|
||||
let originalToViewTransform = toView.transform;
|
||||
let originalFromViewTransform = fromView.transform;
|
||||
|
||||
let fromViewEndTransform: CGAffineTransform;
|
||||
let toViewBeginTransform: CGAffineTransform;
|
||||
let push = (operation === UINavigationControllerOperation.Push);
|
||||
let fromViewEndTransform: CGAffineTransform;
|
||||
let toViewBeginTransform: CGAffineTransform;
|
||||
let push = operation === UINavigationControllerOperation.Push;
|
||||
|
||||
switch (this._direction) {
|
||||
case "left":
|
||||
toViewBeginTransform = push ? rightEdge : leftEdge;
|
||||
fromViewEndTransform = push ? leftEdge : rightEdge;
|
||||
break;
|
||||
case "right":
|
||||
toViewBeginTransform = push ? leftEdge : rightEdge;
|
||||
fromViewEndTransform = push ? rightEdge : leftEdge;
|
||||
break;
|
||||
case "top":
|
||||
toViewBeginTransform = push ? bottomEdge : topEdge;
|
||||
fromViewEndTransform = push ? topEdge : bottomEdge;
|
||||
break;
|
||||
case "bottom":
|
||||
toViewBeginTransform = push ? topEdge : bottomEdge;
|
||||
fromViewEndTransform = push ? bottomEdge : topEdge;
|
||||
break;
|
||||
}
|
||||
switch (this._direction) {
|
||||
case "left":
|
||||
toViewBeginTransform = push ? rightEdge : leftEdge;
|
||||
fromViewEndTransform = push ? leftEdge : rightEdge;
|
||||
break;
|
||||
case "right":
|
||||
toViewBeginTransform = push ? leftEdge : rightEdge;
|
||||
fromViewEndTransform = push ? rightEdge : leftEdge;
|
||||
break;
|
||||
case "top":
|
||||
toViewBeginTransform = push ? bottomEdge : topEdge;
|
||||
fromViewEndTransform = push ? topEdge : bottomEdge;
|
||||
break;
|
||||
case "bottom":
|
||||
toViewBeginTransform = push ? topEdge : bottomEdge;
|
||||
fromViewEndTransform = push ? bottomEdge : topEdge;
|
||||
break;
|
||||
}
|
||||
|
||||
toView.transform = toViewBeginTransform;
|
||||
fromView.transform = CGAffineTransformIdentity;
|
||||
toView.transform = toViewBeginTransform;
|
||||
fromView.transform = CGAffineTransformIdentity;
|
||||
|
||||
switch (operation) {
|
||||
case UINavigationControllerOperation.Push:
|
||||
containerView.insertSubviewAboveSubview(toView, fromView);
|
||||
break;
|
||||
case UINavigationControllerOperation.Pop:
|
||||
containerView.insertSubviewBelowSubview(toView, fromView);
|
||||
break;
|
||||
}
|
||||
switch (operation) {
|
||||
case UINavigationControllerOperation.Push:
|
||||
containerView.insertSubviewAboveSubview(toView, fromView);
|
||||
break;
|
||||
case UINavigationControllerOperation.Pop:
|
||||
containerView.insertSubviewBelowSubview(toView, fromView);
|
||||
break;
|
||||
}
|
||||
|
||||
let duration = this.getDuration();
|
||||
let curve = this.getCurve();
|
||||
UIView.animateWithDurationAnimationsCompletion(duration, () => {
|
||||
UIView.setAnimationCurve(curve);
|
||||
toView.transform = CGAffineTransformIdentity;
|
||||
fromView.transform = fromViewEndTransform;
|
||||
}, (finished: boolean) => {
|
||||
toView.transform = originalToViewTransform;
|
||||
fromView.transform = originalFromViewTransform;
|
||||
completion(finished);
|
||||
});
|
||||
}
|
||||
let duration = this.getDuration();
|
||||
let curve = this.getCurve();
|
||||
UIView.animateWithDurationAnimationsCompletion(
|
||||
duration,
|
||||
() => {
|
||||
UIView.setAnimationCurve(curve);
|
||||
toView.transform = CGAffineTransformIdentity;
|
||||
fromView.transform = fromViewEndTransform;
|
||||
},
|
||||
(finished: boolean) => {
|
||||
toView.transform = originalToViewTransform;
|
||||
fromView.transform = originalFromViewTransform;
|
||||
completion(finished);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user