Tuesday, August 16, 2022
HomeiOS Developmentios - SwiftUI - Repair animation leap when utilizing searchable with out...

ios – SwiftUI – Repair animation leap when utilizing searchable with out a listing


Hoping somebody might know of an answer for this animation difficulty as I can not discover a technique 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. Nonetheless there’s two points, its deprecated in iOS 15.0, and it animates the listing gadgets in loopy methods as they seem and are filtered and so forth.

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

Does anybody understand how I can get this to animate accurately with out resorting to utilizing Listing (Which does not have the customisability I want for the listing gadgets)?

Thanks to your assist!

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

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 difficulty 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 fundamental 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()
    }
}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular