2

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

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.