diff --git a/ui/core/view.d.ts b/ui/core/view.d.ts index ee59508a3..d9a058331 100644 --- a/ui/core/view.d.ts +++ b/ui/core/view.d.ts @@ -502,6 +502,7 @@ declare module "ui/core/view" { _goToVisualState(state: string); _nativeView: any; _isVisible: boolean; + _setNativeViewFrame(nativeView: UIView, frame: CGRect): void; //@endprivate } diff --git a/ui/core/view.ios.ts b/ui/core/view.ios.ts index 608dfac9a..ddd8af3e6 100644 --- a/ui/core/view.ios.ts +++ b/ui/core/view.ios.ts @@ -232,13 +232,20 @@ export class View extends viewCommon.View { // } + public _setNativeViewFrame(nativeView: UIView, frame: CGRect) { + if (!CGRectEqualToRect(nativeView.frame, frame)) { + trace.write(this + ", Native setFrame: = " + NSStringFromCGRect(frame), trace.categories.Layout); + nativeView.frame = frame; + var boundsOrigin = nativeView.bounds.origin; + nativeView.bounds = CGRectMake(boundsOrigin.x, boundsOrigin.y, frame.size.width, frame.size.height); + } + } + public layoutNativeView(left: number, top: number, right: number, bottom: number): void { if (!this._nativeView) { return; } - var frame = CGRectMake(left, top, right - left, bottom - top); - // This is done because when rotated in iOS7 there is rotation applied on the first subview on the Window which is our frame.nativeView.view. // If we set it it should be transformed so it is correct. // When in landscape in iOS 7 there is transformation on the first subview of the window so we set frame to its subview. @@ -252,12 +259,8 @@ export class View extends viewCommon.View { nativeView = this._nativeView; } - if (!CGRectEqualToRect(nativeView.frame, frame)) { - trace.write(this + ", Native setFrame: = " + NSStringFromCGRect(frame), trace.categories.Layout); - nativeView.frame = frame; - var boundsOrigin = nativeView.bounds.origin; - nativeView.bounds = CGRectMake(boundsOrigin.x, boundsOrigin.y, frame.size.width, frame.size.height); - } + var frame = CGRectMake(left, top, right - left, bottom - top); + this._setNativeViewFrame(nativeView, frame); } public _updateLayout() { diff --git a/ui/frame/frame.ios.ts b/ui/frame/frame.ios.ts index e617bdc90..7d1a51980 100644 --- a/ui/frame/frame.ios.ts +++ b/ui/frame/frame.ios.ts @@ -233,6 +233,17 @@ export class Frame extends frameCommon.Frame { var navigationBar = this._ios.controller.navigationBar; return (navigationBar && !this._ios.controller.navigationBarHidden) ? navigationBar.frame.size.height : 0; } + + public _setNativeViewFrame(nativeView: UIView, frame: CGRect) { + // HACK: The plugin https://github.com/hackiftekhar/IQKeyboardManager offsets our Frame's 'nativeView.frame.origin.y' + // to a negative value so the currently focused TextField/TextView is always on the screen while the soft keyboard is showing. + // Our Frame always wants to have an origin of {0, 0}, so if someone else has been playing with origin.x or origin.y do not bring it back to {0, 0}. + if (nativeView.frame.size.width === frame.size.width && nativeView.frame.size.height === frame.size.height) { + return; + } + + super._setNativeViewFrame(nativeView, frame); + } } class UINavigationControllerImpl extends UINavigationController implements UINavigationControllerDelegate {