I've been having an issue with my list where after removing an item, it gets removed correctly, but if I toggle between two branches on the same view, my list items get this weird leading padding.
Not sure how to explain it exactly, so I'm attaching a give of what happens.
https://i.stack.imgur.com/Y0npU.jpg
Here's my list row code:
if (/** condition **/) {
EmptyView()
} else {
ZStack(alignment: .center) {
NavigationLink(
destination: MovieDetailsView(movie: moviesVM.movie)) {
EmptyView()
}.opacity(0)
WebImage(url: moviesVM.movie.backdropUrl)
.resizable()
.placeholder {
Image("tile_placeholder")
.resizable()
.aspectRatio(aspectRatioW780Poster, contentMode: .fill)
.frame(maxHeight: 170)
.clipped()
}
.transition(.fade(duration: 0.5))
.aspectRatio(aspectRatioW780Poster, contentMode: .fill)
.frame(maxHeight: 170)
.clipped()
.overlay(TextOverlay(movieOrShow: moviesVM.movie))
}
.swipeActions(edge: .trailing, allowsFullSwipe: false) {
// buttons that invoke removal
}
}
And the list rows are instantiated inside the "profile" view, which looks like this:
NavigationView {
VStack {
if profileVM.profileRepository.profile == nil {
HStack(alignment: .center) {
Text("Please log in or sign up to use your watchlist. ☺️")
}
}
if profileVM.profileRepository.profile != nil {
HStack {
Text("Watched")
Toggle("Watched", isOn: $profileVM.defaultTab)
.onChange(of: profileVM.defaultTab, perform: { _ in
profileVM.updateDefaultTab()
})
.labelsHidden()
.tint(Constants.MUSH_BLUE)
Text("Watchlist")
}
// this is where my view "branches" depending on the toggle
HStack {
if !profileVM.defaultTab {
ZStack(alignment: .center) {
List {
ForEach(Array(profileVM.profileRepository.watchedMovies), id: \.id) { movie in
MovieListRow(moviesVM: MoviesViewModel(profileRepository: profileVM.profileRepository, movie: movie, fromProfile: true))
.id(movie.id)
.listRowInsets(EdgeInsets())
.listRowSeparator(.hidden)
}
}
.listStyle(InsetListStyle())
if profileVM.profileRepository.watchedMovies.count == 0 {
Text("Nothing here yet :)")
}
}
} else {
ZStack(alignment: .center) {
List {
ForEach(Array(profileVM.profileRepository.watchlistedMovies), id: \.id) { movie in
MovieListRow(moviesVM: MoviesViewModel(profileRepository: profileVM.profileRepository, movie: movie, fromProfile: true))
.id(movie.id)
.listRowInsets(EdgeInsets())
.listRowSeparator(.hidden)
}
}
.listStyle(InsetListStyle())
if profileVM.profileRepository.watchlistedMovies.count == 0 {
Text("Nothing here yet :)")
}
}
}
}
}
}
.navigationTitle("Watchlist")
}