Image generate with AI

Member-only story

Drag gesture with SwiftUI

Nicola De Filippo
2 min readMay 9, 2024

In this post, we’ll learn how to use a drag gesture to check the scrolling direction of a list. The goal is to hide the tab bar and change the appearance of a floating button based on whether the list is scrolling up or down, similar to the behavior of the Gmail app. (Check the code from previous post floating-button-in-swiftui).

First step: Define the two different styles for the Floating Button:

struct FullFB: View {
var body: some View {
Label("write", systemImage: "pencil")
.font(.title.weight(.semibold))
.padding()
.background(.pink)
.foregroundStyle(.white)
.clipShape(RoundedRectangle(cornerSize: CGSize(width: 40, height: 40)))
.shadow(radius: 4, x: 0, y: 4)
}
}

struct SmallFB: View {
var body: some View {
Image(systemName: "pencil")
.font(.title.weight(.semibold))
.padding()
.background(.pink)
.foregroundStyle(.white)
.clipShape(Circle())
.shadow(radius: 4, x: 0, y: 4)
}
}

The code should be self-explanatory: the first style is a rounded rectangle button featuring both text and an icon, while the second style is a circular button with only an icon.

Now take a look to the list:

List(initList(), id:\.self) { mail in
HStack {…

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Nicola De Filippo
Nicola De Filippo

Written by Nicola De Filippo

Software Engineer and Entrepreneur

Responses (1)

Write a response

Hi, is this approach working on iOS < 18.0 too?