View.prototype.onMeasure = function (widthMeasureSpec, heightMeasureSpec) {
     var view = this._nativeView;
     var nativeWidth = 0;
     var nativeHeight = 0;
     if (view) {
         var width = utils.layout.getMeasureSpecSize(widthMeasureSpec);
         var widthMode = utils.layout.getMeasureSpecMode(widthMeasureSpec);
         var height = utils.layout.getMeasureSpecSize(heightMeasureSpec);
         var heightMode = utils.layout.getMeasureSpecMode(heightMeasureSpec);
         if (widthMode === utils.layout.UNSPECIFIED) {
             width = Number.POSITIVE_INFINITY;
         }
         if (heightMode === utils.layout.UNSPECIFIED) {
             height = Number.POSITIVE_INFINITY;
         }
         var nativeSize = view.sizeThatFits(CGSizeMake(width, height));
         nativeWidth = nativeSize.width;
         nativeHeight = nativeSize.height;
     }
     var measureWidth = Math.max(nativeWidth, this.minWidth);
     var measureHeight = Math.max(nativeHeight, this.minHeight);
     var widthAndState = View.resolveSizeAndState(measureWidth, width, widthMode, 0);
     var heightAndState = View.resolveSizeAndState(measureHeight, height, heightMode, 0);
     this.setMeasuredDimension(widthAndState, heightAndState);
 };
示例#2
0
 Image.prototype.onMeasure = function (widthMeasureSpec, heightMeasureSpec) {
     var utils = require("utils/utils");
     var width = utils.layout.getMeasureSpecSize(widthMeasureSpec);
     var widthMode = utils.layout.getMeasureSpecMode(widthMeasureSpec);
     var height = utils.layout.getMeasureSpecSize(heightMeasureSpec);
     var heightMode = utils.layout.getMeasureSpecMode(heightMeasureSpec);
     var nativeWidth = this.imageSource ? this.imageSource.width : 0;
     var nativeHeight = this.imageSource ? this.imageSource.height : 0;
     var measureWidth = Math.max(nativeWidth, this.minWidth);
     var measureHeight = Math.max(nativeHeight, this.minHeight);
     var finiteWidth = widthMode !== utils.layout.UNSPECIFIED;
     var finiteHeight = heightMode !== utils.layout.UNSPECIFIED;
     if (nativeWidth !== 0 && nativeHeight !== 0 && (finiteWidth || finiteHeight)) {
         var scale = Image.computeScaleFactor(width, height, finiteWidth, finiteHeight, nativeWidth, nativeHeight, this.stretch);
         var resultW = Math.floor(nativeWidth * scale.width);
         var resultH = Math.floor(nativeHeight * scale.height);
         measureWidth = finiteWidth ? Math.min(resultW, width) : resultW;
         measureHeight = finiteHeight ? Math.min(resultH, height) : resultH;
         var trace = require("trace");
         trace.write("Image stretch: " + this.stretch +
             ", nativeWidth: " + nativeWidth +
             ", nativeHeight: " + nativeHeight, trace.categories.Layout);
     }
     var view = require("ui/core/view");
     var widthAndState = view.View.resolveSizeAndState(measureWidth, width, widthMode, 0);
     var heightAndState = view.View.resolveSizeAndState(measureHeight, height, heightMode, 0);
     this.setMeasuredDimension(widthAndState, heightAndState);
 };
 Image.prototype.onMeasure = function (widthMeasureSpec, heightMeasureSpec) {
     var width = utils.layout.getMeasureSpecSize(widthMeasureSpec);
     var widthMode = utils.layout.getMeasureSpecMode(widthMeasureSpec);
     var height = utils.layout.getMeasureSpecSize(heightMeasureSpec);
     var heightMode = utils.layout.getMeasureSpecMode(heightMeasureSpec);
     var nativeWidth = this.imageSource ? this.imageSource.width : 0;
     var nativeHeight = this.imageSource ? this.imageSource.height : 0;
     var measureWidth = Math.max(nativeWidth, this.minWidth);
     var measureHeight = Math.max(nativeHeight, this.minHeight);
     var finiteWidth = widthMode !== utils.layout.UNSPECIFIED;
     var finiteHeight = heightMode !== utils.layout.UNSPECIFIED;
     this._imageSourceAffectsLayout = widthMode !== utils.layout.EXACTLY || heightMode !== utils.layout.EXACTLY;
     if (nativeWidth !== 0 && nativeHeight !== 0 && (finiteWidth || finiteHeight)) {
         var scale = Image.computeScaleFactor(width, height, finiteWidth, finiteHeight, nativeWidth, nativeHeight, this.stretch);
         var resultW = Math.round(nativeWidth * scale.width);
         var resultH = Math.round(nativeHeight * scale.height);
         measureWidth = finiteWidth ? Math.min(resultW, width) : resultW;
         measureHeight = finiteHeight ? Math.min(resultH, height) : resultH;
         if (trace.enabled) {
             trace.write("Image stretch: " + this.stretch +
                 ", nativeWidth: " + nativeWidth +
                 ", nativeHeight: " + nativeHeight, trace.categories.Layout);
         }
     }
     var widthAndState = Image.resolveSizeAndState(measureWidth, width, widthMode, 0);
     var heightAndState = Image.resolveSizeAndState(measureHeight, height, heightMode, 0);
     this.setMeasuredDimension(widthAndState, heightAndState);
 };
示例#4
0
 Page.prototype.onMeasure = function (widthMeasureSpec, heightMeasureSpec) {
     var width = utils.layout.getMeasureSpecSize(widthMeasureSpec);
     var widthMode = utils.layout.getMeasureSpecMode(widthMeasureSpec);
     var height = utils.layout.getMeasureSpecSize(heightMeasureSpec);
     var heightMode = utils.layout.getMeasureSpecMode(heightMeasureSpec);
     var actionBarWidth = 0;
     var actionBarHeight = 0;
     var statusBarHeight = this.backgroundSpanUnderStatusBar ? uiUtils.ios.getStatusBarHeight() : 0;
     if (this.frame && this.frame.parent) {
         statusBarHeight = 0;
     }
     if (this._isModal && this._UIModalPresentationFormSheet && platform_1.device.deviceType === enums_1.DeviceType.Tablet) {
         statusBarHeight = 0;
     }
     if (this.frame && this.frame._getNavBarVisible(this)) {
         var actionBarSize = view_1.View.measureChild(this, this.actionBar, widthMeasureSpec, heightMeasureSpec);
         actionBarWidth = actionBarSize.measuredWidth;
         actionBarHeight = actionBarSize.measuredHeight;
     }
     var heightSpec = utils.layout.makeMeasureSpec(height - actionBarHeight - statusBarHeight, heightMode);
     var result = view_1.View.measureChild(this, this.layoutView, widthMeasureSpec, heightSpec);
     var measureWidth = Math.max(actionBarWidth, result.measuredWidth, this.minWidth);
     var measureHeight = Math.max(result.measuredHeight + actionBarHeight, this.minHeight);
     var widthAndState = view_1.View.resolveSizeAndState(measureWidth, width, widthMode, 0);
     var heightAndState = view_1.View.resolveSizeAndState(measureHeight, height, heightMode, 0);
     this.setMeasuredDimension(widthAndState, heightAndState);
 };
 Label.prototype.onMeasure = function (widthMeasureSpec, heightMeasureSpec) {
     var nativeView = this._nativeView;
     if (nativeView) {
         var width = utils.layout.getMeasureSpecSize(widthMeasureSpec);
         var widthMode = utils.layout.getMeasureSpecMode(widthMeasureSpec);
         var height = utils.layout.getMeasureSpecSize(heightMeasureSpec);
         var heightMode = utils.layout.getMeasureSpecMode(heightMeasureSpec);
         if (widthMode === utils.layout.UNSPECIFIED) {
             width = Number.POSITIVE_INFINITY;
         }
         if (heightMode === utils.layout.UNSPECIFIED) {
             height = Number.POSITIVE_INFINITY;
         }
         this._fixedSize = (widthMode === utils.layout.EXACTLY ? FixedSize.WIDTH : FixedSize.NONE)
             | (heightMode === utils.layout.EXACTLY ? FixedSize.HEIGHT : FixedSize.NONE);
         var nativeSize = nativeView.sizeThatFits(CGSizeMake(width, height));
         var labelWidth = nativeSize.width;
         if (!this.textWrap && this.style.whiteSpace !== enums.WhiteSpace.nowrap) {
             labelWidth = Math.min(labelWidth, width);
         }
         var measureWidth = Math.max(labelWidth, this.minWidth);
         var measureHeight = Math.max(nativeSize.height, this.minHeight);
         var widthAndState = view_1.View.resolveSizeAndState(measureWidth, width, widthMode, 0);
         var heightAndState = view_1.View.resolveSizeAndState(measureHeight, height, heightMode, 0);
         this.setMeasuredDimension(widthAndState, heightAndState);
     }
 };
 this.eachLayoutChild(function (child, last) {
     if (_this.stretchLastChild && last) {
         childWidthMeasureSpec = utils.layout.makeMeasureSpec(remainingWidth, widthMode);
         childHeightMeasureSpec = utils.layout.makeMeasureSpec(remainingHeight, heightMode);
     }
     else {
         childWidthMeasureSpec = utils.layout.makeMeasureSpec(remainingWidth, widthMode === utils.layout.EXACTLY ? utils.layout.AT_MOST : widthMode);
         childHeightMeasureSpec = utils.layout.makeMeasureSpec(remainingHeight, heightMode === utils.layout.EXACTLY ? utils.layout.AT_MOST : heightMode);
     }
     var childSize = view_1.View.measureChild(_this, child, childWidthMeasureSpec, childHeightMeasureSpec);
     var dock = DockLayout.getDock(child);
     switch (dock) {
         case enums_1.Dock.top:
         case enums_1.Dock.bottom:
             remainingHeight = Math.max(0, remainingHeight - childSize.measuredHeight);
             tempHeight += childSize.measuredHeight;
             measureWidth = Math.max(measureWidth, tempWidth + childSize.measuredWidth);
             measureHeight = Math.max(measureHeight, tempHeight);
             break;
         case enums_1.Dock.left:
         case enums_1.Dock.right:
         default:
             remainingWidth = Math.max(0, remainingWidth - childSize.measuredWidth);
             tempWidth += childSize.measuredWidth;
             measureWidth = Math.max(measureWidth, tempWidth);
             measureHeight = Math.max(measureHeight, tempHeight + childSize.measuredHeight);
             break;
     }
 });
 LayoutBase.adjustChildrenLayoutParams = function (layoutBase, widthMeasureSpec, heightMeasureSpec) {
     var availableWidth = utils.layout.getMeasureSpecSize(widthMeasureSpec);
     var widthSpec = utils.layout.getMeasureSpecMode(widthMeasureSpec);
     var availableHeight = utils.layout.getMeasureSpecSize(heightMeasureSpec);
     var heightSpec = utils.layout.getMeasureSpecMode(heightMeasureSpec);
     for (var i = 0, count = layoutBase.getChildrenCount(); i < count; i++) {
         var child = layoutBase.getChildAt(i);
         var lp = child.style._getValue(style.nativeLayoutParamsProperty);
         if (widthSpec !== utils.layout.UNSPECIFIED) {
             if (lp.widthPercent > 0) {
                 lp.width = Math.round(availableWidth * lp.widthPercent);
             }
             if (lp.leftMarginPercent > 0) {
                 lp.leftMargin = Math.round(availableWidth * lp.leftMarginPercent);
             }
             if (lp.rightMarginPercent > 0) {
                 lp.rightMargin = Math.round(availableWidth * lp.rightMarginPercent);
             }
         }
         if (heightSpec !== utils.layout.UNSPECIFIED) {
             if (lp.heightPercent > 0) {
                 lp.height = Math.round(availableHeight * lp.heightPercent);
             }
             if (lp.topMarginPercent > 0) {
                 lp.topMargin = Math.round(availableHeight * lp.topMarginPercent);
             }
             if (lp.bottomMarginPercent > 0) {
                 lp.bottomMargin = Math.round(availableHeight * lp.bottomMarginPercent);
             }
         }
     }
 };
示例#8
0
 Switch.prototype.onMeasure = function (widthMeasureSpec, heightMeasureSpec) {
     var nativeSize = this._nativeView.sizeThatFits(CGSizeMake(0, 0));
     this.width = nativeSize.width;
     this.height = nativeSize.height;
     var widthAndState = utils.layout.makeMeasureSpec(nativeSize.width, utils.layout.EXACTLY);
     var heightAndState = utils.layout.makeMeasureSpec(nativeSize.height, utils.layout.EXACTLY);
     this.setMeasuredDimension(widthAndState, heightAndState);
 };
 ActionBar.prototype.onMeasure = function (widthMeasureSpec, heightMeasureSpec) {
     if (this.titleView) {
         var width = utils.layout.getMeasureSpecSize(widthMeasureSpec);
         view.View.measureChild(this, this.titleView, utils.layout.makeMeasureSpec(width, utils.layout.AT_MOST), utils.layout.makeMeasureSpec(this.navigationBarHeight, utils.layout.AT_MOST));
     }
     this.setMeasuredDimension(0, 0);
     _super.prototype.onMeasure.call(this, widthMeasureSpec, heightMeasureSpec);
 };
 UIViewControllerImpl.prototype.viewDidLayoutSubviews = function () {
     var owner = this._owner.get();
     if (!owner) {
         return;
     }
     if (trace.enabled) {
         trace.write(owner + " viewDidLayoutSubviews, isLoaded = " + owner.isLoaded, trace.categories.ViewHierarchy);
     }
     if (!owner.isLoaded) {
         return;
     }
     if (owner._modalParent) {
         var isTablet = platform_1.device.deviceType === enums_1.DeviceType.Tablet;
         var isFullScreen = !owner._UIModalPresentationFormSheet || !isTablet;
         var frame = isFullScreen ? UIScreen.mainScreen().bounds : this.view.frame;
         var size = frame.size;
         var width = size.width;
         var height = size.height;
         var mode = utils.layout.EXACTLY;
         var superViewRotationRadians = void 0;
         if (this.view.superview) {
             var transform = this.view.superview.transform;
             superViewRotationRadians = atan2f(transform.b, transform.a);
         }
         if (utils.ios.MajorVersion < 8 && utils.ios.isLandscape() && !superViewRotationRadians) {
             width = size.height;
             height = size.width;
         }
         var bottom = height;
         var statusBarHeight = uiUtils.ios.getStatusBarHeight();
         var statusBarVisible = !UIApplication.sharedApplication().statusBarHidden;
         var backgroundSpanUnderStatusBar = owner.backgroundSpanUnderStatusBar;
         if (statusBarVisible && !backgroundSpanUnderStatusBar) {
             height -= statusBarHeight;
         }
         var widthSpec = utils.layout.makeMeasureSpec(width, mode);
         var heightSpec = utils.layout.makeMeasureSpec(height, mode);
         view_1.View.measureChild(null, owner, widthSpec, heightSpec);
         var top_1 = ((backgroundSpanUnderStatusBar && isFullScreen) || utils.ios.MajorVersion < 8 || !isFullScreen) ? 0 : statusBarHeight;
         view_1.View.layoutChild(null, owner, 0, top_1, width, bottom);
         if (utils.ios.MajorVersion < 8) {
             if (!backgroundSpanUnderStatusBar && (!isTablet || isFullScreen)) {
                 if (utils.ios.isLandscape() && !superViewRotationRadians) {
                     this.view.center = CGPointMake(this.view.center.x - statusBarHeight, this.view.center.y);
                 }
                 else {
                     this.view.center = CGPointMake(this.view.center.x, this.view.center.y + statusBarHeight);
                 }
             }
         }
         if (trace.enabled) {
             trace.write(owner + ", native frame = " + NSStringFromCGRect(this.view.frame), trace.categories.Layout);
         }
     }
     else {
         owner._updateLayout();
     }
 };
示例#11
0
exports.itemSwipeProgressStarted = function(args) {
    var swipeLimits = args.data.swipeLimits;
    swipeLimits.threshold = 50 * utilsModule.layout.getDisplayDensity();

    // Workaround https://github.com/telerik/nativescript-ui/issues/277
    var swipeDistance = 50 * utilsModule.layout.getDisplayDensity();
    swipeLimits.left = page.android ? swipeDistance : 0;
    swipeLimits.right = page.android ? 0 : swipeDistance;
};
示例#12
0
 View.prototype.getActualSize = function () {
     var currentBounds = this._getCurrentLayoutBounds();
     if (!currentBounds) {
         return undefined;
     }
     return {
         width: utils.layout.toDeviceIndependentPixels(currentBounds.right - currentBounds.left),
         height: utils.layout.toDeviceIndependentPixels(currentBounds.bottom - currentBounds.top),
     };
 };
 View.prototype.getLocationInWindow = function () {
     if (!this._nativeView || !this._nativeView.window) {
         return undefined;
     }
     var pointInWindow = this._nativeView.convertPointToView(this._nativeView.bounds.origin, null);
     return {
         x: utils.layout.toDeviceIndependentPixels(pointInWindow.x),
         y: utils.layout.toDeviceIndependentPixels(pointInWindow.y),
     };
 };
 Frame.prototype.onMeasure = function (widthMeasureSpec, heightMeasureSpec) {
     var width = utils.layout.getMeasureSpecSize(widthMeasureSpec);
     var widthMode = utils.layout.getMeasureSpecMode(widthMeasureSpec);
     var height = utils.layout.getMeasureSpecSize(heightMeasureSpec);
     var heightMode = utils.layout.getMeasureSpecMode(heightMeasureSpec);
     var result = view.View.measureChild(this, this.currentPage, widthMeasureSpec, utils.layout.makeMeasureSpec(height - this.navigationBarHeight, heightMode));
     var widthAndState = view.View.resolveSizeAndState(result.measuredWidth, width, widthMode, 0);
     var heightAndState = view.View.resolveSizeAndState(result.measuredHeight, height, heightMode, 0);
     this.setMeasuredDimension(widthAndState, heightAndState);
 };
 Frame.prototype.measurePage = function (page) {
     var heightSpec = this._heightMeasureSpec;
     if (page && !page.backgroundSpanUnderStatusBar && !this.parent) {
         var height = utils.layout.getMeasureSpecSize(this._heightMeasureSpec);
         var heightMode = utils.layout.getMeasureSpecMode(this._heightMeasureSpec);
         var statusBarHeight = uiUtils.ios.getStatusBarHeight();
         heightSpec = utils.layout.makeMeasureSpec(height - statusBarHeight, heightMode);
     }
     return view_1.View.measureChild(this, page, this._widthMeasureSpec, heightSpec);
 };
 Repeater.prototype.onMeasure = function (widthMeasureSpec, heightMeasureSpec) {
     var result = viewModule.View.measureChild(this, this.itemsLayout, widthMeasureSpec, heightMeasureSpec);
     var width = utils.layout.getMeasureSpecSize(widthMeasureSpec);
     var widthMode = utils.layout.getMeasureSpecMode(widthMeasureSpec);
     var height = utils.layout.getMeasureSpecSize(heightMeasureSpec);
     var heightMode = utils.layout.getMeasureSpecMode(heightMeasureSpec);
     var widthAndState = viewModule.View.resolveSizeAndState(result.measuredWidth, width, widthMode, 0);
     var heightAndState = viewModule.View.resolveSizeAndState(result.measuredHeight, height, heightMode, 0);
     this.setMeasuredDimension(widthAndState, heightAndState);
 };
 WrapLayout.getChildMeasureSpec = function (parentMode, parentLength, itemLength) {
     if (itemLength > 0) {
         return utils.layout.makeMeasureSpec(itemLength, utils.layout.EXACTLY);
     }
     else if (parentMode === utils.layout.UNSPECIFIED) {
         return utils.layout.makeMeasureSpec(0, utils.layout.UNSPECIFIED);
     }
     else {
         return utils.layout.makeMeasureSpec(parentLength, utils.layout.AT_MOST);
     }
 };
