Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI Menu top-to-bottom order varies depending on context?

I think I know the answer to this, but I'll pose it as a question and give my answer, since it was a bit puzzling to me and it took me a little while to figure out.

I'm just starting to use Menu's in SwiftUI. In my first application of them I used them in the nav bar of my app.

            Menu {
                ForEach(pickers, id: \.mediaPickerUIDisplayName) { picker in
                    Button(action: {
                        viewModel.sheetToShow = .picker(picker)
                    }) {
                        Text(picker.mediaPickerUIDisplayName)
                    }.enabled(picker.mediaPickerEnabled)
                }
            } label: {
                SFSymbolIcon(symbol: .plusCircle)
            }

And it looked good.

enter image description here

Then, I changed the context in which this same code was used. Instead of being used from the nav bar, I used it in the center of a screen. And instead I saw:

enter image description here

I was disconcerted in that the top-to-bottom ordering of items in the list had changed.

like image 634
Chris Prince Avatar asked Oct 29 '25 14:10

Chris Prince


1 Answers

[UPDATE] In iOS16 (beta) at the time of writing you can now use the new modifier .menuOrder(.fixed). That will keep the order of your items, well, fixed and the name implies…

Yup. This is the ‘native’ behavior which I personally find extremely bad. Imagine you have the delete button on the bottom and suddenly without any warning the order changes only because the element has moved above /bellow the midline. Muscle memory will kick in and the users will get extremely confused. This is an omission with catastrophic consequences.

like image 134
gm_ Avatar answered Oct 31 '25 05:10

gm_



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!