Skip to content

.searchable duplicates search input on Android if modifier added to NavigationStack #65

Description

@christoff-1992

The following example duplicates the search on Android. Whilst moving the modifier to the List resolves the issue this is not always preference on iOS.

My main issue is that I am trying to use both searchable and refreshable at the same time, however using refreshable with the search attached to the list causes Android to pull to refresh before the search is shown as its attached to the List and not the NavigationStack. This doesn't appear to be an issue with large titles either as the behaviour is the same if this is .inLine.

In iOS the behaviour is the same if this is attached to the list or the navigation, the pull to refresh will take into consideration that there's a search input been used and won't pull to refresh until the search has been scrolled to the top.

However in Android the only way to I've managed to get the pull to refresh to work at the correct time is to attach the .searchable modifier to the NavigationStack (This would be my preference for iOS anyways) however it then duplicates the search input.

struct Test: View {

  @State internal var searchText = ""

  var body: some View {
    TabView {
      NavigationStack {
        List(0..<100) { I in
          Text("Item \(i)")
        }
        // MARK: - Works but not preferred.
        //.searchable(text: $searchText)
        .navigationTitle("Entries")
      }
      // MARK: - Duplicates the search.
      .searchable(text: $searchText)
      .tabItem { Label("List", systemImage: "list.bullet")  }
    }
  }
}

Emulator:

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions