Replies: 2 comments 1 reply
-
Hi @ltns35, it is not possible to support this kind of thing. SwiftUI does not open up enough of their internal APIs to allow one to use environment values outside of views. There may be hacks you can employ, but it's hard to give concrete advice without more information. Can you share some code that demonstrates what you are trying to achieve? |
Beta Was this translation helpful? Give feedback.
-
This is the code I currently have and its working, but I need to call the function in all the screens. private struct NavigatorAdaptor: ViewModifier {
@Environment(\.navigator)
private var navigator
@Binding
private var nav: Navigator?
public init(_ nav: Binding<Navigator?>) {
_nav = nav
}
func body(content: Content) -> some View {
content
.onAppear {
nav = navigator
}
}
}
public extension View {
func exposeNavigator(_ navigator: Binding<Navigator?>) -> some View {
modifier(NavigatorAdaptor(navigator))
}
} What I want to do is call the The main problem I'm facing with TCA is the navigation between isolated modules with a navigation framework that decouples the navigation. |
Beta Was this translation helpful? Give feedback.
-
Hi everyone,
I'm working on a use case where I need to pass an environment value as a dependency to be used within a feature. Right now, I'm handling this manually by assigning the environment value to a state variable inside the .onAppear modifier. However, this approach adds quite a bit of boilerplate code.
To reduce repetition, I'm considering creating a custom ViewModifier to encapsulate this logic and make it reusable.
Has anyone tackled a similar scenario? I'd appreciate any advice or best practices for implementing this pattern effectively.
Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions