1 | import { CORE_ANIMATION_DEFAULTS, getDurationWithDampingFromSpring } from '../../utils/common';
|
2 | import { isNumber } from '../../utils/types';
|
3 | import { Transition } from '.';
|
4 | import { SharedTransition, SharedTransitionAnimationType } from './shared-transition';
|
5 | import { SharedTransitionHelper } from './shared-transition-helper';
|
6 | import { GestureStateTypes } from '../gestures';
|
7 | export class ModalTransition extends Transition {
|
8 | iosPresentedController(presented, presenting, source) {
|
9 | this.transitionController = ModalTransitionController.initWithOwner(new WeakRef(this));
|
10 | this.presented = presented;
|
11 |
|
12 | return this.transitionController;
|
13 | }
|
14 | iosDismissedController(dismissed) {
|
15 | this.transitionController = ModalTransitionController.initWithOwner(new WeakRef(this));
|
16 | this.presented = dismissed;
|
17 | return this.transitionController;
|
18 | }
|
19 | iosInteractionDismiss(animator) {
|
20 |
|
21 | this.interactiveController = PercentInteractiveController.initWithOwner(new WeakRef(this));
|
22 | return this.interactiveController;
|
23 | }
|
24 | iosInteractionPresented(animator) {
|
25 |
|
26 | return null;
|
27 | }
|
28 | setupInteractiveGesture(startCallback, view) {
|
29 | this._interactiveStartCallback = startCallback;
|
30 | this._interactiveDismissGesture = this._interactiveDismissGestureHandler.bind(this);
|
31 | view.on('pan', this._interactiveDismissGesture);
|
32 |
|
33 |
|
34 |
|
35 |
|
36 | }
|
37 | _interactiveDismissGestureHandler(args) {
|
38 | if (args?.ios?.view) {
|
39 | const state = SharedTransition.getState(this.id);
|
40 | const percent = state.interactive?.dismiss?.percentFormula ? state.interactive.dismiss.percentFormula(args) : args.deltaY / (args.ios.view.bounds.size.height / 2);
|
41 | if (SharedTransition.DEBUG) {
|
42 | console.log('Interactive dismissal percentage:', percent);
|
43 | }
|
44 | switch (args.state) {
|
45 | case GestureStateTypes.began:
|
46 | SharedTransition.updateState(this.id, {
|
47 | interactiveBegan: true,
|
48 | interactiveCancelled: false,
|
49 | });
|
50 | if (this._interactiveStartCallback) {
|
51 | this._interactiveStartCallback();
|
52 | }
|
53 | break;
|
54 | case GestureStateTypes.changed:
|
55 | if (percent < 1) {
|
56 | if (this.interactiveController) {
|
57 | this.interactiveController.updateInteractiveTransition(percent);
|
58 | }
|
59 | }
|
60 | break;
|
61 | case GestureStateTypes.cancelled:
|
62 | case GestureStateTypes.ended:
|
63 | if (this.interactiveController) {
|
64 | const finishThreshold = isNumber(state.interactive?.dismiss?.finishThreshold) ? state.interactive.dismiss.finishThreshold : 0.5;
|
65 | if (percent > finishThreshold) {
|
66 | this.interactiveController.finishInteractiveTransition();
|
67 | }
|
68 | else {
|
69 | SharedTransition.updateState(this.id, {
|
70 | interactiveCancelled: true,
|
71 | });
|
72 | this.interactiveController.cancelInteractiveTransition();
|
73 | }
|
74 | }
|
75 | break;
|
76 | }
|
77 | }
|
78 | }
|
79 | }
|
80 | var PercentInteractiveController = (function (_super) {
|
81 | __extends(PercentInteractiveController, _super);
|
82 | function PercentInteractiveController() {
|
83 | return _super !== null && _super.apply(this, arguments) || this;
|
84 | }
|
85 | PercentInteractiveController.initWithOwner = function (owner) {
|
86 | var ctrl = PercentInteractiveController.new();
|
87 | ctrl.owner = owner;
|
88 | return ctrl;
|
89 | };
|
90 | PercentInteractiveController.prototype.startInteractiveTransition = function (transitionContext) {
|
91 | var _a;
|
92 |
|
93 | if (!this.interactiveState) {
|
94 | this.interactiveState = {
|
95 | transitionContext: transitionContext,
|
96 | };
|
97 | var owner = (_a = this.owner) === null || _a === void 0 ? void 0 : _a.deref();
|
98 | if (owner) {
|
99 | var state = SharedTransition.getState(owner.id);
|
100 | SharedTransitionHelper.interactiveStart(state, this.interactiveState, 'modal');
|
101 | }
|
102 | }
|
103 | };
|
104 | PercentInteractiveController.prototype.updateInteractiveTransition = function (percentComplete) {
|
105 | var _a;
|
106 | var owner = (_a = this.owner) === null || _a === void 0 ? void 0 : _a.deref();
|
107 | if (owner) {
|
108 | var state = SharedTransition.getState(owner.id);
|
109 | SharedTransitionHelper.interactiveUpdate(state, this.interactiveState, 'modal', percentComplete);
|
110 | }
|
111 | };
|
112 | PercentInteractiveController.prototype.cancelInteractiveTransition = function () {
|
113 | var _a;
|
114 |
|
115 | var owner = (_a = this.owner) === null || _a === void 0 ? void 0 : _a.deref();
|
116 | if (owner) {
|
117 | var state = SharedTransition.getState(owner.id);
|
118 | SharedTransitionHelper.interactiveCancel(state, this.interactiveState, 'modal');
|
119 | }
|
120 | };
|
121 | PercentInteractiveController.prototype.finishInteractiveTransition = function () {
|
122 | var _a;
|
123 |
|
124 | var owner = (_a = this.owner) === null || _a === void 0 ? void 0 : _a.deref();
|
125 | if (owner) {
|
126 | var state = SharedTransition.getState(owner.id);
|
127 | SharedTransitionHelper.interactiveFinish(state, this.interactiveState, 'modal');
|
128 | }
|
129 | };
|
130 | PercentInteractiveController.ObjCProtocols = [UIViewControllerInteractiveTransitioning];
|
131 | return PercentInteractiveController;
|
132 | }(UIPercentDrivenInteractiveTransition));
|
133 | var ModalTransitionController = (function (_super) {
|
134 | __extends(ModalTransitionController, _super);
|
135 | function ModalTransitionController() {
|
136 | return _super !== null && _super.apply(this, arguments) || this;
|
137 | }
|
138 | ModalTransitionController.initWithOwner = function (owner) {
|
139 | var ctrl = ModalTransitionController.new();
|
140 | ctrl.owner = owner;
|
141 | return ctrl;
|
142 | };
|
143 | ModalTransitionController.prototype.transitionDuration = function (transitionContext) {
|
144 | var _a, _b, _c, _d, _e, _f;
|
145 | var owner = this.owner.deref();
|
146 | if (owner) {
|
147 | var state = SharedTransition.getState(owner.id);
|
148 | switch (state === null || state === void 0 ? void 0 : state.activeType) {
|
149 | case SharedTransitionAnimationType.present:
|
150 | if (isNumber((_a = state === null || state === void 0 ? void 0 : state.pageEnd) === null || _a === void 0 ? void 0 : _a.duration)) {
|
151 | return ((_b = state.pageEnd) === null || _b === void 0 ? void 0 : _b.duration) / 1000;
|
152 | }
|
153 | else {
|
154 | return getDurationWithDampingFromSpring((_c = state.pageEnd) === null || _c === void 0 ? void 0 : _c.spring).duration;
|
155 | }
|
156 | case SharedTransitionAnimationType.dismiss:
|
157 | if (isNumber((_d = state === null || state === void 0 ? void 0 : state.pageReturn) === null || _d === void 0 ? void 0 : _d.duration)) {
|
158 | return ((_e = state.pageReturn) === null || _e === void 0 ? void 0 : _e.duration) / 1000;
|
159 | }
|
160 | else {
|
161 | return getDurationWithDampingFromSpring((_f = state.pageReturn) === null || _f === void 0 ? void 0 : _f.spring).duration;
|
162 | }
|
163 | }
|
164 | }
|
165 | return CORE_ANIMATION_DEFAULTS.duration;
|
166 | };
|
167 | ModalTransitionController.prototype.animateTransition = function (transitionContext) {
|
168 |
|
169 | var owner = this.owner.deref();
|
170 | if (owner) {
|
171 |
|
172 | var state = SharedTransition.getState(owner.id);
|
173 | if (!state) {
|
174 | return;
|
175 | }
|
176 | SharedTransitionHelper.animate(state, transitionContext, 'modal');
|
177 | }
|
178 | };
|
179 | ModalTransitionController.ObjCProtocols = [UIViewControllerAnimatedTransitioning];
|
180 | return ModalTransitionController;
|
181 | }(NSObject));
|
182 |
|
\ | No newline at end of file |