I'm trying to force a layout direction using .environment(\.layoutDirection, .rightToLeft)
modifier on a View.
I'm using the following hierarchy:
let layoutDirection = LayoutDirection.rightToLeft
let view = SettingsView().environment(\.layoutDirection, layoutDirection)
let settingsViewController = UIHostingController(rootView: view)
let navigationController = UINavigationController(rootViewController: settingsViewController)
present(navigationController, animated: true)
SettingsView
has a NavigationLink
to submenu items.
LayoutDirection
is only set to right
on the root view (SettingsView
) and is ignored in child views.
I tried putting .environment(\.layoutDirection, .rightToLeft)
not just after root initializer but also on List
and Section
items in root view. They are all ignored except when setting them specifically to various submenu initializers.
I tried the same thing in a pure SwiftUI app and passing the environment value to children works as expected. Could UIHostingController or UINavigationController be the issue here?
Additionally, I tried the same thing with a custom environment value. Example from https://developer.apple.com/documentation/swiftui/environmentvalues . It also doesn't get passed to child views.