I have the following view:
My trouble is when a list item moves between upFrontAlters
and otherAlters
inside FrontViewModelHelper which just has the referenced properties as publishable. The row moves between the section, but the view changes that would go along with isOtherView
don't toggle with it. It's stuck as which ever one it was in when the app started.
struct FrontViewInternal: View {
@StateObject var state: FrontViewModelHelper
let dispatch: (FrontActions) -> Void
var body: some View {
let textBinding: Binding<String> = Binding(
get: { state.search },
set: { search in dispatch(FrontActions.FilterAlters(search: search))}
)
NavigationView {
LazyVStack(alignment: .leading, pinnedViews: [.sectionHeaders]) {
Section(header: Text("Front Alters")) {
if (state.upFrontAlters.isEmpty) {
Text("No Up Front Alters!")
} else {
ForEach(state.upFrontAlters, id: \.id) { alter in
FrontOtherRowView(
id: alter.id,
avatarUrl: alter.avatarUrl,
hexColor: alter.colorHex,
name: alter.name,
pronouns: alter.pronouns,
dispatch: dispatch,
isOtherView: false
)
}
}
}
Divider()
Section(header: Text("Other Alters")) {
ForEach(state.otherAlters, id: \.id) { alter in
FrontOtherRowView(
id: alter.id,
avatarUrl: alter.avatarUrl,
hexColor: alter.colorHex,
name: alter.name,
pronouns: alter.pronouns,
dispatch: dispatch,
isOtherView: true
)
}
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.searchable(text: textBinding)
.background(Color.background)
.navigationTitle("Alters")
.padding()
.navigationBarItems(
trailing: Button(
action: {},
label: {
Image(systemName: "plus.app")
}
)
)
}
}
}