Fawzi Rifai
Fawzi Rifai

Reputation: 771

How to prevent covering a ScrollView embedded in ZStack when scrolling to the bottom of the ScrollView?

I have HStack and ScrollView in ZStack, how can I prevent the HStack from covering the bottom of ScrollView? I think there is a modifier to fix this issue, but I can’t remember it.

struct Messages: View {
    var body: some View {
        ZStack(alignment: .bottom) {
            ScrollView {
                VStack() {
                    MessagesList()
                }
            }
            MessageInput()
        }
    }
}

Upvotes: 0

Views: 559

Answers (1)

ScottM
ScottM

Reputation: 10452

You can drop the ZStack and declare the view that sticks to the bottom using the .safeAreaInset modifier, e.g.:

ScrollView {
  // etc.
}
.safeAreaInset(edge: .bottom) {
  MessageInput()
}

More information on Hacking with Swift and Apple’s developer docs

Upvotes: 3

Related Questions