I am working on combining two feeds in the same view. They are held inside a ZStack enclosed by a NavigationStack. The issue arises when clicking on the tab bar item to navigate to the message view, which works fine. However, when coming back and clicking on a NavigationLink to navigate to a user profile page, this results in issues:
A NavigationLink is presenting a value of type “User,” but there is no matching NavigationDestination declaration visible from the location of the link. The link cannot be activated.
Note: Links search for destinations in any surrounding NavigationStack, then within the same column of a NavigationSplitView.
Here is the main view:
struct Feed: View {
@State private var path: NavigationPath = NavigationPath()
@State private var selectedView = "Events"
private let options = ["Events", "Posts"]
@State private var show = false
@State private var showNewTweetView = false
@State private var messageCount: String = ""
var body: some View {
NavigationStack(path: $path) {
ZStack{
EventFeed(path: $path).opacity(selectedView == "Posts" ? 0 : 1)
}
.navigationDestination(for: User.self, destination: { result in
SearchableUserProfile(user: result, path: $path)
})
.navigationDestination(for: String.self) { result in
ChatChannelView(
viewFactory: CustomUIFactory.shared,
channelController: ChatManager.shared.client.channelController(
for: try! ChannelId(cid: result),
messageOrdering: .topToBottom
)
)
.toolbar(.hidden, for: .tabBar)
.navigationBarBackButtonHidden(true)
}
.navigationTitle("Home")
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .topBarLeading) {
Picker("Select View", selection: $selectedView) {
ForEach(options, id: .self) {
Text($0)
}
}
.pickerStyle(MenuPickerStyle())
}
ToolbarItem(placement: .topBarTrailing) {
NavigationLink(destination: MessageView()) {
VStack{
Image(systemName: "ellipsis.message")
.font(.title)
Text(messageCount)
}
}
}
}
}
}
}
Here is the Event Feed view which is displayed inside the the Feed View:
struct EventFeed: View {
@State private var show = false
@State private var showNewTweetView = false
@State private var didFinishSetup = false
@EnvironmentObject var newEventViewModel: EventPostViewModel
@EnvironmentObject var viewModel : EventFeedViewModel
@State private var showComments = false
init(path: Binding<NavigationPath>){
UIScrollView.appearance().decelerationRate = .fast
self._path = path
}
@Binding var path: NavigationPath
var body: some View {
ScrollView{
LazyVStack(spacing: 40){
ForEach(viewModel.EventPost) { event in
EventFeedPost( event: event).onTapGesture {
}
Divider()
}
}.padding(.top,8)
}
}
Here is where the navigation occus when clicking on a event feed item to navigate to a user profile:
`struct EventFeedPost: View {
@EnvironmentObject var myEventsViewModel : MyEventFeedViewModel
@EnvironmentObject var localNotificationManger: LocalNotificationManager
@State private var showEventDetails = false
@State private var showComments = false
@ObservedObject var viewModel: EventFeedCellViewModel
@State private var showButtons = false
private var event: Event{
return viewModel.event
}
private var isGoing: Bool{
return event.isGoing ?? false
}
init(event: Event){
self.viewModel = EventFeedCellViewModel(event: event)
}
var body: some View {
VStack{
if let user = event.user{
HStack{
NavigationLink(value: user) {
CircularProfileImageVIew(user: user, size: .medium)
.clipShape(Circle())
Text(event.user?.fullname ?? "")
.foregroundColor(.black)
}
}
}
`
MessageView contains a customUI factory model from getstream.io that I didn’t really customize. I added no navigation stack besides FeedView.