我尝试根据编辑模式更改视图状态,何时编辑隐藏视图,当它不编辑时显示视图,当我使用更改并打印编辑模式值时它的工作但它在使用视图时不起作用.
struct TaskStateMark_Row: View {
@ObservedObject var task: Task
@Environment(\.editMode) private var editMode
var body: some View {
Group {
// Show and hide the view according to edit mode state
if let editMode = editMode?.wrappedValue {
if editMode == .inactive {
taskState
.onTapGesture(perform: onTapAction)
}
}
}
}
private var taskState: some View {
Group {
if task.isCompleted {
completedState
} else {
incompletedState
}
}
.frame(width: 44, height: 44)
}
private var incompletedState: some View {
ZStack{
fillCircle
circle
}
}
private var circle: some View {
Image(systemName: "circle")
.font(.system(size: 24))
.foregroundColor(task.wrappedPriority.color)
}
private var fillCircle: some View {
Image(systemName: "circle.fill")
.font(.system(size: 24))
.foregroundColor(task.wrappedPriority.color.opacity(0.15))
}
private var completedState: some View {
Image(systemName: "checkmark.circle.fill")
.symbolRenderingMode(.palette)
.foregroundStyle(.white, task.wrappedPriority.color)
.font(.system(size: 24))
}
}