Complete
over 3 years ago

VVA4-5339

Fixed

Menu2 doesn't allow live updates.

Menu2 does not update, for example with addItem, whilst the menu is being viewed.

There is no mention of this in the documentation and it works in the simulator.  

I am not the only person having this issue (see links below) and as it stands it wastes a lot of developer time to develop using Menu2 then debug why it doesn't work.  At the least the documentation should reflect the functionality.

https://forums.garmin.com/developer/connect-iq/f/discussion/254078/menu2-additem-does-not-cause-refresh-of-menu-on-edge520plus

https://forums.garmin.com/developer/connect-iq/f/discussion/7382/menu2-additem-does-not-work-on-fenix-5s

Parents
  • Given the status of the original issue reported against the fenix5s, it sounds like it was fixed for that device when the Menu2InputDelegate.onSelect() method was called. This new issue is slightly different in that it is looking for onUpdate() to refresh the list. I'm not certain if that is a device bug (it should refresh the list) or a simulator bug (it should not). Either way, here is some source code that can be used to test.

    using Toybox.Application;
    using Toybox.Lang;
    using Toybox.System;
    using Toybox.Timer;
    using Toybox.WatchUi;
    
    // https://forums.garmin.com/developer/connect-iq/f/discussion/254078/menu2-additem-does-not-cause-refresh-of-menu-on-edge520plus
    
    class Menu2View extends WatchUi.Menu2
    {
        hidden var _timer;
        hidden var _item;
    
        function initialize() {
            Menu2.initialize({
                :title => "Test"
            });
            _item = new WatchUi.MenuItem("Label", "subLabel", :identifier, null);
            addItem(_item);
        }
    
        function onShow() {
            _timer = new Timer.Timer();
            _timer.start(self.method(:onTimer), 1000, true);
        }
    
        function onHide() {
            _timer.stop();
            _timer = null;
        }
    
        hidden var _counter = 0;
    
        function onTimer() {
            _item.setSubLabel(_counter.toString());
    
            if (_counter < 5) {
                ++_counter;
                addItem(new WatchUi.MenuItem("Blah!", null, null, null));
    
                // should see updates to sub-label and new items
                WatchUi.requestUpdate();
            }
        }
    }
    
    class Menu2ViewDelegate extends WatchUi.Menu2InputDelegate
    {
        function initialize() {
            Menu2InputDelegate.initialize();
        }
    }
    
    class ForumTestView extends WatchUi.View
    {
        function initialize() {
            View.initialize();
        }
    
        function onUpdate(dc) {
            dc.setColor(Graphics.COLOR_BLACK, Graphics.COLOR_WHITE);
            dc.clear();
    
            var cx = dc.getWidth() / 2;
            var cy = dc.getHeight() / 2;
    
            dc.drawText(cx, cy, Graphics.FONT_LARGE, "Press\nSelect/Enter", Graphics.TEXT_JUSTIFY_CENTER | Graphics.TEXT_JUSTIFY_VCENTER);
        }
    }
    
    class ForumTestViewDelegate extends WatchUi.BehaviorDelegate
    {
        function initialize() {
            BehaviorDelegate.initialize();
        }
    
        function onSelect() {
            WatchUi.pushView(new Menu2View(), new Menu2ViewDelegate(), WatchUi.SLIDE_UP);
            return true;
        }
    }
    
    class ForumTestApp extends Application.AppBase
    {
        function initialize() {
            AppBase.initialize();
        }
    
        function getInitialView() {
            return [ new ForumTestView(), new ForumTestViewDelegate() ];
        }
    }
    

Comment
  • Given the status of the original issue reported against the fenix5s, it sounds like it was fixed for that device when the Menu2InputDelegate.onSelect() method was called. This new issue is slightly different in that it is looking for onUpdate() to refresh the list. I'm not certain if that is a device bug (it should refresh the list) or a simulator bug (it should not). Either way, here is some source code that can be used to test.

    using Toybox.Application;
    using Toybox.Lang;
    using Toybox.System;
    using Toybox.Timer;
    using Toybox.WatchUi;
    
    // https://forums.garmin.com/developer/connect-iq/f/discussion/254078/menu2-additem-does-not-cause-refresh-of-menu-on-edge520plus
    
    class Menu2View extends WatchUi.Menu2
    {
        hidden var _timer;
        hidden var _item;
    
        function initialize() {
            Menu2.initialize({
                :title => "Test"
            });
            _item = new WatchUi.MenuItem("Label", "subLabel", :identifier, null);
            addItem(_item);
        }
    
        function onShow() {
            _timer = new Timer.Timer();
            _timer.start(self.method(:onTimer), 1000, true);
        }
    
        function onHide() {
            _timer.stop();
            _timer = null;
        }
    
        hidden var _counter = 0;
    
        function onTimer() {
            _item.setSubLabel(_counter.toString());
    
            if (_counter < 5) {
                ++_counter;
                addItem(new WatchUi.MenuItem("Blah!", null, null, null));
    
                // should see updates to sub-label and new items
                WatchUi.requestUpdate();
            }
        }
    }
    
    class Menu2ViewDelegate extends WatchUi.Menu2InputDelegate
    {
        function initialize() {
            Menu2InputDelegate.initialize();
        }
    }
    
    class ForumTestView extends WatchUi.View
    {
        function initialize() {
            View.initialize();
        }
    
        function onUpdate(dc) {
            dc.setColor(Graphics.COLOR_BLACK, Graphics.COLOR_WHITE);
            dc.clear();
    
            var cx = dc.getWidth() / 2;
            var cy = dc.getHeight() / 2;
    
            dc.drawText(cx, cy, Graphics.FONT_LARGE, "Press\nSelect/Enter", Graphics.TEXT_JUSTIFY_CENTER | Graphics.TEXT_JUSTIFY_VCENTER);
        }
    }
    
    class ForumTestViewDelegate extends WatchUi.BehaviorDelegate
    {
        function initialize() {
            BehaviorDelegate.initialize();
        }
    
        function onSelect() {
            WatchUi.pushView(new Menu2View(), new Menu2ViewDelegate(), WatchUi.SLIDE_UP);
            return true;
        }
    }
    
    class ForumTestApp extends Application.AppBase
    {
        function initialize() {
            AppBase.initialize();
        }
    
        function getInitialView() {
            return [ new ForumTestView(), new ForumTestViewDelegate() ];
        }
    }
    

Children
No Data