You have two views, A and B. You present a menu on A with a menu option that switches to B.
After you switch to view B, I expected view A to stop receiving `onUpdate` calls.
However, that doesn't seem to be the case:
ViewA.onUpdate
Switched to B
ViewA.onUpdate
ViewB.onUpdate
I'm guessing the menu somehow calls `onUpdate` one more time on its view (not the current view which was changed) after it returns. But I'm not sure, and definitely not sure why.
Code to replicate this is here:
using Toybox.Application;
using Toybox.Graphics as Gfx;
using Toybox.WatchUi as Ui;
using Toybox.System;
class WidgetTestApp extends Application.AppBase {
function getInitialView() {
return [ new ViewA(), new ViewADelegate() ];
}
}
class ViewA extends Ui.View {
function onUpdate(dc) {
System.println("ViewA.onUpdate");
Ui.View.onUpdate(dc);
dc.setColor(Gfx.COLOR_WHITE, Gfx.COLOR_BLACK);
dc.drawText(50, 50, Gfx.FONT_MEDIUM, "A", Gfx.TEXT_JUSTIFY_LEFT);
}
}
class ViewAMenuInputDelegate extends Ui.MenuInputDelegate {
function onMenuItem(item) {
Ui.popView(Ui.SLIDE_IMMEDIATE);
Ui.switchToView(new ViewB(), new ViewBDelegate(), Ui.SLIDE_IMMEDIATE);
System.println("Switched to B");
}
}
class ViewADelegate extends Ui.BehaviorDelegate {
function onMenu() {
var menu = new Ui.Menu();
menu.addItem("Switch To B", :switchToB);
Ui.pushView(menu, new ViewAMenuInputDelegate(), Ui.SLIDE_UP);
return true;
}
}
class ViewB extends Ui.View {
function onUpdate(dc) {
System.println("ViewB.onUpdate");
Ui.View.onUpdate(dc);
dc.setColor(Gfx.COLOR_WHITE, Gfx.COLOR_BLACK);
dc.drawText(50, 50, Gfx.FONT_MEDIUM, "B", Gfx.TEXT_JUSTIFY_LEFT);
}
}
class ViewBDelegate extends Ui.BehaviorDelegate {
function onBack() {
return false;
}
}
Is this expected behavior?
Thanks!