Reputation: 20158
I have the following code:
struct FocusStateTestView: View {
@State var showSheet = false
var body: some View {
VStack {
Text("FocusStateTestView")
Button {
showSheet.toggle()
} label: {
Text("present sheet")
}
}
.sheet(isPresented: $showSheet) {
SheetTestView()
}
}
}
struct SheetTestView: View {
@State var text = ""
var body: some View {
NavigationView {
Form {
Text("hello")
}
.searchable(text: $text)
}
}
}
The sheet presents fine:
Problem:
keyboard does not show up. I cannot type in that text search textfield.
When the sheet is presented the console logs this:
2022-03-24 15:40:11.230674-0600 myApp[92118:2113819] [UIFocus] Failed to update focus with context <UIFocusUpdateContext: 0x6000026bc8c0: previouslyFocusedItem=(null), nextFocusedItem=(null), focusHeading=None>. No additional info available. 2022-03-24 15:40:13.455689-0600 myApp[92118:2113819] [UIFocus] Deferring focus update to item <UISearchBarTextField: 0x14c89da00>. No additional info available. 2022-03-24 15:40:13.455920-0600 myApp[92118:2113819] [UIFocus] Failed to update focus with context <UIFocusUpdateContext: 0x6000026b7660: previouslyFocusedItem=(null), nextFocusedItem=(null), focusHeading=None>. No additional info available.
I then try to tap on the search field, and the console shows this:
objc[92118]: Class _PathPoint is implemented in both /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore (0x12b85f338) and /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/TextInputUI.framework/TextInputUI (0x1395d4fe8). One of the two will be used. Which one is undefined. objc[92118]: Class _PointQueue is implemented in both /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore (0x12b85f310) and /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/TextInputUI.framework/TextInputUI (0x1395d5010). One of the two will be used. Which one is undefined. 2022-03-24 15:40:26.005733-0600 myApp[92118:2113819] [UIFocus] Deferring focus update to item <UISearchBarTextField: 0x14c89da00>. No additional info available. 2022-03-24 15:40:26.005824-0600 myApp[92118:2113819] [UIFocus] Failed to update focus with context <UIFocusUpdateContext: 0x60000269d9a0: previouslyFocusedItem=(null), nextFocusedItem=(null), focusHeading=None>. No additional info available.
Interestingly enough, the same code works on iPhone. I still get some weird logs about it when on iPhone:
objc[92218]: Class _PathPoint is implemented in both /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore (0x12aff7338) and /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/TextInputUI.framework/TextInputUI (0x13f380fe8). One of the two will be used. Which one is undefined. objc[92218]: Class _PointQueue is implemented in both /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore (0x12aff7310) and /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/TextInputUI.framework/TextInputUI (0x13f381010). One of the two will be used. Which one is undefined. 2022-03-24 15:43:25.454520-0600 myApp[92218:2116972] [HardwareKeyboard] -[UIApplication getKeyboardDevicePropertiesForSenderID:shouldUpdate:usingSyntheticEvent:], failed to fetch device property for senderID (778835616971358211) use primary keyboard info instead. 2022-03-24 15:43:25.457774-0600 myApp[92218:2116972] [HardwareKeyboard] -[UIApplication getKeyboardDevicePropertiesForSenderID:shouldUpdate:usingSyntheticEvent:], failed to fetch device property for senderID (778835616971358211) use primary keyboard info instead.
But on iPhone at least it works.
How can I fix this? How can I properly present the keyboard on the iPad and search??
I have the same problem both on simulator and device. running Xcode Version 13.3 (13E113).
Upvotes: 4
Views: 4858
Reputation: 163
In my case, I solved it by adding this:
.searchable(text: $text, placement: .navigationBarDrawer(displayMode: .always))
It changes search bar's appearance a little, but it works for me.
Upvotes: 3