NavigationLink binding question

I have this code that is intended to walk a user through allowing notifications and Bluetooth. I am having an issue where the NavigationLink is never becoming active, and I am not quite sure where things are going wrong. Would love some help :smiley:.

struct OOBEState: Equatable {
  var allowedNotifications: Bool = false
  var allowedBluetooth: Bool = false
}

enum OOBEAction: Equatable {
  case allowNotifications
  case allowedNotifications(Bool)

  case allowBluetooth
  case allowedBluetooth(Bool)
}

let OOBEReducer = Reducer<OOBEState, OOBEAction, AppEnvironment> { state, action, env in
  switch action {
  case .allowNotifications:
    return Effect(value: .allowedNotifications(true))
  case .allowedNotifications(let isAllowed):
    state.allowedNotifications = isAllowed
    return .none

  case .allowBluetooth:
    return Effect(value: .allowedBluetooth(true))
  case .allowedBluetooth(let isAllowed):
    state.allowedBluetooth = isAllowed
    return .none
  }
}
.debug()

struct OOBEView: View {
  var store: Store<OOBEState, OOBEAction>

  var body: some View {
    WithViewStore(self.store) { viewStore in
      VStack {
        NavigationLink(
          destination: NextView(store: self.store),
          isActive: viewStore.binding(
            get: { $0.allowedNotifications },
            send: OOBEAction.allowedNotifications
          ),
          label: {
            Text("Navigate")
          }
        )
        Button("Allow Notificatons") {
          viewStore.send(.allowNotifications)
        }
      }
    }
  }
}

This may be a silly thing to ask, but I just wanna double check... do you have your OOBEView wrapped in a NavigationView somewhere? Otherwise the navigation link won't work.

When I ran your code locally it worked fine, as long as I wrapped it in a NavigationView.

OMG Not a silly thing to ask!

No, I didn't, and yes, now that I do, it works. WOOOOW. Thanks so much!

Terms of Service

Privacy Policy

Cookie Policy