示例#18
0
 View.prototype.getLocationOnScreen = function () {
     if (!this._nativeView || !this._nativeView.getWindowToken()) {
         return undefined;
     }
     var nativeArray = Array.create("int", 2);
     this._nativeView.getLocationOnScreen(nativeArray);
     return {
         x: utils.layout.toDeviceIndependentPixels(nativeArray[0]),
         y: utils.layout.toDeviceIndependentPixels(nativeArray[1]),
     };
 };
 onScrollChanged: function () {
     var rootScrollView = that.get();
     if (rootScrollView && rootScrollView.android) {
         rootScrollView.notify({
             object: rootScrollView,
             eventName: ScrollView.scrollEvent,
             scrollX: rootScrollView.android.getScrollX() / utils.layout.getDisplayDensity(),
             scrollY: rootScrollView.android.getScrollY() / utils.layout.getDisplayDensity()
         });
     }
 }
 DockLayout.prototype.onMeasure = function (widthMeasureSpec, heightMeasureSpec) {
     var _this = this;
     DockLayout.adjustChildrenLayoutParams(this, widthMeasureSpec, heightMeasureSpec);
     _super.prototype.onMeasure.call(this, widthMeasureSpec, heightMeasureSpec);
     var measureWidth = 0;
     var measureHeight = 0;
     var width = utils.layout.getMeasureSpecSize(widthMeasureSpec);
     var widthMode = utils.layout.getMeasureSpecMode(widthMeasureSpec);
     var height = utils.layout.getMeasureSpecSize(heightMeasureSpec);
     var heightMode = utils.layout.getMeasureSpecMode(heightMeasureSpec);
     var density = utils.layout.getDisplayDensity();
     var remainingWidth = widthMode === utils.layout.UNSPECIFIED ? Number.MAX_VALUE : width - ((this.paddingLeft + this.paddingRight) * density);
     var remainingHeight = heightMode === utils.layout.UNSPECIFIED ? Number.MAX_VALUE : height - ((this.paddingTop + this.paddingBottom) * density);
     var tempHeight = 0;
     var tempWidth = 0;
     var childWidthMeasureSpec;
     var childHeightMeasureSpec;
     this.eachLayoutChild(function (child, last) {
         if (_this.stretchLastChild && last) {
             childWidthMeasureSpec = utils.layout.makeMeasureSpec(remainingWidth, widthMode);
             childHeightMeasureSpec = utils.layout.makeMeasureSpec(remainingHeight, heightMode);
         }
         else {
             childWidthMeasureSpec = utils.layout.makeMeasureSpec(remainingWidth, widthMode === utils.layout.EXACTLY ? utils.layout.AT_MOST : widthMode);
             childHeightMeasureSpec = utils.layout.makeMeasureSpec(remainingHeight, heightMode === utils.layout.EXACTLY ? utils.layout.AT_MOST : heightMode);
         }
         var childSize = view_1.View.measureChild(_this, child, childWidthMeasureSpec, childHeightMeasureSpec);
         var dock = DockLayout.getDock(child);
         switch (dock) {
             case enums_1.Dock.top:
             case enums_1.Dock.bottom:
                 remainingHeight = Math.max(0, remainingHeight - childSize.measuredHeight);
                 tempHeight += childSize.measuredHeight;
                 measureWidth = Math.max(measureWidth, tempWidth + childSize.measuredWidth);
                 measureHeight = Math.max(measureHeight, tempHeight);
                 break;
             case enums_1.Dock.left:
             case enums_1.Dock.right:
             default:
                 remainingWidth = Math.max(0, remainingWidth - childSize.measuredWidth);
                 tempWidth += childSize.measuredWidth;
                 measureWidth = Math.max(measureWidth, tempWidth);
                 measureHeight = Math.max(measureHeight, tempHeight + childSize.measuredHeight);
                 break;
         }
     });
     measureWidth += (this.paddingLeft + this.paddingRight) * density;
     measureHeight += (this.paddingTop + this.paddingBottom) * density;
     measureWidth = Math.max(measureWidth, this.minWidth * density);
     measureHeight = Math.max(measureHeight, this.minHeight * density);
     var widthAndState = view_1.View.resolveSizeAndState(measureWidth, width, widthMode, 0);
     var heightAndState = view_1.View.resolveSizeAndState(measureHeight, height, heightMode, 0);
     this.setMeasuredDimension(widthAndState, heightAndState);
 };
 CustomControl.prototype.onMeasure = function (widthMeasureSpec, heightMeasureSpec) {
     var result = view_1.View.measureChild(this, this.template, widthMeasureSpec, heightMeasureSpec);
     var width = utils.layout.getMeasureSpecSize(widthMeasureSpec);
     var widthMode = utils.layout.getMeasureSpecMode(widthMeasureSpec);
     var height = utils.layout.getMeasureSpecSize(heightMeasureSpec);
     var heightMode = utils.layout.getMeasureSpecMode(heightMeasureSpec);
     var density = utils.layout.getDisplayDensity();
     var measureWidth = Math.max(result.measuredWidth, this.minWidth * density);
     var measureHeight = Math.max(result.measuredHeight, this.minHeight * density);
     var widthAndState = view_1.View.resolveSizeAndState(measureWidth, width, widthMode, 0);
     var heightAndState = view_1.View.resolveSizeAndState(measureHeight, height, heightMode, 0);
     this.setMeasuredDimension(widthAndState, heightAndState);
 };
 View.prototype.getLocationRelativeTo = function (otherView) {
     if (!this._nativeView || !this._nativeView.window ||
         !otherView._nativeView || !otherView._nativeView.window ||
         this._nativeView.window !== otherView._nativeView.window) {
         return undefined;
     }
     var myPointInWindow = this._nativeView.convertPointToView(this._nativeView.bounds.origin, null);
     var otherPointInWindow = otherView._nativeView.convertPointToView(otherView._nativeView.bounds.origin, null);
     return {
         x: utils.layout.toDeviceIndependentPixels(myPointInWindow.x - otherPointInWindow.x),
         y: utils.layout.toDeviceIndependentPixels(myPointInWindow.y - otherPointInWindow.y),
     };
 };
function cssValueToDevicePixels(source, total) {
    var result;
    source = source.trim();
    if (source.indexOf("px") !== -1) {
        result = parseFloat(source.replace("px", ""));
    }
    else if (source.indexOf("%") !== -1 && total > 0) {
        result = (parseFloat(source.replace("%", "")) / 100) * utils.layout.toDeviceIndependentPixels(total);
    }
    else {
        result = parseFloat(source);
    }
    return utils.layout.toDevicePixels(result);
}
示例#24
0
 View.prototype.getLocationRelativeTo = function (otherView) {
     if (!this._nativeView || !this._nativeView.getWindowToken() ||
         !otherView._nativeView || !otherView._nativeView.getWindowToken() ||
         this._nativeView.getWindowToken() !== otherView._nativeView.getWindowToken()) {
         return undefined;
     }
     var myArray = Array.create("int", 2);
     this._nativeView.getLocationOnScreen(myArray);
     var otherArray = Array.create("int", 2);
     otherView._nativeView.getLocationOnScreen(otherArray);
     return {
         x: utils.layout.toDeviceIndependentPixels(myArray[0] - otherArray[0]),
         y: utils.layout.toDeviceIndependentPixels(myArray[1] - otherArray[1]),
     };
 };
 ToolBar.prototype.onMeasure = function (widthMeasureSpec, heightMeasureSpec) {
     var width = utils_1.layout.getMeasureSpecSize(widthMeasureSpec);
     var widthMode = utils_1.layout.getMeasureSpecMode(widthMeasureSpec);
     var height = utils_1.layout.getMeasureSpecSize(heightMeasureSpec);
     var heightMode = utils_1.layout.getMeasureSpecMode(heightMeasureSpec);
     var newHeight = height;
     var navBarWidth = 0;
     var navBarHeight = 0;
     if (heightMode != utils_1.layout.EXACTLY) {
         var toolbarSize = this._ios.intrinsicContentSize();
         newHeight = toolbarSize.height;
         heightMode = utils_1.layout.EXACTLY;
     }
     var heightAndState = view_1.View.resolveSizeAndState(height, newHeight, heightMode, 0);
     this.setMeasuredDimension(widthMeasureSpec, heightAndState);
 };
 WrapLayout.prototype.onLayout = function (left, top, right, bottom) {
     var _this = this;
     _super.prototype.onLayout.call(this, left, top, right, bottom);
     var isVertical = this.orientation === enums_1.Orientation.vertical;
     var density = utils.layout.getDisplayDensity();
     var topPadding = (this.borderTopWidth + this.paddingTop) * density;
     var leftPadding = (this.borderLeftWidth + this.paddingLeft) * density;
     var bottomPadding = (this.paddingBottom + this.borderBottomWidth) * density;
     var rightPadding = (this.paddingRight + this.borderRightWidth) * density;
     var childLeft = leftPadding;
     var childTop = topPadding;
     var childrenLength;
     if (isVertical) {
         childrenLength = bottom - top - bottomPadding;
     }
     else {
         childrenLength = right - left - rightPadding;
     }
     var rowOrColumn = 0;
     this.eachLayoutChild(function (child, last) {
         var lp = child.style._getValue(style_1.nativeLayoutParamsProperty);
         var childWidth = child.getMeasuredWidth() + (lp.leftMargin + lp.rightMargin) * density;
         var childHeight = child.getMeasuredHeight() + (lp.topMargin + lp.bottomMargin) * density;
         var length = _this._lengths[rowOrColumn];
         if (isVertical) {
             childWidth = length;
             childHeight = _this.itemHeight > 0 ? _this.itemHeight * density : childHeight;
             var isFirst = childTop === topPadding;
             if (childTop + childHeight > childrenLength) {
                 childTop = topPadding;
                 if (!isFirst) {
                     childLeft += length;
                 }
                 rowOrColumn++;
                 childWidth = _this._lengths[isFirst ? rowOrColumn - 1 : rowOrColumn];
             }
         }
         else {
             childWidth = _this.itemWidth > 0 ? _this.itemWidth * density : childWidth;
             childHeight = length;
             var isFirst = childLeft === leftPadding;
             if (childLeft + childWidth > childrenLength) {
                 childLeft = leftPadding;
                 if (!isFirst) {
                     childTop += length;
                 }
                 rowOrColumn++;
                 childHeight = _this._lengths[isFirst ? rowOrColumn - 1 : rowOrColumn];
             }
         }
         view_1.View.layoutChild(_this, child, childLeft, childTop, childLeft + childWidth, childTop + childHeight);
         if (isVertical) {
             childTop += childHeight;
         }
         else {
             childLeft += childWidth;
         }
     });
     WrapLayout.restoreOriginalParams(this);
 };
 StackLayout.prototype.layoutHorizontal = function (left, top, right, bottom) {
     var _this = this;
     var density = utils.layout.getDisplayDensity();
     var paddingLeft = this.paddingLeft * density;
     var paddingRight = this.paddingRight * density;
     var paddingTop = this.paddingTop * density;
     var paddingBottom = this.paddingBottom * density;
     var childTop = paddingTop;
     var childLeft;
     var childBottom = bottom - top - paddingBottom;
     switch (this.horizontalAlignment) {
         case enums_1.HorizontalAlignment.center:
             childLeft = (right - left - this._totalLength) / 2 + paddingLeft - paddingRight;
             break;
         case enums_1.HorizontalAlignment.right:
             childLeft = right - left - this._totalLength + paddingLeft - paddingRight;
             break;
         case enums_1.HorizontalAlignment.left:
         case enums_1.HorizontalAlignment.stretch:
         default:
             childLeft = paddingLeft;
             break;
     }
     this.eachLayoutChild(function (child, last) {
         var lp = child.style._getValue(style_1.nativeLayoutParamsProperty);
         var childWidth = child.getMeasuredWidth() + (lp.leftMargin + lp.rightMargin) * density;
         view_1.View.layoutChild(_this, child, childLeft, childTop, childLeft + childWidth, childBottom);
         childLeft += childWidth;
     });
 };
 StackLayout.prototype.layoutVertical = function (left, top, right, bottom) {
     var _this = this;
     var density = utils.layout.getDisplayDensity();
     var paddingLeft = this.paddingLeft * density;
     var paddingRight = this.paddingRight * density;
     var paddingTop = this.paddingTop * density;
     var paddingBottom = this.paddingBottom * density;
     var childTop;
     var childLeft = paddingLeft;
     var childRight = right - left - paddingRight;
     switch (this.verticalAlignment) {
         case enums_1.VerticalAlignment.center:
         case enums_1.VerticalAlignment.middle:
             childTop = (bottom - top - this._totalLength) / 2 + paddingTop - paddingBottom;
             break;
         case enums_1.VerticalAlignment.bottom:
             childTop = bottom - top - this._totalLength + paddingTop - paddingBottom;
             break;
         case enums_1.VerticalAlignment.top:
         case enums_1.VerticalAlignment.stretch:
         default:
             childTop = paddingTop;
             break;
     }
     this.eachLayoutChild(function (child, last) {
         var lp = child.style._getValue(style_1.nativeLayoutParamsProperty);
         var childHeight = child.getMeasuredHeight() + (lp.topMargin + lp.bottomMargin) * density;
         view_1.View.layoutChild(_this, child, childLeft, childTop, childRight, childTop + childHeight);
         childTop += childHeight;
     });
 };
