How do you set behaviors for a `Menu` and its sub-...
# doodle
a
How do you set behaviors for a
Menu
and its sub-menus (the ones that appear as a popup)?
n
assuming you're using a custom `Theme`; you can do this by creating a new module and binding the
Behavior
there:
Copy code
// If you're using a custom Theme, you should make it a DynamicTheme so you can bind modules
// for it as follows.
class MyTheme(behaviors: Iterable<Modules.BehaviorResolver>): DynamicTheme(behaviors.filter { it.theme == MyTheme::class })

// This module can then be added to your app
val module = Module(name = "Some Module") {
    // This binds a Behavior for Menus that will be included whenever MyTheme is installed
    bindBehavior<Menu>(MyTheme::class) {
        it.behavior = ..
    }
}
you can also create a binding for an existing
Theme
(i.e.
BasicTheme
) this way and add your module to the app. Then your behavior will be included whenever that theme is installed. sub-menus get the theme behavior installed just like the root does.
a
But I'm trying to target only specific menus (e.g., menus that are children of some specific kind of view) and their sub-menus. Is there a way to accomplish this?
n
there are two ways to do this general pattern of targeting `Behavior`s to `View`s. unfortunately there’s a limitation with `Menu`s (i’ll be fixing in 0.9.3) that will prevent this from working. 1. use a
Theme
and binding that install a
Behavior
based on the
View
itself. this would be choosing a value based on the properties of the
View
on the line where the
Behavior
is set above. this won’t work for your case because a
Menu
has no parent or owner to switch on. 2. install a
Behavior
manually and set
acceptsThemes
to false. this will work for the top-level menu that your code creates; but the sub-menus will revert to any installed
Theme
. this is what i need to fix. a root menu should propagate its
Behavior
down to sub-menus.