0

I am trying to replicate the Add New Task feature in a macOS app. Exactly as it is implemented in the macOS official Reminders app. If I tap on the List then I can show the "Add Task Row". The row consists of a TextBox and few buttons.

The problem is that when I tap on the TextBox the row hides itself since the gesture of List is invoked. How can I make it work exactly like macOS Tasks app.

struct ContentView: View {
    
    @State private var editing: Bool = false
    @State private var taskName: String = ""
    
    var body: some View {
        List {
            ForEach(1...5, id: \.self) { index in
                Text("\(index)")
            }
            
            if editing {
                
                VStack(alignment: .leading) {
                    TextField("Enter task", text: $taskName)
                    HStack {
                        Button("Add Date") {
                           
                        }.buttonStyle(.bordered)
                        Button("Add Location") {
                           
                        }.buttonStyle(.bordered)
                    }
                }.onTapGesture {
                    
                }
            }
            
        }.listStyle(.plain)
            .gesture(TapGesture().onEnded({ _ in
                withAnimation {
                    editing.toggle()
                }
            }), including: editing ? .subviews  : .gesture)
           
    }
}
Mary Doe
  • 1,073
  • 1
  • 6
  • 22
  • 1
    What is the `macOS official Tasks app`? If it's not a macOS/system app, screenshots & gifs will help with those that don't have the app. – George Nov 24 '21 at 21:37
  • I meant the Reminders app – Mary Doe Nov 24 '21 at 22:08
  • The question is more related to showing and hiding the TextBox. – Mary Doe Nov 24 '21 at 22:38
  • Does this answer your question? [How to update attributes of a struct with TextFields made in ForEach](https://stackoverflow.com/questions/69139218/how-to-update-attributes-of-a-struct-with-textfields-made-in-foreach) – Magnas Nov 25 '21 at 07:37

0 Answers0