Merge pull request #1483 from NativeScript/feature/proxy-container-layout-fix

Fixed ios proxy view blocks layout requests
This commit is contained in:
Alexander Vakrilov
2016-02-04 10:30:06 +02:00
7 changed files with 140 additions and 16 deletions

View File

@@ -22,7 +22,7 @@ export class Border extends contentView.ContentView implements definition.Border
var density = utils.layout.getDisplayDensity();
var borderSize = (2 * this.borderWidth) * density;
var result = viewModule.View.measureChild(this, this.content,
var result = viewModule.View.measureChild(this, this.layoutView,
utils.layout.makeMeasureSpec(width - borderSize, widthMode),
utils.layout.makeMeasureSpec(height - borderSize, heightMode));
@@ -35,6 +35,6 @@ export class Border extends contentView.ContentView implements definition.Border
public onLayout(left: number, top: number, right: number, bottom: number): void {
var density = utils.layout.getDisplayDensity();
var borderSize = this.borderWidth * density;
viewModule.View.layoutChild(this, this.content, borderSize, borderSize, right - left - borderSize, bottom - top - borderSize);
viewModule.View.layoutChild(this, this.layoutView, borderSize, borderSize, right - left - borderSize, bottom - top - borderSize);
}
}

View File

@@ -24,5 +24,7 @@ declare module "ui/content-view" {
//@endprivate
_addChildFromBuilder(name: string, value: any): void;
layoutView: view.View;
}
}

View File

@@ -23,6 +23,24 @@ export class ContentView extends view.CustomLayoutView implements definition.Con
this._onContentChanged(oldView, value);
}
get layoutView(): view.View {
var result: view.View;
if (this._content) {
let first = true;
this._content._eachLayoutView((child) => {
if (first) {
first = false;
result = child;
} else {
throw new Error("More than one layout child inside a ContentView");
}
});
}
return result;
}
get _childrenCount(): number {
if (this._content) {
return 1;
@@ -49,7 +67,7 @@ export class ContentView extends view.CustomLayoutView implements definition.Con
// This method won't be called in Android because we use the native android layout.
public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void {
var result = view.View.measureChild(this, this.content, widthMeasureSpec, heightMeasureSpec);
var result = view.View.measureChild(this, this.layoutView, widthMeasureSpec, heightMeasureSpec);
var width = utils.layout.getMeasureSpecSize(widthMeasureSpec);
var widthMode = utils.layout.getMeasureSpecMode(widthMeasureSpec);
@@ -69,6 +87,6 @@ export class ContentView extends view.CustomLayoutView implements definition.Con
// This method won't be called in Android because we use the native android layout.
public onLayout(left: number, top: number, right: number, bottom: number): void {
view.View.layoutChild(this, this.content, 0, 0, right - left, bottom - top);
view.View.layoutChild(this, this.layoutView, 0, 0, right - left, bottom - top);
}
}

View File

@@ -276,7 +276,7 @@ export class Page extends pageCommon.Page {
let heightSpec = utils.layout.makeMeasureSpec(height - actionBarHeight - statusBarHeight, heightMode);
// Measure content with height - navigationBarHeight. Here we could use actionBarSize.measuredHeight probably.
let result = View.measureChild(this, this.content, widthMeasureSpec, heightSpec);
let result = View.measureChild(this, this.layoutView, widthMeasureSpec, heightSpec);
let measureWidth = Math.max(actionBarWidth, result.measuredWidth, this.minWidth);
let measureHeight = Math.max(result.measuredHeight + actionBarHeight, this.minHeight);
@@ -307,7 +307,7 @@ export class Page extends pageCommon.Page {
statusBarHeight = 0;
}
View.layoutChild(this, this.content, 0, navigationBarHeight + statusBarHeight, right - left, bottom - top);
View.layoutChild(this, this.layoutView, 0, navigationBarHeight + statusBarHeight, right - left, bottom - top);
}
public _addViewToNativeVisualTree(view: View): boolean {

View File

@@ -18,18 +18,23 @@ import {LayoutBase} from "ui/layouts/layout-base";
// - Android: _onDetached calls _removeViewFromNativeVisualTree recursively when the proxy is removed from its parent.
export class ProxyViewContainer extends LayoutBase implements definition.ProxyViewContainer {
// No native view for proxy container.
get ios(): any {
return null;
get ios(): any {
return null;
}
get android(): any {
return null;
}
get _nativeView(): any {
return null;
}
get isLayoutRequested(): boolean {
// Always return false so all layout requests from children bubble up.
return false;
}
public _createUI() {
//
}
@@ -70,7 +75,7 @@ export class ProxyViewContainer extends LayoutBase implements definition.ProxyVi
// Add last;
insideIndex = this._getNativeViewsCount();
}
trace.write("ProxyViewContainer._addViewToNativeVisualTree at: " + atIndex + " base: " + baseIndex + " additional: " + insideIndex, trace.categories.ViewHierarchy);
return parent._addViewToNativeVisualTree(child, baseIndex + insideIndex);
}

View File

@@ -109,7 +109,7 @@ export class ScrollView extends common.ScrollView implements definition.ScrollVi
var heightMode = utils.layout.getMeasureSpecMode(heightMeasureSpec);
var density = utils.layout.getDisplayDensity();
var child = this.content
var child = this.layoutView;
if (!child) {
this._contentMeasuredWidth = this.minWidth * density;
this._contentMeasuredHeight = this.minHeight * density;
@@ -140,10 +140,10 @@ export class ScrollView extends common.ScrollView implements definition.ScrollVi
var height = (bottom - top);
if (this.orientation === enums.Orientation.horizontal) {
view.View.layoutChild(this, this.content, 0, 0, Math.max(this._contentMeasuredWidth, width), height);
view.View.layoutChild(this, this.layoutView, 0, 0, Math.max(this._contentMeasuredWidth, width), height);
}
else {
view.View.layoutChild(this, this.content, 0, 0, width, Math.max(this._contentMeasuredHeight, height));
view.View.layoutChild(this, this.layoutView, 0, 0, width, Math.max(this._contentMeasuredHeight, height));
}
}
}