SwiftPrettyPrint icon indicating copy to clipboard operation
SwiftPrettyPrint copied to clipboard

infinity-loop when include `@FocusState`

Open sahara-ooga opened this issue 2 years ago • 2 comments

Inputing an object containing @FocusState will cause an infinite loop.

A temporary fix to not output anything in FocusState object has been included in #182, but no fundamental fix has been made yet.

sahara-ooga avatar May 18 '22 10:05 sahara-ooga

@YusukeHosonuma Can you provide a simple code sample to reproduce the event?

sahara-ooga avatar May 18 '22 11:05 sahara-ooga

As follows.

import SwiftUI
import SwiftPrettyPrint

enum FocusableField: Hashable {
    case email
    case password
}

struct ContentView: View {
    @FocusState private var focus: FocusableField?

    var body: some View {
        TextField("email", text: .constant(""))
            .focused($focus, equals: .email)
            .onChange(of: focus) { _ in
                Pretty.prettyPrintDebug(self) // ⚠️ Occur infinity-loop when focus to `email` TextField.
            }
    }
}
image

YusukeHosonuma avatar May 18 '22 11:05 YusukeHosonuma