@nativescript/core 8.5.0-alpha.1 → 8.5.0-alpha.3

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.
Files changed (81) hide show
  1. package/file-system/file-system-access.android.d.ts +13 -0
  2. package/file-system/file-system-access.android.js +141 -0
  3. package/file-system/file-system-access.android.js.map +1 -1
  4. package/file-system/file-system-access.d.ts +12 -0
  5. package/file-system/file-system-access.ios.d.ts +7 -0
  6. package/file-system/file-system-access.ios.js +56 -0
  7. package/file-system/file-system-access.ios.js.map +1 -1
  8. package/package.json +1 -1
  9. package/platforms/android/widgets-release.aar +0 -0
  10. package/ui/core/view/index.android.js +1 -22
  11. package/ui/core/view/index.android.js.map +1 -1
  12. package/ui/core/view/index.ios.js +28 -12
  13. package/ui/core/view/index.ios.js.map +1 -1
  14. package/ui/core/view/view-common.d.ts +4 -0
  15. package/ui/core/view/view-common.js +33 -12
  16. package/ui/core/view/view-common.js.map +1 -1
  17. package/ui/core/view/view-helper/index.ios.d.ts +10 -0
  18. package/ui/core/view/view-helper/index.ios.js +99 -40
  19. package/ui/core/view/view-helper/index.ios.js.map +1 -1
  20. package/ui/core/view-base/index.d.ts +443 -538
  21. package/ui/core/view-base/index.js +150 -5
  22. package/ui/core/view-base/index.js.map +1 -1
  23. package/ui/frame/fragment.transitions.d.ts +0 -4
  24. package/ui/frame/frame-common.d.ts +2 -2
  25. package/ui/frame/frame-common.js +8 -0
  26. package/ui/frame/frame-common.js.map +1 -1
  27. package/ui/frame/index.android.js +2 -4
  28. package/ui/frame/index.android.js.map +1 -1
  29. package/ui/frame/index.ios.js +58 -9
  30. package/ui/frame/index.ios.js.map +1 -1
  31. package/ui/index.d.ts +2 -0
  32. package/ui/index.js +2 -0
  33. package/ui/index.js.map +1 -1
  34. package/ui/page/index.ios.d.ts +4 -1
  35. package/ui/page/index.ios.js +81 -60
  36. package/ui/page/index.ios.js.map +1 -1
  37. package/ui/styling/background.ios.js +3 -0
  38. package/ui/styling/background.ios.js.map +1 -1
  39. package/ui/transition/fade-transition.d.ts +1 -3
  40. package/ui/transition/fade-transition.ios.d.ts +14 -1
  41. package/ui/transition/fade-transition.ios.js +60 -26
  42. package/ui/transition/fade-transition.ios.js.map +1 -1
  43. package/ui/transition/index.android.d.ts +0 -3
  44. package/ui/transition/index.android.js +0 -5
  45. package/ui/transition/index.android.js.map +1 -1
  46. package/ui/transition/index.d.ts +9 -9
  47. package/ui/transition/index.ios.d.ts +0 -3
  48. package/ui/transition/index.ios.js +0 -33
  49. package/ui/transition/index.ios.js.map +1 -1
  50. package/ui/transition/modal-transition.android.d.ts +3 -4
  51. package/ui/transition/modal-transition.android.js +4 -51
  52. package/ui/transition/modal-transition.android.js.map +1 -1
  53. package/ui/transition/modal-transition.ios.d.ts +6 -1
  54. package/ui/transition/modal-transition.ios.js +287 -80
  55. package/ui/transition/modal-transition.ios.js.map +1 -1
  56. package/ui/transition/page-transition.android.d.ts +4 -4
  57. package/ui/transition/page-transition.android.js +44 -33
  58. package/ui/transition/page-transition.android.js.map +1 -1
  59. package/ui/transition/page-transition.ios.d.ts +21 -1
  60. package/ui/transition/page-transition.ios.js +471 -184
  61. package/ui/transition/page-transition.ios.js.map +1 -1
  62. package/ui/transition/shared-transition.d.ts +87 -15
  63. package/ui/transition/shared-transition.js +41 -24
  64. package/ui/transition/shared-transition.js.map +1 -1
  65. package/ui/transition/slide-transition.android.d.ts +1 -1
  66. package/ui/transition/slide-transition.android.js +1 -1
  67. package/ui/transition/slide-transition.android.js.map +1 -1
  68. package/ui/transition/slide-transition.d.ts +1 -1
  69. package/ui/transition/slide-transition.ios.d.ts +15 -2
  70. package/ui/transition/slide-transition.ios.js +86 -52
  71. package/ui/transition/slide-transition.ios.js.map +1 -1
  72. package/utils/native-helper.d.ts +35 -0
  73. package/utils/native-helper.ios.d.ts +13 -0
  74. package/utils/native-helper.ios.js +73 -0
  75. package/utils/native-helper.ios.js.map +1 -1
  76. package/utils/number-utils.d.ts +10 -0
  77. package/utils/number-utils.js +12 -0
  78. package/utils/number-utils.js.map +1 -1
  79. package/ui/frame/fragment.transitions.ios.d.ts +0 -2
  80. package/ui/frame/fragment.transitions.ios.js +0 -71
  81. package/ui/frame/fragment.transitions.ios.js.map +0 -1
@@ -1,202 +1,489 @@
1
- import { Transition, iosMatchLayerProperties, iosSnapshotView, iosPrintRect } from '.';
1
+ import { Transition } from '.';
2
2
  import { Screen } from '../../platform';
3
- import { SharedTransition, SharedTransitionAnimationType, DEFAULT_DURATION } from './shared-transition';
3
+ import { iOSNativeHelper } from '../../utils/native-helper';
4
+ import { isNumber } from '../../utils/types';
5
+ import { GestureStateTypes } from '../gestures';
6
+ import { SharedTransition, SharedTransitionAnimationType, DEFAULT_DURATION, DEFAULT_SPRING } from './shared-transition';
4
7
  export class PageTransition extends Transition {
5
- animateIOSTransition(transitionContext, fromViewCtrl, toViewCtrl, operation) {
6
- console.log('--- PageTransitionController animateTransition');
7
- console.log('toViewCtrl:', toViewCtrl);
8
- console.log('fromViewCtrl:', fromViewCtrl);
9
- // console.log('owner.id:', owner.id);
10
- const state = SharedTransition.getState(this.id);
11
- if (!state) {
12
- return;
8
+ iosNavigatedController(navigationController, operation, fromVC, toVC) {
9
+ this.navigationController = navigationController;
10
+ if (!this.transitionController) {
11
+ this.presented = toVC;
12
+ this.presenting = fromVC;
13
13
  }
14
- console.log('state.activeType:', state.activeType);
15
- console.log('operation:', operation);
16
- // switch (state.activeType) {
17
- switch (operation) {
18
- case 1 /* UINavigationControllerOperation.Push */: {
19
- this.presented = toViewCtrl;
20
- console.log('-- Transition present --', this.presented);
21
- // transitionContext.containerView.addSubview(this.presented.view);
22
- transitionContext.containerView.insertSubviewAboveSubview(this.presented.view, fromViewCtrl.view);
23
- this.presented.view.layoutIfNeeded();
24
- const { sharedElements, presented } = SharedTransition.getSharedElements(state.page, state.toPage);
25
- console.log(' ');
26
- console.log(`1. Found sharedTransitionTags to animate:`, sharedElements.map((v) => v.sharedTransitionTag));
27
- console.log(`2. Take snapshots of shared elements and position them based on presenting view:`);
28
- for (const presentingView of sharedElements) {
29
- if (!this.sharedElements) {
30
- this.sharedElements = {
31
- presented: [],
32
- presenting: [],
33
- };
34
- }
35
- const presentingSharedElement = presentingView.ios;
36
- // console.log('fromTarget instanceof UIImageView:', fromTarget instanceof UIImageView)
37
- // TODO: discuss whether we should check if UIImage/UIImageView type to always snapshot images or if other view types could be duped/added vs. snapshotted
38
- // Note: snapshot may be most efficient/simple
39
- // console.log('---> ', presentingView.sharedTransitionTag, ': ', presentingSharedElement)
40
- const presentedView = presented.find((v) => v.sharedTransitionTag === presentingView.sharedTransitionTag);
41
- const presentedSharedElement = presentedView.ios;
42
- const sharedElementSnapshot = UIImageView.alloc().init(); // WithImage(snapshotView(presentedSharedElement));
43
- // treat images differently...
44
- if (presentedSharedElement instanceof UIImageView) {
45
- // in case the image is loaded async, we need to update the snapshot when it changes
46
- // todo: remove listener on transition end
47
- presentedView.on('imageSourceChange', () => {
48
- sharedElementSnapshot.image = iosSnapshotView(presentedSharedElement);
49
- sharedElementSnapshot.tintColor = presentedSharedElement.tintColor;
50
- });
51
- sharedElementSnapshot.tintColor = presentedSharedElement.tintColor;
52
- sharedElementSnapshot.contentMode = presentedSharedElement.contentMode;
53
- }
54
- iosMatchLayerProperties(sharedElementSnapshot, presentingSharedElement);
55
- sharedElementSnapshot.clipsToBounds = true;
56
- // console.log('---> snapshot: ', sharedElementSnapshot);
57
- const startFrame = presentingSharedElement.convertRectToView(presentingSharedElement.bounds, transitionContext.containerView);
58
- const endFrame = presentedSharedElement.convertRectToView(presentedSharedElement.bounds, transitionContext.containerView);
59
- sharedElementSnapshot.frame = startFrame;
60
- console.log('---> ', presentingView.sharedTransitionTag, ' frame:', iosPrintRect(sharedElementSnapshot.frame));
61
- this.sharedElements.presenting.push({
62
- view: presentingView,
63
- startFrame,
64
- endFrame,
65
- snapshot: sharedElementSnapshot,
66
- startOpacity: presentingView.opacity,
67
- endOpacity: presentedView.opacity,
68
- });
69
- this.sharedElements.presented.push({
70
- view: presentedView,
71
- startFrame: endFrame,
72
- endFrame: startFrame,
73
- startOpacity: presentedView.opacity,
74
- endOpacity: presentingView.opacity,
14
+ this.transitionController = PageTransitionController.initWithOwner(new WeakRef(this));
15
+ // console.log('iosNavigatedController presenting:', this.presenting);
16
+ this.operation = operation;
17
+ return this.transitionController;
18
+ }
19
+ iosInteractionDismiss(animator) {
20
+ // console.log('-- iosInteractionDismiss --');
21
+ this.interactiveController = PercentInteractiveController.initWithOwner(new WeakRef(this));
22
+ return this.interactiveController;
23
+ }
24
+ setupInteractiveGesture(startCallback, view) {
25
+ // console.log(' -- setupInteractiveGesture --');
26
+ this._interactiveStartCallback = startCallback;
27
+ if (!this._interactiveDismissGesture) {
28
+ // console.log('setup but tearing down first!');
29
+ view.off('pan', this._interactiveDismissGesture);
30
+ this._interactiveDismissGesture = this._interactiveDismissGestureHandler.bind(this);
31
+ }
32
+ view.on('pan', this._interactiveDismissGesture);
33
+ this._interactiveGestureTeardown = () => {
34
+ // console.log(`-- TEARDOWN setupInteractiveGesture --`);
35
+ view.off('pan', this._interactiveDismissGesture);
36
+ this._interactiveDismissGesture = null;
37
+ };
38
+ return this._interactiveGestureTeardown;
39
+ }
40
+ _interactiveDismissGestureHandler(args) {
41
+ if (args?.ios?.view) {
42
+ // console.log('this.id:', this.id);
43
+ const state = SharedTransition.getState(this.id);
44
+ const percent = state.interactive?.dismiss?.percentFormula ? state.interactive.dismiss.percentFormula(args) : args.deltaX / (args.ios.view.bounds.size.width / 2);
45
+ if (SharedTransition.DEBUG) {
46
+ console.log('Interactive dismissal percentage:', percent);
47
+ }
48
+ switch (args.state) {
49
+ case GestureStateTypes.began:
50
+ SharedTransition.updateState(this.id, {
51
+ interactiveBegan: true,
52
+ interactiveCancelled: false,
75
53
  });
76
- // set initial opacity to match the source view opacity
77
- sharedElementSnapshot.alpha = presentingView.opacity;
78
- // hide both while animating within the transition context
79
- presentingView.opacity = 0;
80
- presentedView.opacity = 0;
81
- // add snapshot to animate
82
- // transitionContext.containerView.addSubview(sharedElementSnapshot);
83
- transitionContext.containerView.insertSubviewAboveSubview(sharedElementSnapshot, this.presented.view);
84
- }
85
- const cleanupPresent = () => {
86
- for (const presented of this.sharedElements.presented) {
87
- presented.view.opacity = presented.startOpacity;
88
- }
89
- // TODO: Discuss with Igor whether this is necessary
90
- // potential this could help smooth some shared element transitions
91
- UIView.animateWithDurationAnimationsCompletion(0, // Igor: disabled for now, we'll talk about this and decide
92
- () => {
93
- for (const presenting of this.sharedElements.presenting) {
94
- presenting.snapshot.alpha = presenting.endOpacity;
54
+ if (this._interactiveStartCallback) {
55
+ this._interactiveStartCallback();
56
+ }
57
+ break;
58
+ case GestureStateTypes.changed:
59
+ if (percent < 1) {
60
+ if (this.interactiveController) {
61
+ this.interactiveController.updateInteractiveTransition(percent);
95
62
  }
96
- }, () => {
97
- for (const presenting of this.sharedElements.presenting) {
98
- presenting.snapshot.removeFromSuperview();
63
+ }
64
+ break;
65
+ case GestureStateTypes.cancelled:
66
+ case GestureStateTypes.ended:
67
+ if (this.interactiveController) {
68
+ const finishThreshold = isNumber(state.interactive?.dismiss?.finishThreshold) ? state.interactive.dismiss.finishThreshold : 0.5;
69
+ if (percent > finishThreshold) {
70
+ if (this._interactiveGestureTeardown) {
71
+ this._interactiveGestureTeardown();
72
+ this._interactiveGestureTeardown = null;
73
+ }
74
+ this.interactiveController.finishInteractiveTransition();
99
75
  }
100
- SharedTransition.updateState({
101
- id: this.id,
102
- activeType: SharedTransitionAnimationType.dismiss,
103
- });
104
- transitionContext.completeTransition(true);
105
- });
106
- };
107
- const updateFramePresent = () => {
108
- // https://stackoverflow.com/a/27997678/1418981
109
- // In order to have proper layout. Seems mostly needed when presenting.
110
- // For instance during presentation, destination view doesn't account navigation bar height.
111
- // Not sure if best to leave all the time?
112
- // owner.presented.view.setNeedsLayout();
113
- // owner.presented.view.layoutIfNeeded();
114
- console.log('3. Animating shared elements:');
115
- for (const presented of this.sharedElements.presented) {
116
- const presentingMatch = this.sharedElements.presenting.find((v) => v.view.sharedTransitionTag === presented.view.sharedTransitionTag);
117
- // Workaround wrong origin due ongoing layout process.
118
- const updatedEndFrame = presented.view.ios.convertRectToView(presented.view.ios.bounds, transitionContext.containerView);
119
- const correctedEndFrame = CGRectMake(updatedEndFrame.origin.x, updatedEndFrame.origin.y, presentingMatch.endFrame.size.width, presentingMatch.endFrame.size.height);
120
- presentingMatch.snapshot.frame = correctedEndFrame;
121
- // apply view and layer properties to the snapshot view to match the source/presented view
122
- iosMatchLayerProperties(presentingMatch.snapshot, presented.view.ios);
123
- // create a snapshot of the presented view
124
- presentingMatch.snapshot.image = iosSnapshotView(presented.view.ios);
125
- // apply correct alpha
126
- presentingMatch.snapshot.alpha = presentingMatch.endOpacity;
127
- console.log(`---> ${presentingMatch.view.sharedTransitionTag} animate to: `, iosPrintRect(correctedEndFrame));
128
- }
129
- console.log(' ');
130
- };
131
- // starting page properties
132
- this.presented.view.alpha = typeof state.toPageStart?.opacity === 'number' ? state.toPageStart?.opacity : 0;
133
- const startX = typeof state.toPageStart?.x === 'number' ? state.toPageStart?.x : Screen.mainScreen.widthDIPs;
134
- const startY = typeof state.toPageStart?.y === 'number' ? state.toPageStart?.y : 0;
135
- const startWidth = typeof state.toPageStart?.width === 'number' ? state.toPageStart?.width : Screen.mainScreen.widthDIPs;
136
- const startHeight = typeof state.toPageStart?.height === 'number' ? state.toPageStart?.height : Screen.mainScreen.heightDIPs;
137
- this.presented.view.frame = CGRectMake(startX, startY, startWidth, startHeight);
138
- UIView.animateWithDurationDelayUsingSpringWithDampingInitialSpringVelocityOptionsAnimationsCompletion(typeof state.toPageStart?.duration === 'number' ? state.toPageStart?.duration / 1000 : DEFAULT_DURATION, 0, 0.5, 3, 0 /* UIViewAnimationOptions.CurveEaseInOut */, () => {
139
- // animate page properties to the following:
140
- this.presented.view.alpha = typeof state.toPageEnd?.opacity === 'number' ? state.toPageEnd?.opacity : 1;
141
- const endX = typeof state.toPageEnd?.x === 'number' ? state.toPageEnd?.x : 0;
142
- const endY = typeof state.toPageEnd?.y === 'number' ? state.toPageEnd?.y : 0;
143
- const endWidth = typeof state.toPageEnd?.width === 'number' ? state.toPageEnd?.width : Screen.mainScreen.widthDIPs;
144
- const endHeight = typeof state.toPageEnd?.height === 'number' ? state.toPageEnd?.height : Screen.mainScreen.heightDIPs;
145
- this.presented.view.frame = CGRectMake(endX, endY, endWidth, endHeight);
146
- updateFramePresent();
147
- }, () => {
148
- cleanupPresent();
149
- });
150
- break;
76
+ else {
77
+ SharedTransition.updateState(this.id, {
78
+ interactiveCancelled: true,
79
+ });
80
+ this.interactiveController.cancelInteractiveTransition();
81
+ }
82
+ }
83
+ break;
84
+ }
85
+ }
86
+ }
87
+ }
88
+ var PercentInteractiveController = /** @class */ (function (_super) {
89
+ __extends(PercentInteractiveController, _super);
90
+ function PercentInteractiveController() {
91
+ var _this = _super !== null && _super.apply(this, arguments) || this;
92
+ _this.started = false;
93
+ _this.added = false;
94
+ return _this;
95
+ }
96
+ PercentInteractiveController.initWithOwner = function (owner) {
97
+ var ctrl = PercentInteractiveController.new();
98
+ ctrl.owner = owner;
99
+ return ctrl;
100
+ };
101
+ PercentInteractiveController.prototype.startInteractiveTransition = function (transitionContext) {
102
+ var _a;
103
+ // console.log('startInteractiveTransition');
104
+ this.transitionContext = transitionContext;
105
+ if (!this.started) {
106
+ this.started = true;
107
+ var owner = (_a = this.owner) === null || _a === void 0 ? void 0 : _a.deref();
108
+ if (owner) {
109
+ this.transitionContext.containerView.insertSubviewBelowSubview(owner.presenting.view, owner.presented.view);
151
110
  }
152
- case 2 /* UINavigationControllerOperation.Pop */: {
153
- // this.presented = fromViewCtrl;
154
- console.log('-- Transition dismiss --', this.presented);
155
- transitionContext.containerView.insertSubviewBelowSubview(toViewCtrl.view, fromViewCtrl.view);
156
- // console.log('transitionContext.containerView.subviews.count:', transitionContext.containerView.subviews.count);
157
- console.log(' ');
158
- console.log(`1. Dismiss sharedTransitionTags to animate:`, this.sharedElements.presented.map((p) => p.view.sharedTransitionTag));
159
- console.log(`2. Add back previously stored sharedElements to dismiss:`);
160
- for (const p of this.sharedElements.presented) {
111
+ }
112
+ };
113
+ PercentInteractiveController.prototype.updateInteractiveTransition = function (percentComplete) {
114
+ var _a;
115
+ var owner = (_a = this.owner) === null || _a === void 0 ? void 0 : _a.deref();
116
+ if (owner) {
117
+ if (!this.added) {
118
+ this.added = true;
119
+ for (var _i = 0, _b = owner.sharedElements.presented; _i < _b.length; _i++) {
120
+ var p = _b[_i];
161
121
  p.view.opacity = 0;
162
122
  }
163
- for (const p of this.sharedElements.presenting) {
123
+ for (var _c = 0, _d = owner.sharedElements.presenting; _c < _d.length; _c++) {
124
+ var p = _d[_c];
164
125
  p.snapshot.alpha = p.endOpacity;
165
- transitionContext.containerView.addSubview(p.snapshot);
166
- // transitionContext.containerView.insertSubviewBelowSubview(p.snapshot, fromViewCtrl.view);
126
+ this.transitionContext.containerView.addSubview(p.snapshot);
167
127
  }
168
- const cleanupDismiss = () => {
169
- for (const presenting of this.sharedElements.presenting) {
128
+ var state = SharedTransition.getState(owner.id);
129
+ var props_1 = state.fromPageEnd;
130
+ this.backgroundAnimation = UIViewPropertyAnimator.alloc().initWithDurationDampingRatioAnimations(1, 1, function () {
131
+ for (var _i = 0, _a = owner.sharedElements.presenting; _i < _a.length; _i++) {
132
+ var p = _a[_i];
133
+ p.snapshot.frame = p.startFrame;
134
+ iOSNativeHelper.copyLayerProperties(p.snapshot, p.view.ios);
135
+ p.snapshot.alpha = 1;
136
+ }
137
+ owner.presented.view.alpha = isNumber(props_1 === null || props_1 === void 0 ? void 0 : props_1.opacity) ? props_1 === null || props_1 === void 0 ? void 0 : props_1.opacity : 0;
138
+ var endX = isNumber(props_1 === null || props_1 === void 0 ? void 0 : props_1.x) ? props_1 === null || props_1 === void 0 ? void 0 : props_1.x : Screen.mainScreen.widthDIPs;
139
+ var endY = isNumber(props_1 === null || props_1 === void 0 ? void 0 : props_1.y) ? props_1 === null || props_1 === void 0 ? void 0 : props_1.y : 0;
140
+ var endWidth = isNumber(props_1 === null || props_1 === void 0 ? void 0 : props_1.width) ? props_1 === null || props_1 === void 0 ? void 0 : props_1.width : Screen.mainScreen.widthDIPs;
141
+ var endHeight = isNumber(props_1 === null || props_1 === void 0 ? void 0 : props_1.height) ? props_1 === null || props_1 === void 0 ? void 0 : props_1.height : Screen.mainScreen.heightDIPs;
142
+ owner.presented.view.frame = CGRectMake(endX, endY, endWidth, endHeight);
143
+ });
144
+ }
145
+ this.backgroundAnimation.fractionComplete = percentComplete;
146
+ }
147
+ };
148
+ PercentInteractiveController.prototype.cancelInteractiveTransition = function () {
149
+ var _this = this;
150
+ var _a, _b, _c;
151
+ // console.log('cancelInteractiveTransition');
152
+ var owner = (_a = this.owner) === null || _a === void 0 ? void 0 : _a.deref();
153
+ if (owner && this.added) {
154
+ var state = SharedTransition.getState(owner.id);
155
+ if (!state) {
156
+ return;
157
+ }
158
+ if (this.backgroundAnimation) {
159
+ this.backgroundAnimation.reversed = true;
160
+ var duration = isNumber((_b = state.toPageStart) === null || _b === void 0 ? void 0 : _b.duration) ? ((_c = state.toPageStart) === null || _c === void 0 ? void 0 : _c.duration) / 1000 : 0.35;
161
+ this.backgroundAnimation.continueAnimationWithTimingParametersDurationFactor(null, duration);
162
+ setTimeout(function () {
163
+ for (var _i = 0, _a = owner.sharedElements.presented; _i < _a.length; _i++) {
164
+ var p = _a[_i];
165
+ p.view.opacity = 1;
166
+ }
167
+ for (var _b = 0, _c = owner.sharedElements.presenting; _b < _c.length; _b++) {
168
+ var p = _c[_b];
169
+ p.snapshot.removeFromSuperview();
170
+ }
171
+ owner.presented.view.alpha = 1;
172
+ _this.backgroundAnimation = null;
173
+ _this.added = false;
174
+ _this.transitionContext.cancelInteractiveTransition();
175
+ _this.transitionContext.completeTransition(false);
176
+ }, duration * 1000);
177
+ }
178
+ }
179
+ };
180
+ PercentInteractiveController.prototype.finishInteractiveTransition = function () {
181
+ var _this = this;
182
+ var _a, _b, _c;
183
+ // console.log('finishInteractiveTransition');
184
+ var owner = (_a = this.owner) === null || _a === void 0 ? void 0 : _a.deref();
185
+ if (owner && this.added) {
186
+ if (this.backgroundAnimation) {
187
+ this.backgroundAnimation.reversed = false;
188
+ var state = SharedTransition.getState(owner.id);
189
+ if (!state) {
190
+ SharedTransition.finishState(owner.id);
191
+ this.transitionContext.completeTransition(true);
192
+ return;
193
+ }
194
+ var duration = isNumber((_b = state.fromPageEnd) === null || _b === void 0 ? void 0 : _b.duration) ? ((_c = state.fromPageEnd) === null || _c === void 0 ? void 0 : _c.duration) / 1000 : 0.35;
195
+ this.backgroundAnimation.continueAnimationWithTimingParametersDurationFactor(null, duration);
196
+ setTimeout(function () {
197
+ for (var _i = 0, _a = owner.sharedElements.presenting; _i < _a.length; _i++) {
198
+ var presenting = _a[_i];
170
199
  presenting.view.opacity = presenting.startOpacity;
171
200
  presenting.snapshot.removeFromSuperview();
172
201
  }
173
- SharedTransition.finishState(this.id);
174
- transitionContext.completeTransition(true);
175
- };
176
- const updateFrameDismiss = () => {
177
- console.log('3. Dismissing shared elements:');
178
- for (const presenting of this.sharedElements.presenting) {
179
- iosMatchLayerProperties(presenting.snapshot, presenting.view.ios);
180
- presenting.snapshot.frame = presenting.startFrame;
181
- presenting.snapshot.alpha = presenting.startOpacity;
182
- console.log(`---> ${presenting.view.sharedTransitionTag} animate to: `, iosPrintRect(presenting.startFrame));
183
- }
184
- console.log(' ');
185
- };
186
- UIView.animateWithDurationDelayUsingSpringWithDampingInitialSpringVelocityOptionsAnimationsCompletion(typeof state.fromPageEnd?.duration === 'number' ? state.fromPageEnd?.duration / 1000 : DEFAULT_DURATION, 0, 0.5, 3, 0 /* UIViewAnimationOptions.CurveEaseInOut */, () => {
187
- this.presented.view.alpha = typeof state.fromPageEnd?.opacity === 'number' ? state.fromPageEnd?.opacity : 0;
188
- const endX = typeof state.fromPageEnd?.x === 'number' ? state.fromPageEnd?.x : Screen.mainScreen.widthDIPs;
189
- const endY = typeof state.fromPageEnd?.y === 'number' ? state.fromPageEnd?.y : 0;
190
- const endWidth = typeof state.fromPageEnd?.width === 'number' ? state.fromPageEnd?.width : Screen.mainScreen.widthDIPs;
191
- const endHeight = typeof state.fromPageEnd?.height === 'number' ? state.fromPageEnd?.height : Screen.mainScreen.heightDIPs;
192
- this.presented.view.frame = CGRectMake(endX, endY, endWidth, endHeight);
193
- updateFrameDismiss();
194
- }, () => {
195
- cleanupDismiss();
196
- });
197
- break;
202
+ SharedTransition.finishState(owner.id);
203
+ _this.backgroundAnimation = null;
204
+ _this.added = false;
205
+ _this.transitionContext.finishInteractiveTransition();
206
+ _this.transitionContext.completeTransition(true);
207
+ }, duration * 1000);
198
208
  }
199
209
  }
210
+ };
211
+ PercentInteractiveController.ObjCProtocols = [UIViewControllerInteractiveTransitioning];
212
+ return PercentInteractiveController;
213
+ }(UIPercentDrivenInteractiveTransition));
214
+ var PageTransitionController = /** @class */ (function (_super) {
215
+ __extends(PageTransitionController, _super);
216
+ function PageTransitionController() {
217
+ return _super !== null && _super.apply(this, arguments) || this;
200
218
  }
201
- }
219
+ PageTransitionController.initWithOwner = function (owner) {
220
+ var ctrl = PageTransitionController.new();
221
+ ctrl.owner = owner;
222
+ return ctrl;
223
+ };
224
+ PageTransitionController.prototype.transitionDuration = function (transitionContext) {
225
+ var owner = this.owner.deref();
226
+ if (owner) {
227
+ return owner.getDuration();
228
+ }
229
+ return DEFAULT_DURATION;
230
+ };
231
+ PageTransitionController.prototype.animateTransition = function (transitionContext) {
232
+ var owner = this.owner.deref();
233
+ if (owner) {
234
+ // console.log('--- PageTransitionController animateTransition');
235
+ // console.log('owner.presented:', owner.presented);
236
+ // console.log('owner.presenting:', owner.presenting);
237
+ // console.log('owner.id:', owner.id);
238
+ var state_1 = SharedTransition.getState(owner.id);
239
+ if (!state_1) {
240
+ return;
241
+ }
242
+ // console.log('state.activeType:', state.activeType);
243
+ // console.log('operation:', owner.operation);
244
+ // switch (state.activeType) {
245
+ switch (owner.operation) {
246
+ case UINavigationControllerOperation.Push: {
247
+ // console.log('pushing!!');
248
+ // this.presented = toViewCtrl;
249
+ // this.presenting = fromViewCtrl;
250
+ transitionContext.containerView.insertSubviewAboveSubview(owner.presented.view, owner.presenting.view);
251
+ owner.presented.view.layoutIfNeeded();
252
+ var _a = SharedTransition.getSharedElements(state_1.page, state_1.toPage), sharedElements = _a.sharedElements, presented = _a.presented;
253
+ if (SharedTransition.DEBUG) {
254
+ console.log(' PageTransition: Push');
255
+ console.log("1. Found sharedTransitionTags to animate:", sharedElements.map(function (v) { return v.sharedTransitionTag; }));
256
+ console.log("2. Take snapshots of shared elements and position them based on presenting view:");
257
+ }
258
+ var _loop_1 = function (presentingView) {
259
+ if (!owner.sharedElements) {
260
+ owner.sharedElements = {
261
+ presented: [],
262
+ presenting: [],
263
+ };
264
+ }
265
+ var presentingSharedElement = presentingView.ios;
266
+ // TODO: discuss whether we should check if UIImage/UIImageView type to always snapshot images or if other view types could be duped/added vs. snapshotted
267
+ // Note: snapshot may be most efficient/simple
268
+ // console.log('---> ', presentingView.sharedTransitionTag, ': ', presentingSharedElement)
269
+ var presentedView = presented.find(function (v) { return v.sharedTransitionTag === presentingView.sharedTransitionTag; });
270
+ var presentedSharedElement = presentedView.ios;
271
+ var sharedElementSnapshot = UIImageView.alloc().init(); // WithImage(snapshotView(presentedSharedElement));
272
+ // treat images differently...
273
+ if (presentedSharedElement instanceof UIImageView) {
274
+ // in case the image is loaded async, we need to update the snapshot when it changes
275
+ // todo: remove listener on transition end
276
+ presentedView.on('imageSourceChange', function () {
277
+ sharedElementSnapshot.image = iOSNativeHelper.snapshotView(presentedSharedElement, Screen.mainScreen.scale);
278
+ sharedElementSnapshot.tintColor = presentedSharedElement.tintColor;
279
+ });
280
+ sharedElementSnapshot.tintColor = presentedSharedElement.tintColor;
281
+ sharedElementSnapshot.contentMode = presentedSharedElement.contentMode;
282
+ }
283
+ iOSNativeHelper.copyLayerProperties(sharedElementSnapshot, presentingSharedElement);
284
+ sharedElementSnapshot.clipsToBounds = true;
285
+ // console.log('---> snapshot: ', sharedElementSnapshot);
286
+ var startFrame = presentingSharedElement.convertRectToView(presentingSharedElement.bounds, transitionContext.containerView);
287
+ var endFrame = presentedSharedElement.convertRectToView(presentedSharedElement.bounds, transitionContext.containerView);
288
+ sharedElementSnapshot.frame = startFrame;
289
+ if (SharedTransition.DEBUG) {
290
+ console.log('---> ', presentingView.sharedTransitionTag, ' frame:', iOSNativeHelper.printCGRect(sharedElementSnapshot.frame));
291
+ }
292
+ owner.sharedElements.presenting.push({
293
+ view: presentingView,
294
+ startFrame: startFrame,
295
+ endFrame: endFrame,
296
+ snapshot: sharedElementSnapshot,
297
+ startOpacity: presentingView.opacity,
298
+ endOpacity: presentedView.opacity,
299
+ });
300
+ owner.sharedElements.presented.push({
301
+ view: presentedView,
302
+ startFrame: endFrame,
303
+ endFrame: startFrame,
304
+ startOpacity: presentedView.opacity,
305
+ endOpacity: presentingView.opacity,
306
+ });
307
+ // set initial opacity to match the source view opacity
308
+ sharedElementSnapshot.alpha = presentingView.opacity;
309
+ // hide both while animating within the transition context
310
+ presentingView.opacity = 0;
311
+ presentedView.opacity = 0;
312
+ // add snapshot to animate
313
+ transitionContext.containerView.addSubview(sharedElementSnapshot);
314
+ };
315
+ for (var _i = 0, sharedElements_1 = sharedElements; _i < sharedElements_1.length; _i++) {
316
+ var presentingView = sharedElements_1[_i];
317
+ _loop_1(presentingView);
318
+ }
319
+ var cleanupPresent_1 = function () {
320
+ for (var _i = 0, _a = owner.sharedElements.presented; _i < _a.length; _i++) {
321
+ var presented_1 = _a[_i];
322
+ presented_1.view.opacity = presented_1.startOpacity;
323
+ }
324
+ for (var _b = 0, _c = owner.sharedElements.presenting; _b < _c.length; _b++) {
325
+ var presenting = _c[_b];
326
+ presenting.snapshot.removeFromSuperview();
327
+ }
328
+ SharedTransition.updateState(owner.id, {
329
+ activeType: SharedTransitionAnimationType.dismiss,
330
+ });
331
+ owner.presenting.view.removeFromSuperview();
332
+ transitionContext.completeTransition(true);
333
+ };
334
+ var updateFramePresent_1 = function () {
335
+ // https://stackoverflow.com/a/27997678/1418981
336
+ // In order to have proper layout. Seems mostly needed when presenting.
337
+ // For instance during presentation, destination view doesn't account navigation bar height.
338
+ // Not sure if best to leave all the time?
339
+ // owner.presented.view.setNeedsLayout();
340
+ // owner.presented.view.layoutIfNeeded();
341
+ if (SharedTransition.DEBUG) {
342
+ console.log('3. Animating shared elements:');
343
+ }
344
+ var _loop_2 = function (presented_2) {
345
+ var presentingMatch = owner.sharedElements.presenting.find(function (v) { return v.view.sharedTransitionTag === presented_2.view.sharedTransitionTag; });
346
+ // Workaround wrong origin due ongoing layout process.
347
+ var updatedEndFrame = presented_2.view.ios.convertRectToView(presented_2.view.ios.bounds, transitionContext.containerView);
348
+ var correctedEndFrame = CGRectMake(updatedEndFrame.origin.x, updatedEndFrame.origin.y, presentingMatch.endFrame.size.width, presentingMatch.endFrame.size.height);
349
+ presentingMatch.snapshot.frame = correctedEndFrame;
350
+ // apply view and layer properties to the snapshot view to match the source/presented view
351
+ iOSNativeHelper.copyLayerProperties(presentingMatch.snapshot, presented_2.view.ios);
352
+ // create a snapshot of the presented view
353
+ presentingMatch.snapshot.image = iOSNativeHelper.snapshotView(presented_2.view.ios, Screen.mainScreen.scale);
354
+ // apply correct alpha
355
+ presentingMatch.snapshot.alpha = presentingMatch.endOpacity;
356
+ if (SharedTransition.DEBUG) {
357
+ console.log("---> ".concat(presentingMatch.view.sharedTransitionTag, " animate to: "), iOSNativeHelper.printCGRect(correctedEndFrame));
358
+ }
359
+ };
360
+ for (var _i = 0, _a = owner.sharedElements.presented; _i < _a.length; _i++) {
361
+ var presented_2 = _a[_i];
362
+ _loop_2(presented_2);
363
+ }
364
+ };
365
+ // starting page properties
366
+ var toProps = state_1.toPageStart;
367
+ owner.presented.view.alpha = isNumber(toProps === null || toProps === void 0 ? void 0 : toProps.opacity) ? toProps === null || toProps === void 0 ? void 0 : toProps.opacity : 0;
368
+ var startX = isNumber(toProps === null || toProps === void 0 ? void 0 : toProps.x) ? toProps === null || toProps === void 0 ? void 0 : toProps.x : Screen.mainScreen.widthDIPs;
369
+ var startY = isNumber(toProps === null || toProps === void 0 ? void 0 : toProps.y) ? toProps === null || toProps === void 0 ? void 0 : toProps.y : 0;
370
+ var startWidth = isNumber(toProps === null || toProps === void 0 ? void 0 : toProps.width) ? toProps === null || toProps === void 0 ? void 0 : toProps.width : Screen.mainScreen.widthDIPs;
371
+ var startHeight = isNumber(toProps === null || toProps === void 0 ? void 0 : toProps.height) ? toProps === null || toProps === void 0 ? void 0 : toProps.height : Screen.mainScreen.heightDIPs;
372
+ owner.presented.view.frame = CGRectMake(startX, startY, startWidth, startHeight);
373
+ var animateProperties_1 = function () {
374
+ var props = state_1.toPageEnd;
375
+ // animate page properties to the following:
376
+ owner.presented.view.alpha = isNumber(props === null || props === void 0 ? void 0 : props.opacity) ? props === null || props === void 0 ? void 0 : props.opacity : 1;
377
+ var endX = isNumber(props === null || props === void 0 ? void 0 : props.x) ? props === null || props === void 0 ? void 0 : props.x : 0;
378
+ var endY = isNumber(props === null || props === void 0 ? void 0 : props.y) ? props === null || props === void 0 ? void 0 : props.y : 0;
379
+ var endWidth = isNumber(props === null || props === void 0 ? void 0 : props.width) ? props === null || props === void 0 ? void 0 : props.width : Screen.mainScreen.widthDIPs;
380
+ var endHeight = isNumber(props === null || props === void 0 ? void 0 : props.height) ? props === null || props === void 0 ? void 0 : props.height : Screen.mainScreen.heightDIPs;
381
+ owner.presented.view.frame = CGRectMake(endX, endY, endWidth, endHeight);
382
+ };
383
+ if (isNumber(toProps === null || toProps === void 0 ? void 0 : toProps.duration)) {
384
+ // override spring and use only linear animation
385
+ UIView.animateWithDurationAnimationsCompletion((toProps === null || toProps === void 0 ? void 0 : toProps.duration) / 1000, function () {
386
+ animateProperties_1();
387
+ updateFramePresent_1();
388
+ }, function () {
389
+ cleanupPresent_1();
390
+ });
391
+ }
392
+ else {
393
+ var spring = toProps === null || toProps === void 0 ? void 0 : toProps.spring;
394
+ iOSNativeHelper.animateWithSpring({
395
+ tension: isNumber(spring === null || spring === void 0 ? void 0 : spring.tension) ? spring === null || spring === void 0 ? void 0 : spring.tension : DEFAULT_SPRING.tension,
396
+ friction: isNumber(spring === null || spring === void 0 ? void 0 : spring.friction) ? spring === null || spring === void 0 ? void 0 : spring.tension : DEFAULT_SPRING.friction,
397
+ animations: function () {
398
+ animateProperties_1();
399
+ updateFramePresent_1();
400
+ },
401
+ completion: function () {
402
+ cleanupPresent_1();
403
+ },
404
+ });
405
+ }
406
+ break;
407
+ }
408
+ case UINavigationControllerOperation.Pop: {
409
+ // console.log('popping!');
410
+ transitionContext.containerView.insertSubviewBelowSubview(owner.presenting.view, owner.presented.view);
411
+ // console.log('transitionContext.containerView.subviews.count:', transitionContext.containerView.subviews.count);
412
+ if (SharedTransition.DEBUG) {
413
+ console.log(' PageTransition: Pop');
414
+ console.log("1. Dismiss sharedTransitionTags to animate:", owner.sharedElements.presented.map(function (p) { return p.view.sharedTransitionTag; }));
415
+ console.log("2. Add back previously stored sharedElements to dismiss:");
416
+ }
417
+ for (var _b = 0, _c = owner.sharedElements.presented; _b < _c.length; _b++) {
418
+ var p = _c[_b];
419
+ p.view.opacity = 0;
420
+ }
421
+ for (var _d = 0, _e = owner.sharedElements.presenting; _d < _e.length; _d++) {
422
+ var p = _e[_d];
423
+ p.snapshot.alpha = p.endOpacity;
424
+ transitionContext.containerView.addSubview(p.snapshot);
425
+ }
426
+ var cleanupDismiss_1 = function () {
427
+ for (var _i = 0, _a = owner.sharedElements.presenting; _i < _a.length; _i++) {
428
+ var presenting = _a[_i];
429
+ presenting.view.opacity = presenting.startOpacity;
430
+ presenting.snapshot.removeFromSuperview();
431
+ }
432
+ SharedTransition.finishState(owner.id);
433
+ transitionContext.completeTransition(true);
434
+ };
435
+ var updateFrameDismiss_1 = function () {
436
+ if (SharedTransition.DEBUG) {
437
+ console.log('3. Dismissing shared elements:');
438
+ }
439
+ for (var _i = 0, _a = owner.sharedElements.presenting; _i < _a.length; _i++) {
440
+ var presenting = _a[_i];
441
+ iOSNativeHelper.copyLayerProperties(presenting.snapshot, presenting.view.ios);
442
+ presenting.snapshot.frame = presenting.startFrame;
443
+ presenting.snapshot.alpha = presenting.startOpacity;
444
+ if (SharedTransition.DEBUG) {
445
+ console.log("---> ".concat(presenting.view.sharedTransitionTag, " animate to: "), iOSNativeHelper.printCGRect(presenting.startFrame));
446
+ }
447
+ }
448
+ };
449
+ var props_1 = state_1.fromPageEnd;
450
+ var animateProperties_2 = function () {
451
+ owner.presented.view.alpha = isNumber(props_1 === null || props_1 === void 0 ? void 0 : props_1.opacity) ? props_1 === null || props_1 === void 0 ? void 0 : props_1.opacity : 0;
452
+ var endX = isNumber(props_1 === null || props_1 === void 0 ? void 0 : props_1.x) ? props_1 === null || props_1 === void 0 ? void 0 : props_1.x : Screen.mainScreen.widthDIPs;
453
+ var endY = isNumber(props_1 === null || props_1 === void 0 ? void 0 : props_1.y) ? props_1 === null || props_1 === void 0 ? void 0 : props_1.y : 0;
454
+ var endWidth = isNumber(props_1 === null || props_1 === void 0 ? void 0 : props_1.width) ? props_1 === null || props_1 === void 0 ? void 0 : props_1.width : Screen.mainScreen.widthDIPs;
455
+ var endHeight = isNumber(props_1 === null || props_1 === void 0 ? void 0 : props_1.height) ? props_1 === null || props_1 === void 0 ? void 0 : props_1.height : Screen.mainScreen.heightDIPs;
456
+ owner.presented.view.frame = CGRectMake(endX, endY, endWidth, endHeight);
457
+ };
458
+ if (isNumber(props_1 === null || props_1 === void 0 ? void 0 : props_1.duration)) {
459
+ // override spring and use only linear animation
460
+ UIView.animateWithDurationAnimationsCompletion((props_1 === null || props_1 === void 0 ? void 0 : props_1.duration) / 1000, function () {
461
+ animateProperties_2();
462
+ updateFrameDismiss_1();
463
+ }, function () {
464
+ cleanupDismiss_1();
465
+ });
466
+ }
467
+ else {
468
+ var spring = props_1 === null || props_1 === void 0 ? void 0 : props_1.spring;
469
+ iOSNativeHelper.animateWithSpring({
470
+ tension: isNumber(spring === null || spring === void 0 ? void 0 : spring.tension) ? spring === null || spring === void 0 ? void 0 : spring.tension : DEFAULT_SPRING.tension,
471
+ friction: isNumber(spring === null || spring === void 0 ? void 0 : spring.friction) ? spring === null || spring === void 0 ? void 0 : spring.tension : DEFAULT_SPRING.friction,
472
+ animations: function () {
473
+ animateProperties_2();
474
+ updateFrameDismiss_1();
475
+ },
476
+ completion: function () {
477
+ cleanupDismiss_1();
478
+ },
479
+ });
480
+ }
481
+ break;
482
+ }
483
+ }
484
+ }
485
+ };
486
+ PageTransitionController.ObjCProtocols = [UIViewControllerAnimatedTransitioning];
487
+ return PageTransitionController;
488
+ }(NSObject));
202
489
  //# sourceMappingURL=page-transition.ios.js.map