mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
chore: cleanup
This commit is contained in:
@ -5,7 +5,7 @@ import { View } from '../ui';
|
||||
import { Builder } from '../ui/builder';
|
||||
import { IOSHelper } from '../ui/core/view/view-helper';
|
||||
import { NavigationEntry } from '../ui/frame/frame-interfaces';
|
||||
import * as Utils from '../utils/';
|
||||
import * as Utils from '../utils';
|
||||
import type { iOSApplication as IiOSApplication } from './';
|
||||
import { ApplicationCommon } from './application-common';
|
||||
import {
|
||||
@ -82,10 +82,6 @@ class Responder extends UIResponder implements UIApplicationDelegate {
|
||||
}
|
||||
|
||||
export class iOSApplication extends ApplicationCommon implements IiOSApplication {
|
||||
private _backgroundColor =
|
||||
Utils.ios.MajorVersion <= 12 || !UIColor.systemBackgroundColor
|
||||
? UIColor.whiteColor
|
||||
: UIColor.systemBackgroundColor;
|
||||
private _delegate: UIApplicationDelegate;
|
||||
private _window: UIWindow;
|
||||
private _notificationObservers: NotificationObserver[] = [];
|
||||
@ -468,7 +464,10 @@ export class iOSApplication extends ApplicationCommon implements IiOSApplication
|
||||
this._window = UIWindow.alloc().initWithFrame(UIScreen.mainScreen.bounds);
|
||||
|
||||
// TODO: Expose Window module so that it can we styled from XML & CSS
|
||||
this._window.backgroundColor = this._backgroundColor;
|
||||
this._window.backgroundColor =
|
||||
Utils.ios.MajorVersion <= 12 || !UIColor.systemBackgroundColor
|
||||
? UIColor.whiteColor
|
||||
: UIColor.systemBackgroundColor;
|
||||
|
||||
this.notifyAppStarted(notification);
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ import {
|
||||
FileSystemAccess,
|
||||
FileSystemAccess29,
|
||||
} from './file-system-access';
|
||||
import { SDK_VERSION } from '../utils/constants';
|
||||
import { SDK_VERSION } from '../utils';
|
||||
import { Application } from '../application';
|
||||
|
||||
// The FileSystemAccess implementation, used through all the APIs.
|
||||
|
@ -1,7 +1,13 @@
|
||||
// @ts-nocheck
|
||||
global.__DEV__ = true;
|
||||
global.WeakRef.prototype.get = global.WeakRef.prototype.deref;
|
||||
global.NativeClass = function () {};
|
||||
global.NSObject = class NSObject {};
|
||||
global.NSTimer = class NSTimer {};
|
||||
global.NSObject = class NSObject {
|
||||
static new() {
|
||||
return new NSObject();
|
||||
}
|
||||
};
|
||||
global.NSString = {
|
||||
stringWithString() {
|
||||
return {
|
||||
@ -22,6 +28,16 @@ global.NSFileManager = {
|
||||
},
|
||||
},
|
||||
};
|
||||
global.NSNotificationCenter = {
|
||||
defaultCenter: {
|
||||
addObserverSelectorNameObject(
|
||||
observer: any,
|
||||
selector: any,
|
||||
name: any,
|
||||
object: any
|
||||
) {},
|
||||
},
|
||||
};
|
||||
global.interop = {
|
||||
Reference: class Reference {
|
||||
constructor(type: any, ref?: boolean) {}
|
||||
@ -96,6 +112,17 @@ global.NativeScriptGlobals = {
|
||||
global.CADisplayLink = function () {};
|
||||
global.NSNotification = function () {};
|
||||
global.UIApplicationDelegate = function () {};
|
||||
global.UIApplicationDidFinishLaunchingNotification =
|
||||
'UIApplicationDidFinishLaunchingNotification';
|
||||
global.UIApplicationDidBecomeActiveNotification =
|
||||
'UIApplicationDidBecomeActiveNotification';
|
||||
global.UIApplicationDidEnterBackgroundNotification =
|
||||
'UIApplicationDidEnterBackgroundNotification';
|
||||
global.UIApplicationWillTerminateNotification = 'UIApplicationWillTerminateNotification';
|
||||
global.UIApplicationDidReceiveMemoryWarningNotification =
|
||||
'UIApplicationDidReceiveMemoryWarningNotification';
|
||||
global.UIApplicationDidChangeStatusBarOrientationNotification =
|
||||
'UIApplicationDidChangeStatusBarOrientationNotification';
|
||||
global.UIResponder = function () {};
|
||||
global.UIResponder.extend = function () {};
|
||||
global.UIViewController = function () {};
|
||||
|
@ -3,13 +3,11 @@ import { View } from '..';
|
||||
|
||||
// Requires
|
||||
import { ViewHelper } from './view-helper-common';
|
||||
import { iOSNativeHelper, layout } from '../../../../utils';
|
||||
import { ios as iOSUtils, layout } from '../../../../utils';
|
||||
import { Trace } from '../../../../trace';
|
||||
|
||||
export * from './view-helper-common';
|
||||
|
||||
const majorVersion = iOSNativeHelper.MajorVersion;
|
||||
|
||||
@NativeClass
|
||||
class UILayoutViewController extends UIViewController {
|
||||
public owner: WeakRef<View>;
|
||||
@ -41,7 +39,7 @@ class UILayoutViewController extends UIViewController {
|
||||
super.viewDidLayoutSubviews();
|
||||
const owner = this.owner?.deref();
|
||||
if (owner) {
|
||||
if (majorVersion >= 11) {
|
||||
if (iOSUtils.MajorVersion >= 11) {
|
||||
// Handle nested UILayoutViewController safe area application.
|
||||
// Currently, UILayoutViewController can be nested only in a TabView.
|
||||
// The TabView itself is handled by the OS, so we check the TabView's parent (usually a Page, but can be a Layout).
|
||||
@ -70,7 +68,10 @@ class UILayoutViewController extends UIViewController {
|
||||
}
|
||||
|
||||
const additionalInsetsTop = Math.max(parentPageInsetsTop - currentInsetsTop, 0);
|
||||
const additionalInsetsBottom = Math.max(parentPageInsetsBottom - currentInsetsBottom, 0);
|
||||
const additionalInsetsBottom = Math.max(
|
||||
parentPageInsetsBottom - currentInsetsBottom,
|
||||
0
|
||||
);
|
||||
|
||||
if (additionalInsetsTop > 0 || additionalInsetsBottom > 0) {
|
||||
const additionalInsets = new UIEdgeInsets({
|
||||
@ -116,9 +117,15 @@ class UILayoutViewController extends UIViewController {
|
||||
public traitCollectionDidChange(previousTraitCollection: UITraitCollection): void {
|
||||
super.traitCollectionDidChange(previousTraitCollection);
|
||||
|
||||
if (majorVersion >= 13) {
|
||||
if (iOSUtils.MajorVersion >= 13) {
|
||||
const owner = this.owner?.deref();
|
||||
if (owner && this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection && this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection(previousTraitCollection)) {
|
||||
if (
|
||||
owner &&
|
||||
this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection &&
|
||||
this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection(
|
||||
previousTraitCollection
|
||||
)
|
||||
) {
|
||||
owner.notify({
|
||||
eventName: IOSHelper.traitCollectionColorAppearanceChangedEvent,
|
||||
object: owner,
|
||||
@ -129,13 +136,19 @@ class UILayoutViewController extends UIViewController {
|
||||
}
|
||||
|
||||
@NativeClass
|
||||
class UIAdaptivePresentationControllerDelegateImp extends NSObject implements UIAdaptivePresentationControllerDelegate {
|
||||
class UIAdaptivePresentationControllerDelegateImp
|
||||
extends NSObject
|
||||
implements UIAdaptivePresentationControllerDelegate
|
||||
{
|
||||
public static ObjCProtocols = [UIAdaptivePresentationControllerDelegate];
|
||||
|
||||
private owner: WeakRef<View>;
|
||||
private closedCallback: Function;
|
||||
|
||||
public static initWithOwnerAndCallback(owner: WeakRef<View>, whenClosedCallback: Function): UIAdaptivePresentationControllerDelegateImp {
|
||||
public static initWithOwnerAndCallback(
|
||||
owner: WeakRef<View>,
|
||||
whenClosedCallback: Function
|
||||
): UIAdaptivePresentationControllerDelegateImp {
|
||||
const instance = <UIAdaptivePresentationControllerDelegateImp>super.new();
|
||||
instance.owner = owner;
|
||||
instance.closedCallback = whenClosedCallback;
|
||||
@ -143,7 +156,9 @@ class UIAdaptivePresentationControllerDelegateImp extends NSObject implements UI
|
||||
return instance;
|
||||
}
|
||||
|
||||
public presentationControllerDidDismiss(presentationController: UIPresentationController) {
|
||||
public presentationControllerDidDismiss(
|
||||
presentationController: UIPresentationController
|
||||
) {
|
||||
const owner = this.owner?.deref();
|
||||
if (owner && typeof this.closedCallback === 'function') {
|
||||
this.closedCallback();
|
||||
@ -152,13 +167,19 @@ class UIAdaptivePresentationControllerDelegateImp extends NSObject implements UI
|
||||
}
|
||||
|
||||
@NativeClass
|
||||
class UIPopoverPresentationControllerDelegateImp extends NSObject implements UIPopoverPresentationControllerDelegate {
|
||||
class UIPopoverPresentationControllerDelegateImp
|
||||
extends NSObject
|
||||
implements UIPopoverPresentationControllerDelegate
|
||||
{
|
||||
public static ObjCProtocols = [UIPopoverPresentationControllerDelegate];
|
||||
|
||||
private owner: WeakRef<View>;
|
||||
private closedCallback: Function;
|
||||
|
||||
public static initWithOwnerAndCallback(owner: WeakRef<View>, whenClosedCallback: Function): UIPopoverPresentationControllerDelegateImp {
|
||||
public static initWithOwnerAndCallback(
|
||||
owner: WeakRef<View>,
|
||||
whenClosedCallback: Function
|
||||
): UIPopoverPresentationControllerDelegateImp {
|
||||
const instance = <UIPopoverPresentationControllerDelegateImp>super.new();
|
||||
instance.owner = owner;
|
||||
instance.closedCallback = whenClosedCallback;
|
||||
@ -166,7 +187,9 @@ class UIPopoverPresentationControllerDelegateImp extends NSObject implements UIP
|
||||
return instance;
|
||||
}
|
||||
|
||||
public popoverPresentationControllerDidDismissPopover(popoverPresentationController: UIPopoverPresentationController) {
|
||||
public popoverPresentationControllerDidDismissPopover(
|
||||
popoverPresentationController: UIPopoverPresentationController
|
||||
) {
|
||||
const owner = this.owner?.deref();
|
||||
if (owner && typeof this.closedCallback === 'function') {
|
||||
this.closedCallback();
|
||||
@ -175,10 +198,13 @@ class UIPopoverPresentationControllerDelegateImp extends NSObject implements UIP
|
||||
}
|
||||
|
||||
export class IOSHelper {
|
||||
static traitCollectionColorAppearanceChangedEvent = 'traitCollectionColorAppearanceChanged';
|
||||
static traitCollectionColorAppearanceChangedEvent =
|
||||
'traitCollectionColorAppearanceChanged';
|
||||
static UILayoutViewController = UILayoutViewController;
|
||||
static UIAdaptivePresentationControllerDelegateImp = UIAdaptivePresentationControllerDelegateImp;
|
||||
static UIPopoverPresentationControllerDelegateImp = UIPopoverPresentationControllerDelegateImp;
|
||||
static UIAdaptivePresentationControllerDelegateImp =
|
||||
UIAdaptivePresentationControllerDelegateImp;
|
||||
static UIPopoverPresentationControllerDelegateImp =
|
||||
UIPopoverPresentationControllerDelegateImp;
|
||||
|
||||
static getParentWithViewController(view: View): View {
|
||||
while (view && !view.viewController) {
|
||||
@ -190,7 +216,7 @@ export class IOSHelper {
|
||||
}
|
||||
|
||||
static updateAutoAdjustScrollInsets(controller: UIViewController, owner: View): void {
|
||||
if (majorVersion <= 10) {
|
||||
if (iOSUtils.MajorVersion <= 10) {
|
||||
owner._automaticallyAdjustsScrollViewInsets = false;
|
||||
// This API is deprecated, but has no alternative for <= iOS 10
|
||||
// Defaults to true and results to appliyng the insets twice together with our logic
|
||||
@ -201,7 +227,7 @@ export class IOSHelper {
|
||||
}
|
||||
|
||||
static updateConstraints(controller: UIViewController, owner: View): void {
|
||||
if (majorVersion <= 10) {
|
||||
if (iOSUtils.MajorVersion <= 10) {
|
||||
const layoutGuide = IOSHelper.initLayoutGuide(controller);
|
||||
(<any>controller.view).safeAreaLayoutGuide = layoutGuide;
|
||||
}
|
||||
@ -211,7 +237,16 @@ export class IOSHelper {
|
||||
const rootView = controller.view;
|
||||
const layoutGuide = UILayoutGuide.new();
|
||||
rootView.addLayoutGuide(layoutGuide);
|
||||
NSLayoutConstraint.activateConstraints(<any>[layoutGuide.topAnchor.constraintEqualToAnchor(controller.topLayoutGuide.bottomAnchor), layoutGuide.bottomAnchor.constraintEqualToAnchor(controller.bottomLayoutGuide.topAnchor), layoutGuide.leadingAnchor.constraintEqualToAnchor(rootView.leadingAnchor), layoutGuide.trailingAnchor.constraintEqualToAnchor(rootView.trailingAnchor)]);
|
||||
NSLayoutConstraint.activateConstraints(<any>[
|
||||
layoutGuide.topAnchor.constraintEqualToAnchor(
|
||||
controller.topLayoutGuide.bottomAnchor
|
||||
),
|
||||
layoutGuide.bottomAnchor.constraintEqualToAnchor(
|
||||
controller.bottomLayoutGuide.topAnchor
|
||||
),
|
||||
layoutGuide.leadingAnchor.constraintEqualToAnchor(rootView.leadingAnchor),
|
||||
layoutGuide.trailingAnchor.constraintEqualToAnchor(rootView.trailingAnchor),
|
||||
]);
|
||||
|
||||
return layoutGuide;
|
||||
}
|
||||
@ -219,7 +254,11 @@ export class IOSHelper {
|
||||
static layoutView(controller: UIViewController, owner: View): void {
|
||||
let layoutGuide = controller.view.safeAreaLayoutGuide;
|
||||
if (!layoutGuide) {
|
||||
Trace.write(`safeAreaLayoutGuide during layout of ${owner}. Creating fallback constraints, but layout might be wrong.`, Trace.categories.Layout, Trace.messageType.error);
|
||||
Trace.write(
|
||||
`safeAreaLayoutGuide during layout of ${owner}. Creating fallback constraints, but layout might be wrong.`,
|
||||
Trace.categories.Layout,
|
||||
Trace.messageType.error
|
||||
);
|
||||
|
||||
layoutGuide = IOSHelper.initLayoutGuide(controller);
|
||||
}
|
||||
@ -240,7 +279,14 @@ export class IOSHelper {
|
||||
const heightSpec = layout.makeMeasureSpec(safeAreaHeight, layout.EXACTLY);
|
||||
|
||||
ViewHelper.measureChild(null, owner, widthSpec, heightSpec);
|
||||
ViewHelper.layoutChild(null, owner, position.left, position.top, position.right, position.bottom);
|
||||
ViewHelper.layoutChild(
|
||||
null,
|
||||
owner,
|
||||
position.left,
|
||||
position.top,
|
||||
position.right,
|
||||
position.bottom
|
||||
);
|
||||
|
||||
if (owner.parent) {
|
||||
owner.parent._layoutParent();
|
||||
@ -251,18 +297,27 @@ export class IOSHelper {
|
||||
const left = layout.round(layout.toDevicePixels(frame.origin.x));
|
||||
const top = layout.round(layout.toDevicePixels(frame.origin.y));
|
||||
const right = layout.round(layout.toDevicePixels(frame.origin.x + frame.size.width));
|
||||
const bottom = layout.round(layout.toDevicePixels(frame.origin.y + frame.size.height));
|
||||
const bottom = layout.round(
|
||||
layout.toDevicePixels(frame.origin.y + frame.size.height)
|
||||
);
|
||||
|
||||
return { left, right, top, bottom };
|
||||
}
|
||||
|
||||
static getFrameFromPosition(position: { left; top; right; bottom }, insets?: { left; top; right; bottom }): CGRect {
|
||||
static getFrameFromPosition(
|
||||
position: { left; top; right; bottom },
|
||||
insets?: { left; top; right; bottom }
|
||||
): CGRect {
|
||||
insets = insets || { left: 0, top: 0, right: 0, bottom: 0 };
|
||||
|
||||
const left = layout.toDeviceIndependentPixels(position.left + insets.left);
|
||||
const top = layout.toDeviceIndependentPixels(position.top + insets.top);
|
||||
const width = layout.toDeviceIndependentPixels(position.right - position.left - insets.left - insets.right);
|
||||
const height = layout.toDeviceIndependentPixels(position.bottom - position.top - insets.top - insets.bottom);
|
||||
const width = layout.toDeviceIndependentPixels(
|
||||
position.right - position.left - insets.left - insets.right
|
||||
);
|
||||
const height = layout.toDeviceIndependentPixels(
|
||||
position.bottom - position.top - insets.top - insets.bottom
|
||||
);
|
||||
|
||||
return CGRectMake(left, top, width, height);
|
||||
}
|
||||
@ -274,7 +329,12 @@ export class IOSHelper {
|
||||
const adjustedFrame = IOSHelper.getFrameFromPosition(position, insets);
|
||||
|
||||
if (Trace.isEnabled()) {
|
||||
Trace.write(`${view} :shrinkToSafeArea: ${JSON.stringify(IOSHelper.getPositionFromFrame(adjustedFrame))}`, Trace.categories.Layout);
|
||||
Trace.write(
|
||||
`${view} :shrinkToSafeArea: ${JSON.stringify(
|
||||
IOSHelper.getPositionFromFrame(adjustedFrame)
|
||||
)}`,
|
||||
Trace.categories.Layout
|
||||
);
|
||||
}
|
||||
|
||||
return adjustedFrame;
|
||||
@ -304,24 +364,43 @@ export class IOSHelper {
|
||||
adjustedPosition.top = fullscreenPosition.top;
|
||||
}
|
||||
|
||||
if (inWindowPosition.right < fullscreenPosition.right && inWindowPosition.right >= safeAreaPosition.right + fullscreenPosition.left) {
|
||||
if (
|
||||
inWindowPosition.right < fullscreenPosition.right &&
|
||||
inWindowPosition.right >= safeAreaPosition.right + fullscreenPosition.left
|
||||
) {
|
||||
adjustedPosition.right += fullscreenPosition.right - inWindowPosition.right;
|
||||
}
|
||||
|
||||
if (inWindowPosition.bottom < fullscreenPosition.bottom && inWindowPosition.bottom >= safeAreaPosition.bottom + fullscreenPosition.top) {
|
||||
if (
|
||||
inWindowPosition.bottom < fullscreenPosition.bottom &&
|
||||
inWindowPosition.bottom >= safeAreaPosition.bottom + fullscreenPosition.top
|
||||
) {
|
||||
adjustedPosition.bottom += fullscreenPosition.bottom - inWindowPosition.bottom;
|
||||
}
|
||||
|
||||
const adjustedFrame = CGRectMake(layout.toDeviceIndependentPixels(adjustedPosition.left), layout.toDeviceIndependentPixels(adjustedPosition.top), layout.toDeviceIndependentPixels(adjustedPosition.right - adjustedPosition.left), layout.toDeviceIndependentPixels(adjustedPosition.bottom - adjustedPosition.top));
|
||||
const adjustedFrame = CGRectMake(
|
||||
layout.toDeviceIndependentPixels(adjustedPosition.left),
|
||||
layout.toDeviceIndependentPixels(adjustedPosition.top),
|
||||
layout.toDeviceIndependentPixels(adjustedPosition.right - adjustedPosition.left),
|
||||
layout.toDeviceIndependentPixels(adjustedPosition.bottom - adjustedPosition.top)
|
||||
);
|
||||
|
||||
if (Trace.isEnabled()) {
|
||||
Trace.write(view + ' :expandBeyondSafeArea: ' + JSON.stringify(IOSHelper.getPositionFromFrame(adjustedFrame)), Trace.categories.Layout);
|
||||
Trace.write(
|
||||
view +
|
||||
' :expandBeyondSafeArea: ' +
|
||||
JSON.stringify(IOSHelper.getPositionFromFrame(adjustedFrame)),
|
||||
Trace.categories.Layout
|
||||
);
|
||||
}
|
||||
|
||||
return adjustedFrame;
|
||||
}
|
||||
|
||||
static getAvailableSpaceFromParent(view: View, frame: CGRect): { safeArea: CGRect; fullscreen: CGRect; inWindow: CGRect } {
|
||||
static getAvailableSpaceFromParent(
|
||||
view: View,
|
||||
frame: CGRect
|
||||
): { safeArea: CGRect; fullscreen: CGRect; inWindow: CGRect } {
|
||||
if (!view) {
|
||||
return;
|
||||
}
|
||||
@ -333,7 +412,11 @@ export class IOSHelper {
|
||||
viewControllerView = view.viewController.view;
|
||||
} else {
|
||||
let parent = view.parent as View;
|
||||
while (parent && !parent.viewController && !(parent.nativeViewProtected instanceof UIScrollView)) {
|
||||
while (
|
||||
parent &&
|
||||
!parent.viewController &&
|
||||
!(parent.nativeViewProtected instanceof UIScrollView)
|
||||
) {
|
||||
parent = parent.parent as View;
|
||||
}
|
||||
|
||||
@ -351,11 +434,24 @@ export class IOSHelper {
|
||||
if (viewControllerView) {
|
||||
safeArea = viewControllerView.safeAreaLayoutGuide.layoutFrame;
|
||||
fullscreen = viewControllerView.frame;
|
||||
controllerInWindow = viewControllerView.convertPointToView(viewControllerView.bounds.origin, null);
|
||||
controllerInWindow = viewControllerView.convertPointToView(
|
||||
viewControllerView.bounds.origin,
|
||||
null
|
||||
);
|
||||
} else if (scrollView) {
|
||||
const insets = scrollView.safeAreaInsets;
|
||||
safeArea = CGRectMake(insets.left, insets.top, scrollView.contentSize.width - insets.left - insets.right, scrollView.contentSize.height - insets.top - insets.bottom);
|
||||
fullscreen = CGRectMake(0, 0, scrollView.contentSize.width, scrollView.contentSize.height);
|
||||
safeArea = CGRectMake(
|
||||
insets.left,
|
||||
insets.top,
|
||||
scrollView.contentSize.width - insets.left - insets.right,
|
||||
scrollView.contentSize.height - insets.top - insets.bottom
|
||||
);
|
||||
fullscreen = CGRectMake(
|
||||
0,
|
||||
0,
|
||||
scrollView.contentSize.width,
|
||||
scrollView.contentSize.height
|
||||
);
|
||||
}
|
||||
|
||||
// We take into account the controller position inside the window.
|
||||
@ -369,7 +465,12 @@ export class IOSHelper {
|
||||
inWindowTop += scrollView.contentOffset.y;
|
||||
}
|
||||
|
||||
const inWindow = CGRectMake(inWindowLeft, inWindowTop, frame.size.width, frame.size.height);
|
||||
const inWindow = CGRectMake(
|
||||
inWindowLeft,
|
||||
inWindowTop,
|
||||
frame.size.width,
|
||||
frame.size.height
|
||||
);
|
||||
|
||||
return {
|
||||
safeArea: safeArea,
|
||||
|
@ -1,8 +1,11 @@
|
||||
import type { Transition, TransitionNavigationType, SharedTransitionTagPropertiesToMatch } from '.';
|
||||
import type {
|
||||
Transition,
|
||||
TransitionNavigationType,
|
||||
SharedTransitionTagPropertiesToMatch,
|
||||
} from '.';
|
||||
import { Observable } from '../../data/observable';
|
||||
import { Screen } from '../../platform';
|
||||
import { isNumber } from '../../utils/types';
|
||||
import { CORE_ANIMATION_DEFAULTS } from '../../utils/common';
|
||||
import { isNumber, CORE_ANIMATION_DEFAULTS } from '../../utils';
|
||||
import { querySelectorAll, ViewBase } from '../core/view-base';
|
||||
import type { View } from '../core/view';
|
||||
import type { PanGestureEventData } from '../gestures';
|
||||
@ -12,9 +15,21 @@ export enum SharedTransitionAnimationType {
|
||||
present,
|
||||
dismiss,
|
||||
}
|
||||
type SharedTransitionEventAction = 'present' | 'dismiss' | 'interactiveStart' | 'interactiveFinish';
|
||||
export type SharedTransitionEventDataPayload = { id: number; type: TransitionNavigationType; action?: SharedTransitionEventAction; percent?: number };
|
||||
export type SharedTransitionEventData = { eventName: string; data: SharedTransitionEventDataPayload };
|
||||
type SharedTransitionEventAction =
|
||||
| 'present'
|
||||
| 'dismiss'
|
||||
| 'interactiveStart'
|
||||
| 'interactiveFinish';
|
||||
export type SharedTransitionEventDataPayload = {
|
||||
id: number;
|
||||
type: TransitionNavigationType;
|
||||
action?: SharedTransitionEventAction;
|
||||
percent?: number;
|
||||
};
|
||||
export type SharedTransitionEventData = {
|
||||
eventName: string;
|
||||
data: SharedTransitionEventDataPayload;
|
||||
};
|
||||
export type SharedRect = { x?: number; y?: number; width?: number; height?: number };
|
||||
export type SharedProperties = SharedRect & {
|
||||
opacity?: number;
|
||||
@ -138,7 +153,11 @@ export interface SharedTransitionState extends SharedTransitionConfig {
|
||||
}
|
||||
class SharedTransitionObservable extends Observable {
|
||||
// @ts-ignore
|
||||
on(eventNames: string, callback: (data: SharedTransitionEventData) => void, thisArg?: any) {
|
||||
on(
|
||||
eventNames: string,
|
||||
callback: (data: SharedTransitionEventData) => void,
|
||||
thisArg?: any
|
||||
) {
|
||||
super.on(eventNames, <any>callback, thisArg);
|
||||
}
|
||||
}
|
||||
@ -156,7 +175,10 @@ export class SharedTransition {
|
||||
* @param options
|
||||
* @returns a configured SharedTransition instance for use with navigational APIs.
|
||||
*/
|
||||
static custom(transition: Transition, options?: SharedTransitionConfig): { instance: Transition } {
|
||||
static custom(
|
||||
transition: Transition,
|
||||
options?: SharedTransitionConfig
|
||||
): { instance: Transition } {
|
||||
SharedTransition.updateState(transition.id, {
|
||||
...(options || {}),
|
||||
instance: transition,
|
||||
@ -282,11 +304,19 @@ export class SharedTransition {
|
||||
presenting: Array<View>;
|
||||
} {
|
||||
// 1. Presented view: gather all sharedTransitionTag views
|
||||
const presentedSharedElements = <Array<View>>querySelectorAll(toPage, 'sharedTransitionTag').filter((v) => !v.sharedTransitionIgnore && typeof v.sharedTransitionTag === 'string');
|
||||
const presentedSharedElements = <Array<View>>(
|
||||
querySelectorAll(toPage, 'sharedTransitionTag').filter(
|
||||
(v) => !v.sharedTransitionIgnore && typeof v.sharedTransitionTag === 'string'
|
||||
)
|
||||
);
|
||||
// console.log('presented sharedTransitionTag total:', presentedSharedElements.length);
|
||||
|
||||
// 2. Presenting view: gather all sharedTransitionTag views
|
||||
const presentingSharedElements = <Array<View>>querySelectorAll(fromPage, 'sharedTransitionTag').filter((v) => !v.sharedTransitionIgnore && typeof v.sharedTransitionTag === 'string');
|
||||
const presentingSharedElements = <Array<View>>(
|
||||
querySelectorAll(fromPage, 'sharedTransitionTag').filter(
|
||||
(v) => !v.sharedTransitionIgnore && typeof v.sharedTransitionTag === 'string'
|
||||
)
|
||||
);
|
||||
// console.log(
|
||||
// 'presenting sharedTransitionTags:',
|
||||
// presentingSharedElements.map((v) => v.sharedTransitionTag)
|
||||
@ -295,7 +325,9 @@ export class SharedTransition {
|
||||
// 3. only handle sharedTransitionTag on presenting which match presented
|
||||
const presentedTags = presentedSharedElements.map((v) => v.sharedTransitionTag);
|
||||
return {
|
||||
sharedElements: presentingSharedElements.filter((v) => presentedTags.includes(v.sharedTransitionTag)),
|
||||
sharedElements: presentingSharedElements.filter((v) =>
|
||||
presentedTags.includes(v.sharedTransitionTag)
|
||||
),
|
||||
presented: presentedSharedElements,
|
||||
presenting: presentingSharedElements,
|
||||
};
|
||||
@ -308,7 +340,10 @@ export class SharedTransition {
|
||||
* @param defaults fallback properties when props doesn't contain a value for it
|
||||
* @returns { x,y,width,height }
|
||||
*/
|
||||
export function getRectFromProps(props: SharedTransitionPageProperties, defaults?: SharedRect): SharedRect {
|
||||
export function getRectFromProps(
|
||||
props: SharedTransitionPageProperties,
|
||||
defaults?: SharedRect
|
||||
): SharedRect {
|
||||
defaults = {
|
||||
x: 0,
|
||||
y: 0,
|
||||
@ -331,10 +366,16 @@ export function getRectFromProps(props: SharedTransitionPageProperties, defaults
|
||||
*/
|
||||
export function getSpringFromProps(props: SharedSpringProperties) {
|
||||
return {
|
||||
tension: isNumber(props?.tension) ? props?.tension : CORE_ANIMATION_DEFAULTS.spring.tension,
|
||||
friction: isNumber(props?.friction) ? props?.friction : CORE_ANIMATION_DEFAULTS.spring.friction,
|
||||
tension: isNumber(props?.tension)
|
||||
? props?.tension
|
||||
: CORE_ANIMATION_DEFAULTS.spring.tension,
|
||||
friction: isNumber(props?.friction)
|
||||
? props?.friction
|
||||
: CORE_ANIMATION_DEFAULTS.spring.friction,
|
||||
mass: isNumber(props?.mass) ? props?.mass : CORE_ANIMATION_DEFAULTS.spring.mass,
|
||||
velocity: isNumber(props?.velocity) ? props?.velocity : CORE_ANIMATION_DEFAULTS.spring.velocity,
|
||||
velocity: isNumber(props?.velocity)
|
||||
? props?.velocity
|
||||
: CORE_ANIMATION_DEFAULTS.spring.velocity,
|
||||
delay: isNumber(props?.delay) ? props?.delay : 0,
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user