Skip to content
This repository has been archived by the owner on Nov 5, 2021. It is now read-only.

Commit

Permalink
Hide Add Task button if current relation is empty to fix anitab-org…
Browse files Browse the repository at this point in the history
…#128

I have used `@ViewBuilder` attribute to pass the appropriate `View` to the `navigationBarItems(trailing:)` method. Before collecting data from the server the `id` of `currentRelation` is 0 and if the user doesn't have any Relation then the server response for `id` would be nil. This is why I have checked both of the conditions.
  • Loading branch information
Zoha131 committed Oct 14, 2020
1 parent d8c4b70 commit 54e5d12
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions mentorship ios/Views/Relation/Relation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ struct Relation: View {
}
}
}

@ViewBuilder func trailingNavigationBarItem() -> some View {
if let id = relationViewModel.currentRelation.id, id != 0 {
Button(LocalizableStringConstants.addTask) {
self.relationViewModel.addTask.toggle()
}
}
}

var body: some View {
NavigationView {
Expand Down Expand Up @@ -116,9 +124,7 @@ struct Relation: View {
}
.environment(\.horizontalSizeClass, .regular)
.navigationBarTitle("Current Relation")
.navigationBarItems(trailing: Button(LocalizableStringConstants.addTask) {
self.relationViewModel.addTask.toggle()
})
.navigationBarItems(trailing: trailingNavigationBarItem())
.sheet(isPresented: $relationViewModel.addTask) {
AddTask(relationViewModel: self.relationViewModel)
}
Expand Down

0 comments on commit 54e5d12

Please sign in to comment.