iOS 16 specific issue with SharedState when using UIViewRepresentable? #2950
Unanswered
catienza022
asked this question in
Q&A
Replies: 1 comment
-
Hi @catienza022, this is an interesting use case that we should get some docs on. We have docs on using The fix is to observe changes to the text in the representable. In particular, in public struct ParticipantSearchTextField: UIViewRepresentable {
…
@State var token = NSObject()
public func makeUIView(context: Context) -> UITextField {
…
token.observe {
textField.text = store.text
}
…
}
} With that it should work. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi all 👋
I'm building a custom UISearchTextField with custom tokens and behavior. One of the UX requirements is if the text field has no text but it does have a token and a user taps backspace, the last token in the UI is deleted. Unfortunately there doesn't seem to be a way with SwiftUI's
TextField
to ever detect if backspace was tapped when the field is already empty - we never receive an action. I've tried a few hacks with no luck, so I wrote aUIKit
component to handle it.If a user is typing text into the text field and they hit
Return
to commit a token, their search text should be wiped and a token committed to the UI. Everything works fine, except for one really strange issue - the text never gets cleared oniOS 16.x
. Even if I update the shared text, feed an action back down into the child feature - I never get theupdateUIView
call to update the text field's text. Switch the sim/ device to iOS 17 and everything works as expected.This may be a vanilla bug, but posting in case it's not. If anyone has any ideas to work around this I would be beyond grateful. I am at a loss and losing hair at this point 😄 . Minimal project that reproduces attached at bottom.
Some code:
Minimal project that reproduces. Run on iOS 17 and then 16 sim:
TCAMinimalWorkingProjects.zip
Beta Was this translation helpful? Give feedback.
All reactions