Xamarin.forms: [Shell, iOS] Navigation from SearchHandler.OnItemSelected override failing

Created on 27 Mar 2019  ·  14Comments  ·  Source: xamarin/Xamarin.Forms

Description

I have a MonkeySearchHandler, which derives from SearchHandler. In my OnItemSelected override I want to navigate to the MonkeyDetailsPage (which is registered in AppShell.xaml.cs). Here's my OnItemSelected override:

        protected override async void OnItemSelected(object item)
        {
            base.OnItemSelected(item);
            ItemsSource = null;
            //await Task.Delay(1000);
            await (App.Current.MainPage as Xamarin.Forms.Shell).GoToAsync("app://xamarin.com/xaminals/animals/monkeys/monkeydetails");
        }

Navigation tries to occur, in that the MonkeyDetailsPage constructor is invoked. However, the page isn't displayed (remains on the MonkeysPage). But if you uncomment the Task.Delay line, navigation then occurs successfully.

Note: this issue only occurs on iOS. On Android, navigation occurs as expected.

Steps to Reproduce

  1. Run the attached sample.
  2. Browse to the Monkeys page (bottom tab).
  3. Use the SearchHandler to bring up some results, and select one of them.

Expected Behavior

The MonkeyDetailsPage is navigated to (currently an empty page until I pass data into it).

Actual Behavior

The Monkeys page remains active, and navigation doesn't occur (although the MonkeyDetailsPage constructor is invoked).

Basic Information

  • Version with issue: 4.0-pre7
  • Last known good version: N/A
  • IDE: VSMac 7.8.3
  • Platform Target Frameworks:

    • iOS: 12.1

Reproduction Link

Xaminals.zip

shell 4 high impact iOS 🍎 bug

Most helpful comment

I'm seeing the same thing. It basically makes SearchHandler unusable for me. Ideally, OnQueryChanged and OnItemSelected should return a Task, correct? Right now, they return void, and marking them async is a janky way of trying to make async calls inside those methods.

Anyway, this is my bump. ::bump::

All 14 comments

still an issue in pre10

Any update on this issue?
It still doesn't work in 4.0.0.482894

I have the same issue unless I un-comment the task.delay … on android the code works without the delay

I'm seeing this in 4.2.0.709249 with iOS. But it only happens from the search handler. If I make a GoToAsync() call with the same URI from a different page (button click command), it works just fine. I was able to lower the delay to 400ms from 1000 and it still worked.

Having the same issue. GotoAsync / PushAsync don't actually navigate when using them from SearchHandler - OnItemSelected in iOS.

Any updates as putting in a delay is not ideal.

Logged in Mar and issue still exists in Oct.

I found that if I specify animated: false in the Shell.Current.Navigation.PushAsync(), I can lower the delay to 500 ms with Forms 4.3. And it no longer chrashes, instead nothing happens and you get a warning in the Debug window:

pushViewController:animated: called on <Xamarin_Forms_Platform_iOS_ShellSectionRenderer 0x7ff8f8600800> while an existing transition or presentation is occurring; the navigation stack will not be updated.

But no, it is far from ideal...

Any news about this?

I'm seeing the same thing. It basically makes SearchHandler unusable for me. Ideally, OnQueryChanged and OnItemSelected should return a Task, correct? Right now, they return void, and marking them async is a janky way of trying to make async calls inside those methods.

Anyway, this is my bump. ::bump::

I'm still getting this in 4.6

I'm still getting this issue in XF 4.7
iOS 13.5
PushAsync();
GoToAsync();
doesn't navigate
only PushModalAsync(); do the navigation and i need that page not to be modal page
any ideas ?

I've still got this in 4.7 too.
Is the only workaround really to delay 500ms+ ?!

I too would really like to see an actual non-hacky solution for this. It's been nearly 18 months since this issue was opened. Please give the Shell SearchHandler some async methods that make sense.

EDIT: I see this has been marked for work in 5.0.0. Yay!

Can confirm this is still an issue, I thought a work around might be using a TapGestureRecogniser on the DataItem. Haven't tested it yet though.

Was this page helpful?
0 / 5 - 0 ratings