Problem
Setting ".environment(.layoutDirection, .rightToLeft)" to a view programmatically won't make buttons in menu to show right to left.
However, setting ".environment(.locale, .init(identifier: "he-IL"))" to a view programmatically makes buttons in menu to show Hebrew strings correctly.
Development environment: Xcode 16.x, macOS 15.3.1
Target iOS: iOS 17 - iOS 18
The expected result is that the button in the menu should be displayed as an icon then a text from left to right.
Code to demonstrate the problem:
struct ContentView: View {
var body: some View {
VStack(alignment: .leading) {
Text("Buttons in menu don't respect the environment value of .layoutDirection")
.font(.subheadline)
.padding(.bottom, 48)
/// This button respects both "he-IL" of ".locale" and ".rightToLeft" of ".layoutDirection".
Button {
print("Button tapped")
} label: {
HStack {
Text("Send")
Image(systemName: "paperplane")
}
}
Menu {
/// This button respects "he-IL" of ".locale" but doesn't respect ".rightToLeft" of ".layoutDirection".
Button {
print("Button tapped")
} label: {
HStack {
Text("Send")
Image(systemName: "paperplane")
}
}
} label: {
Text("Menu")
}
}
.padding()
.environment(\.locale, .init(identifier: "he-IL"))
.environment(\.layoutDirection, .rightToLeft)
}
}
Selecting any option will automatically load the page