'SwiftUI Emoji Keyboard hidden with ScrollView

When I try below code and show Emoji keyboard, keyboard will hide with Emoji keyboard horizontal scroll.

I applied "keyboardDismissMode" to make keyboard hide with scrollview but I think "keyboardDimissMode" apples Emoji keyboard's ScrollView also. so I would like to apply that only ScrollView in the ContentView. Are there any solutions?

struct ContentView: View {

@State private var text: String = ""

var body: some View {
    ScrollView {
        TextField("Text", text: $text)
    }
    .onAppear {
        UIScrollView.appearance().keyboardDismissMode = .interactive
    }
}

}

Sample



Solution 1:[1]

This is apparently a bug in Apple's keyboard implementation. I ran into the same problem just now and filed a bug report. It also happened with keyboardDismissMode = .onDrag.

There is a workaround when you only want this keyboard dismiss behavior for Lists. In this case, you can simply use

UITableView.appearance().keyboardDismissMode = .interactive
–––––––––––

The reason this works is that Apple uses a UICollectionView for laying out their Emoji keyboard. Both UITableView and UICollectionView inherit from UIScrollView, so when you set

UIScrollView.appearance().keyboardDismissMode = .interactive
––––––––––––

it also affects the Emoji keyboard and the bug occurs. When only changing the UITableView's appearance, it doesn't affect UICollectionView and thus the bug does not occur.

If you need this behavior with LayzHGrid, LazyVGrid, or ScrollViews in general, I'm afraid that there is no working solution currently (to my knowledge).

Reference

For further information, please also refer to this question:
SwiftUI - Close Keyboard on Scroll

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1