Monday, June 29, 2026
HomeiOS Developmentios - SwiftUI - Repair animation bounce when utilizing searchable with out...

ios – SwiftUI – Repair animation bounce when utilizing searchable with out a record

[ad_1]

Hoping somebody might know of an answer for this animation difficulty as I am unable to discover a option to make it work!

Im utilizing ForEach inside LazyVStack inside ScrollView. I’ve a .searchable modifier on the scrollview. Once I enter/cancel the search subject the navigation bar and search subject animate upwards/downwards however my scrollview jumps with out animation.

if I add .animation(.easeInOut) after .searchable it animates accurately. Nevertheless there’s two points, its deprecated in iOS 15.0, and it animates the record objects in loopy methods as they seem and are filtered and many others.

When utilizing a Record it additionally works however cannot be customised in the way in which I would like. This difficulty is current in simulator, in previews and on machine.

Does anybody know the way I can get this to animate accurately with out resorting to utilizing Record (Which does not have the customisability I would like for the record objects)?

Thanks on your assist!

A slimmed down model of what I am doing to recreate the problem:

import SwiftUI

struct ContentView: View {
    @State var searchText: String = ""
    
    var physique: some View {
        NavigationView {
            ScrollView(.vertical) {
                CustomListView()
            }
            .navigationTitle("Misbehaving ScrollView")
            .searchable(textual content: $searchText, placement: .computerized)
            // This .animation() will repair the problem however create many extra...  
//            .animation(.easeInOut)
        }
    }
}

struct CustomListView: View {
    @State non-public var listItems = ["Item 0", "Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6", "Item 7", "Item 8", "Item 9", "Item 10"]
    
    var physique: some View {
        LazyVStack(alignment: .main, spacing: 10) {
            ForEach(listItems, id: .self) { merchandise in
                CustomListItemView(merchandise: merchandise)
                    .padding(.horizontal)
            }
        }
    }
}

struct CustomListItemView: View {
    @State var merchandise: String
    
    var physique: some View {
        ZStack(alignment: .main) {
            RoundedRectangle(cornerRadius: 20, type: .steady)
                .foregroundColor(.inexperienced.opacity(0.1))
            VStack(alignment: .main, spacing: 4) {
                Textual content(merchandise)
                    .font(.headline)
                Textual content(merchandise)
                    .font(.subheadline)
            }
            .padding(25)
        }
    }
}



struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

An much more primary instance that shows the identical difficulty:

import SwiftUI

struct SwiftUIView: View {
    @State var textual content = ""
    
    var physique: some View {
        NavigationView {
            ScrollView {
                Textual content("1")
                Textual content("2")
                Textual content("3")
                Textual content("4")
                Textual content("5")
                Textual content("6")
            }
        }
        .searchable(textual content: $textual content)
    }
}

struct SwiftUIView_Previews: PreviewProvider {
    static var previews: some View {
        SwiftUIView()
    }
}

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments