saket / cascade

Nested popup menus with smooth height animations for Android
https://saket.github.io/cascade
Apache License 2.0
2.02k stars 67 forks source link

Make fixedWidth a function. #25

Closed kizitonwose closed 6 months ago

kizitonwose commented 3 years ago

The width of the popup is currently fixed and while this is fine in a single-language project, translations often lead to truncated texts in the popup.

The change in the PR simply makes the fixedWidth property a function and provides the menu as a parameter so users get the chance to calculate the width before the popup is shown.

Currently, for my use case, I loop through the menu items and find the item with the largest width.

Note that in cases where I inflate the menu on cascade myself before calling show() then I can already do this calculation before creating cascade even though that would mean inflating a dummy menu outside since fixedWidth is a constructor parameter so I can't use the menu inside cascade. However, since I also use cascade to override the toolbar's popup menu, grabbing the inflated menu before it is shown becomes a problem because all the work is done in the toolbar.kt

Granted, this would be considered a breaking change but it is one that is quite easy to fix, and users who do not set a custom value for this parameter do not even need to do anything.