move frame position conversion methods to ios namespace

This commit is contained in:
Martin Yankov
2018-08-24 18:13:21 +03:00
parent 5b2f8c7248
commit 50a6073f33
3 changed files with 29 additions and 47 deletions

View File

@@ -884,14 +884,6 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
return undefined;
}
public getPositionFromFrame(frame: any): { left, top, right, bottom } {
return undefined;
}
public getFrameFromPosition(position: { left, top, right, bottom }, insets?: { left, top }): any {
return undefined;
}
public getLocationInWindow(): Point {
return undefined;
}

View File

@@ -531,16 +531,6 @@ export abstract class View extends ViewBase {
*/
public getSafeAreaInsets(): { left, top, right, bottom };
/**
* Transforms iOS CGRect to a position object with left, top, right and bottom.
*/
public getPositionFromFrame(frame: any): { left, top, right, bottom };
/**
* Transforms a position object with left, top, right and bottom to an iOS CGRect.
*/
public getFrameFromPosition(position: { left, top, right, bottom }, insets?: { left, top }): any;
/**
* Returns the location of this view in the window coordinate system.
*/

View File

@@ -98,7 +98,7 @@ export class View extends ViewCommon {
// on iOS 11+ it is possible to have a changed layout frame due to safe area insets
// get the frame and adjust the position, so that onLayout works correctly
const frame = this.nativeViewProtected.frame;
position = this.getPositionFromFrame(frame);
position = ios.getPositionFromFrame(frame);
}
this.onLayout(position.left, position.top, position.right, position.bottom);
@@ -192,7 +192,7 @@ export class View extends ViewCommon {
}
const nativeView = this.nativeViewProtected;
const frame = this.getFrameFromPosition({ left, top, right, bottom });
const frame = ios.getFrameFromPosition({ left, top, right, bottom });
this._setNativeViewFrame(nativeView, frame);
}
@@ -229,8 +229,8 @@ export class View extends ViewCommon {
const insets = this.getSafeAreaInsets();
if (insets.left || insets.top) {
const position = this.getPositionFromFrame(frame);
const adjustedFrame = this.getFrameFromPosition(position, insets);
const position = ios.getPositionFromFrame(frame);
const adjustedFrame = ios.getFrameFromPosition(position, insets);
return adjustedFrame;
}
} else {
@@ -243,9 +243,9 @@ export class View extends ViewCommon {
const onScreenLeft = layout.round(layout.toDevicePixels(locationOnScreen.x));
const onScreenTop = layout.round(layout.toDevicePixels(locationOnScreen.y));
const position = this.getPositionFromFrame(frame);
const safeAreaPosition = this.getPositionFromFrame(safeArea);
const fullscreenPosition = this.getPositionFromFrame(fullscreen);
const position = ios.getPositionFromFrame(frame);
const safeAreaPosition = ios.getPositionFromFrame(safeArea);
const fullscreenPosition = ios.getPositionFromFrame(fullscreen);
const adjustedPosition = position;
@@ -287,26 +287,6 @@ export class View extends ViewCommon {
return insets;
}
public getPositionFromFrame(frame: CGRect): { left, top, right, bottom } {
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));
return { left, right, top, bottom };
}
public 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.round(layout.toDeviceIndependentPixels(position.left + insets.left));
const top = layout.round(layout.toDeviceIndependentPixels(position.top + insets.top));
const width = layout.round(layout.toDeviceIndependentPixels(position.right - position.left - insets.left - insets.right));
const height = layout.round(layout.toDeviceIndependentPixels(position.bottom - position.top - insets.top - insets.bottom));
return CGRectMake(left, top, width, height);
}
public getLocationInWindow(): Point {
if (!this.nativeViewProtected || !this.nativeViewProtected.window) {
return undefined;
@@ -772,13 +752,13 @@ export namespace ios {
layoutGuide = initLayoutGuide(controller);
}
const safeArea = layoutGuide.layoutFrame;
let position = owner.getPositionFromFrame(safeArea);
let position = ios.getPositionFromFrame(safeArea);
const safeAreaSize = safeArea.size;
const hasChildViewControllers = controller.childViewControllers.count > 0;
if (hasChildViewControllers) {
const fullscreen = controller.view.frame;
position = owner.getPositionFromFrame(fullscreen);
position = ios.getPositionFromFrame(fullscreen);
}
const safeAreaWidth = layout.round(layout.toDevicePixels(safeAreaSize.width));
@@ -793,6 +773,26 @@ export namespace ios {
layoutParent(owner.parent);
}
export function getPositionFromFrame(frame: CGRect): { left, top, right, bottom } {
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));
return { left, right, top, bottom };
}
export function 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.round(layout.toDeviceIndependentPixels(position.left + insets.left));
const top = layout.round(layout.toDeviceIndependentPixels(position.top + insets.top));
const width = layout.round(layout.toDeviceIndependentPixels(position.right - position.left - insets.left - insets.right));
const height = layout.round(layout.toDeviceIndependentPixels(position.bottom - position.top - insets.top - insets.bottom));
return CGRectMake(left, top, width, height);
}
function layoutParent(view: ViewBase): void {
if (!view) {
return;