Merge pull request #1040 from NativeScript/frame.origin.y

Patch for IQKeyboardManager issue.
This commit is contained in:
Rossen Hristov
2015-11-06 09:42:57 +02:00
4 changed files with 27 additions and 8 deletions

View File

@ -1120,4 +1120,8 @@ export class View extends proxy.ProxyObject implements definition.View {
return this.typeName;
}
public _setNativeViewFrame(nativeView: any, frame: any) {
//
}
}

1
ui/core/view.d.ts vendored
View File

@ -502,6 +502,7 @@ declare module "ui/core/view" {
_goToVisualState(state: string);
_nativeView: any;
_isVisible: boolean;
_setNativeViewFrame(nativeView: any, frame: any): void;
//@endprivate
}

View File

@ -232,13 +232,20 @@ export class View extends viewCommon.View {
//
}
public _setNativeViewFrame(nativeView: any, frame: any) {
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() {

View File

@ -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: any, frame: any) {
// 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 {