2

I have a chat app and want to add a toolbar to the keyboard similar to an inputAccessoryView previously prior to SwiftUI.

I know iOS15 now has the option to add a toolbar using the following (from hackingwithswift)

.toolbar {
    ToolbarItemGroup(placement: .keyboard) {
        Button("Click me!") {
            print("Clicked")
        }
    }
}

However this only displays when the keyboard is visible. As with all chat apps I want this "accessoryView" to be permanently visible. I am able to do my own custom implementation using views however I want to know if it is possible to use a keyboard toolbar and have it permanently displayed?

This would help greatly with the animations as opposed to using custom implementations.

Once again, prior to SwiftUI this would be achieved using an inputAccessoryView and having that viewController overriding inputAccessoryView and canBecomeFirstResponder to have the toolbar floating at the bottom of the screen when the keyboard is not visible. I want to achieve that in SwiftUI with a toolbar.

alionthego
  • 8,508
  • 9
  • 52
  • 125
  • So why you do not make that view? It is not difficult to add that custom view to top of keyboard, you do not need even iOS15 for that! – ios coder Oct 06 '21 at 00:02
  • I’ve done it already. It’s the animations when the keyboard displays and disappears that aren’t quite right. – alionthego Oct 06 '21 at 00:03
  • I can solve the animation issue show your code and I try. – ios coder Oct 06 '21 at 00:04
  • I don't want to change the purpose of this post but I have a VStack { // List with messages HStack { // Chat Input View } }. So the VStack has the List and the input view. The inputView has .layoutPriority(1.0) and sets vertical frame explicitly. – alionthego Oct 06 '21 at 00:15
  • Then let stay on purpose. – ios coder Oct 06 '21 at 00:22

0 Answers0