Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to pass additional @Binding parameters to the View from another parent View #31

Open
xplatsolutions opened this issue Jun 26, 2020 · 1 comment

Comments

@xplatsolutions
Copy link

xplatsolutions commented Jun 26, 2020

I have a parent View with a TabView and a custom modifier to present a custom full modal view (doesn't exist in SwiftUI so custom work had to be done)

struct ContentView: View {
  
  @ObservedObject private var tabData = MainTabBarData(initialIndex: 1, customItemIndex: 3)
  
  var body: some View {
    
    TabView(selection: $tabData.itemSelected){
      // tab items with views and tags
    }
    .present($tabData.isCustomItemSelected, // Present the modal view when isCustomItemSelected @State is true
             view: Widget(store: HostBroadcast.ViewModel(), content: BroadcastLiveView.init), // Using CombineFeedbackUI Widget passing the viewmodel and content view
// I need somehow to link the isPresented: $tabData.isCustomItemSelected so that I can toggle it from the BroadcastLiveView to close the modal, or if feasible signal from HostBroadcast.ViewModel the state change to MainTabBarData
             style: .fade)

My BroadcastLiveView.init is following 0.7.0 tag source code examples.

  typealias State = HostBroadcast.State
  typealias Event = HostBroadcast.Event
  
  @ObservedObject
  var context: Context<State, Event>
  
  init(context: Context<State, Event>) {
    self.context = context
    logInit(of: self)
  }

I'd love to understand if this somehow can happen in ViewModel context, I have a Feedback where I check if the button to close the view tapped but I lack understanding how to tell the MainTabBarData ObservableObject that isCustomItemSelected should be false.

@rpanichkin
Copy link

rpanichkin commented Apr 26, 2021

You can use context.binding(for: \.keyPath)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants