Skip to content

SwiftUI implementation of KeyboardAccessory. This resolves the keyboard interactive dismissal animation issue.

License

Notifications You must be signed in to change notification settings

atlou/KeyboardAccessory

Repository files navigation

KeyboardAccessory

Problem

In SwiftUI, there is this bug where a bottom view will not follow the interactive dismissal of the keyboard.

Screenshot of the problem

Solution

Using this package, we can solve this problem and achieve the expected behavior.

Screenshot of the problem

Using the package

First, you need to add this package to your project dependencies. Then, you can import the package and use the .keyboardAccessory modifier on any type of scrolling view.

import SwiftUI
import KeyboardAccessory // Import the package

struct ContentView: View {
    var body: some View {
        VStack {
            ChatView()
                .keyboardAccessory {
                    InputView() // The view you want to use as an accessory
                }
                .scrollDismissesKeyboard(.interactively) // Dismiss the keyboard interactively
        }
    }
}

There is also a background closure that lets you add a background view.

ScrollView {}
    .keyboardAccessory {
        // Accessory
    } background {
        Rectangle()
            .fill(.regularMaterial)
    }

Credits

This package was built using BottomInputBarSwiftUI, which is used under the MIT license as per the user's permission. I only made some changes to the modifier and created a package. All credit for the actual implementation goes to frogcjn.

About

SwiftUI implementation of KeyboardAccessory. This resolves the keyboard interactive dismissal animation issue.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages