Login required for access
In order to watch this lesson, you'll need to login to the website.
ScrollViewReader and Proxy Auto Message Scrolling
SwiftUI Firebase Real Time Chat

In order to auto-scroll the messages to the last send message, we'll utilize the ScrollViewReader component.

private var messagesView: some View {    VStack {        ScrollView {            ScrollViewReader { scrollViewProxy in                VStack {                    ForEach(vm.chatMessages) { message in                        MessageView(message: message)                    }                                        HStack{ Spacer() }                    .id(Self.emptyScrollToString)                }                .onReceive(vm.$count) { _ in                    withAnimation(.easeOut(duration: 0.5)) {                        scrollViewProxy.scrollTo(Self.emptyScrollToString, anchor: .bottom)                    }                }            }        }        .background(Color(.init(white: 0.95, alpha: 1)))        .safeAreaInset(edge: .bottom) {            chatBottomBar                .background(Color(.systemBackground).ignoresSafeArea())        }    }}

Comments (0)
HELP & SUPPORT