I have the following code and I'm noticing something odd when I enter the view as the following is printed out in my console.
onLayout
onShow
onUpdate
onUpdate
onUpdate
Why is the view updated three times when it does absolutely nothing?
using Toybox.WatchUi as Ui;
using Toybox.Graphics as Gfx;
class OverlayView extends Ui.View {
private var width;
private var height;
function initialize() {
Ui.View.initialize();
self.width = null;
self.height = null;
}
function onLayout(dc as Gfx.Dc) {
View.onLayout(dc);
System.println("onLayout");
self.width = dc.getWidth();
self.height = dc.getHeight();
}
function onShow() {
View.onShow();
System.println("onShow");
}
function onUpdate(dc as Gfx.Dc) {
View.onUpdate(dc);
System.println("onUpdate");
}
}
class OverlayViewDelegate extends Ui.BehaviorDelegate {
function initialize() {
Ui.BehaviorDelegate.initialize();
}
function onMenu() {
System.println("Menu behavior triggered");
// Setting this to false will cause the onKey() to be triggered
return true;
}
function onSelect() {
System.println("Select behavior triggered");
return false;
}
function onBack() {
Ui.popView(0 as Toybox.WatchUi.SlideType);
return true;
}
function onNextPage() {
System.println("Pressed on down");
return false;
}
function onPreviousPage() {
System.println("Pressed on up");
return false;
}
function onKey(keyEvent) {
Ui.requestUpdate();
return true;
}
}