I am trying to write a native script app which retrieves the rendered height of the bottle
view/element in my xml. I have tried the following code, but unfortunately, I get an error (shown below). Any guidance would be much appreciated.
JS:
var viewModule = require("ui/core/view");
var page;
exports.fabTap = function (args) {
page = args.object;
var bottle = page.getViewById("bottle");
console.log("Height: " + bottle.height);
}
XML:
<Page xmlns="http://schemas.nativescript.org/tns.xsd" xmlns:FAB="nativescript-floatingactionbutton" actionBarHidden="true" loaded="pageLoaded">
<GridLayout columns="*, *, *, *" rows="15*, 5*, 20*, 5*, 5*, 5*, 5*, 20*, 20*" width="100%" height="100%" style.backgroundColor="white" >
<Image src="res://logo" row="0" col="1" colSpan="2" stretch ="aspectFit" class="logo"/>
<Image id="bottle" src="res://bottle_outline" row="2" col="0" rowSpan="6" colSpan="2" stretch="aspectFit"/>
</GridLayout>
</Page>
Cannot read property 'height' of undefined.
To get the calculated size of the view, not what you declared in the styles:
const viewModule = require("ui/core/view");
let page;
exports.pageLoaded = function (args) {
page = args.object;
}
exports.fabTap = function (args) {
const bottle = page.getViewById("bottle");
console.log("Height: " + bottle.getActualSize().height);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With