示例#29
0
 StackLayout.prototype.layoutHorizontal = function (left, top, right, bottom) {
     var density = utils.layout.getDisplayDensity();
     var paddingLeft = this.paddingLeft * density;
     var paddingRight = this.paddingRight * density;
     var paddingTop = this.paddingTop * density;
     var paddingBottom = this.paddingBottom * density;
     var childTop = paddingTop;
     var childLeft;
     var childBottom = bottom - top - paddingBottom;
     switch (this.horizontalAlignment) {
         case enums.HorizontalAlignment.center:
             childLeft = (right - left - this._totalLength) / 2 + paddingLeft - paddingRight;
             break;
         case enums.HorizontalAlignment.right:
             childLeft = right - left - this._totalLength + paddingLeft - paddingRight;
             break;
         case enums.HorizontalAlignment.left:
         case enums.HorizontalAlignment.stretch:
         default:
             childLeft = paddingLeft;
             break;
     }
     var count = this.getChildrenCount();
     for (var i = 0; i < count; i++) {
         var child = this.getChildAt(i);
         if (!child || !child._isVisible) {
             continue;
         }
         var childWidth = child.getMeasuredWidth() + (child.marginLeft + child.marginRight) * density;
         ;
         view.View.layoutChild(this, child, childLeft, childTop, childLeft + childWidth, childBottom);
         childLeft += childWidth;
     }
 };
 function PinchGestureListener(observer, target) {
     _super.call(this);
     this._observer = observer;
     this._target = target;
     this._density = utils.layout.getDisplayDensity();
     return global.__native(this);
 }