WWDC22 SALE: Save 50% on all my Swift books and bundles! >>

Leaving a swipeAction half-swiped breaks all my cells

Forums > SwiftUI

I’m using iOS 15’s .swipeActions() in a List. Basically, if the user half-swipes without completing the action, then leaves it hanging and navigates to a different view, all cells in the entire app seem to break (button action no longer works, but scrolling does).

Then when the user returns to the view they half-swiped on, the cells have shifted. The wild part is, I can cause this bug by leaving the swipeAction hanging on anything. Even just doing this on Text in a List will cause the bug:

List {
    Text("Swipe this")
        .swipeActions() {
            Button("Remove", role: .destructive) {
                print("Swiped")
            }
        }
}

I just have no idea what could be causing this. If it helps, here's the beginning of my view hierarchy in the parent view. The parent view shows subviews when the user taps an icon on the custom toolbar, using an EnvironmentObject enum. Doing this (navigating to another view) with a row left half-swiped is what breaks the app.

ZStack {

    Color.mainBackground
        .ignoresSafeArea()

    VStack(spacing: 0) {
        GlobalToolbar()

        switch global.sectionShowing {

        case .heroPage:
            NavigationView {
                WrappedDetailView()
            }
            .navigationViewStyle(StackNavigationViewStyle())

        case .tank:
            TankView(vm: vm)
        case .damage:
            DamageView(vm: vm)
        case .support:
            SupportView(vm: vm)
        case .favorites:
            FavoritesView(vm: vm)
        case .aboutPage:
            AboutPage()
        case .launchPage:
            LaunchPage()
        case .privacyPolicy:
            PrivacyPolicy()
        case .none:
            TankView(vm: vm)
        }
        Spacer()
    }
}
.preferredColorScheme(.dark) // Force dark mode
.onAppear {
    loadSettings()
}

   

Hacking with Swift is sponsored by RevenueCat

SPONSORED You know StoreKit, but you don’t want to do StoreKit. RevenueCat makes it easy to deploy, manage, and analyze in-app subscriptions on iOS and Android so you can focus on building your app.

Explore the docs

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.