0

I have a chat app in a SwiftUI project that uses a List. I don't wish to use a ScrollView/LazyVStack.

I am having issues moving the content up when the keyboard appears and the List is already scrolled to the bottom. The keyboard just covers the content until the user scrolls it up. Prior to swiftUI I would achieve this by listening to keyboard changes and setting the tableView.contentOffset to match the keyboard showing.

Is there anyway to do a similar thing using a SwiftUI List? Other than inverting the List I can't find anyway to smoothly have the content move up as the keyboard shows. Currently I am just listening to keyboardDidShow and using scrollView proxy to scroll the List after the keyboard has shown but there is a delay and it is not smooth:

.onReceive($scrollListForKeyboardAppearance) { value in
    withAnimation {
        scrollView.scrollTo("LastMessageInList")
    }
}

I also tried to observe the keyboard height and add a padding to the List with the keyboard height but this doesn't work as well.

alionthego
  • 7,218
  • 9
  • 45
  • 92

0 Answers0