swiftui textfield is extremely laggy

Viewed 113

I'm having issues where as more text is being typed into the textfield, the application (Mac) becomes more and more laggy.

class Action: ObservableObject, Identifiable {
    var id = String(UUID().uuidString.prefix(7))
    @Published var actionType = ActionType.display
    @Published var arguments = [String:ValueType]()
}

struct AnalyticsKeyValuePairView: View {
    var state: Action
    let initialKey : String
    @State var stateKey: String
    @State var value: String
    init(state: Action, initialKey: String) {
        self.initialKey = initialKey
        self.state = state
        self._stateKey = State(initialValue: initialKey)
        self._value = State(initialValue: state.arguments[initialKey]!.stringValue!)
    }
    var body: some View {
        HStack {
            TextField("key", text: $stateKey) { (b) in
                
            } onCommit: {
                if initialKey != stateKey {
                    state.setArgument(nil, forKey: initialKey)
                }
                state.setArgument(.string(value), forKey: stateKey)
            }

            Spacer()
            
            TextField("value", text: $value) { (_) in
                
            } onCommit: {
                if initialKey != stateKey {
                    state.arguments[initialKey] = nil
                }
                state.setArgument(.string(value), forKey: stateKey)
                
            }
    }
}

in instruments you can see a lot core animation activity

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

0 Answers
Related