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