Skip to content

Instantly share code, notes, and snippets.

@CrystalKnightCodes
Created May 24, 2021 19:48
Show Gist options
  • Save CrystalKnightCodes/2c86d57c8f3f504e392b844c50392ec3 to your computer and use it in GitHub Desktop.
Save CrystalKnightCodes/2c86d57c8f3f504e392b844c50392ec3 to your computer and use it in GitHub Desktop.
M1 Code issue
import SwiftUI
import ComposableArchitecture
struct HotlistSelector: View
{
let store: Store<HotlistManagementState, HotlistManagementAction>
var body: some View {
WithViewStore(store) { (viewStore: ViewStore<HotlistManagementState, HotlistManagementAction>) in
NavigationView {
List {
Toggle(
"Select all lists",
isOn: viewStore.binding(get: \.allListsSelected, send: { .setAllSelected($0) })
)
.disabled(viewStore.listSelections.isEmpty)
.animation(.default)
ForEachStore(store.scope(state: \.sections, action: sectionAction)) { sectionStore in
WithViewStore(sectionStore) { vs in
Section(header: Text(vs.source.description)) {
ForEachStore(sectionStore.scope(state: \.hotlists), content: Row.init)
}
}
}
}
.listStyle(GroupedListStyle())
.navigationTitle("List Management")
}
}
}
typealias ListActionData = (id: UUID, action: HotlistManagementAction.List)
typealias SectionActionData = (source: HotlistSource, listData: ListActionData)
private func sectionAction(for sectionData: SectionActionData) -> HotlistManagementAction {
.listAction(sectionData.source, sectionData.listData.id, sectionData.listData.action)
}
private struct Row: View
{
var store: Store<HotlistSelection, HotlistManagementAction.List>
var body: some View {
WithViewStore(store) { viewStore in
HStack {
Image(viewStore.isSelected ? .checkmarkCircleFill : .circle)
.foregroundColor(viewStore.isSelected ? Color.rekorGreen : Color.rekorGrey)
.font(.system(size: 20))
Text(viewStore.name)
Spacer()
}
.contentShape(Rectangle())
.onTapGesture { viewStore.send(.toggleSelected) }
.transition(.opacity)
.animation(.default, value: viewStore.isSelected)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment