0
votes

I am controlling my backstack at the view model layer, as navigation structure of my app is the same in iOS and Android.

I have a concept of "topmost view model", for which no backstack should exist. Therefore, when displaying such a view model, I would like to close the existing ones.

IMvxNavigationService navigationService = GetFromSomewhere();

var existingViewModels = GetViewModelBackStack();

await navigationService.Navigate(newTopmostViewModel);

foreach (var viewModel in existingViewModels)
    await navigationService.Close(viewModel);

However, in Android, the above code leads to my application being closed.

Whether I place Close before or after the Navigate call doesn't matter, the result is the same.

MvvmCross 5.7.0, single activity, all navigation is fragment-based. Page view models correspond to full screen fragments.

I know this can be done at the view presenter layer using various fragment manager hacks, but I don't want to resort to those and keep as much logic at the cross-platform layer as possible.

Any suggestions or ideas?

1

1 Answers

1
votes

I understand why you want to keep most of your logic in the core. However, each platform handles navigation and back stack differently which is the reason why the presentation logic belongs to the platform layer.

I have faced the same problem before and the way I handled it was by creating presentation hints. (ex: ClearBackStackPresentationHint) that is handled by the presenters of each platform and implements the logic of clearing the back stack.

You can read more about presentation hints here