Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introspecting TextFields or TextViews to set the inputView doesn't work within conditional Views #436

Open
2 tasks done
paescebu opened this issue Sep 28, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@paescebu
Copy link
Contributor

paescebu commented Sep 28, 2024

Description

Hi,

it seems there's a nasty edge case when using introspection on TextFields or TextViews within conditionals:

import SwiftUI
import SwiftUIIntrospect

struct ContentView: View {
    @State private var isShown: Bool = false
    @FocusState private var textFieldFocused
    @State private var textFieldContent = ""

    var body: some View {
        Form {
            Toggle("Show Keyboard", isOn: $isShown)
            if isShown {
                TextField("title", text: $textFieldContent, axis: .vertical)
                    .introspect(.textEditor, on: .iOS(.v18), customize: { textView in
                        let view = UIView()
                        view.backgroundColor = .red
                        view.frame = .init(origin: .zero, size: .init(width: 200, height: 100))
                        textView.backgroundColor = .red
                        textView.inputView = view
                    })
                    .onAppear {
                        textFieldFocused = true
                    }
                    .focused($textFieldFocused)
            }
        }
    }
}

The code above shows that the introspection sets the background color of the textView nicely, but the inputView only receives the right inputView after toggling the flag a second time to true.

Do you have any idea why that could be happening and whether this is solveable?

Kind regards!

Checklist

Expected behavior

No response

Actual behavior

No response

Steps to reproduce

No response

Version information

1.3.0

Destination operating system

iOS18

Xcode version information

Xcode 16.0

Swift Compiler version information

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant