{"action":"opened","issue":{"url":"https://api.github.com/repos/rid00z/FreshMvvm/issues/104","repository_url":"https://api.github.com/repos/rid00z/FreshMvvm","labels_url":"https://api.github.com/repos/rid00z/FreshMvvm/issues/104/labels{/name}","comments_url":"https://api.github.com/repos/rid00z/FreshMvvm/issues/104/comments","events_url":"https://api.github.com/repos/rid00z/FreshMvvm/issues/104/events","html_url":"https://github.com/rid00z/FreshMvvm/issues/104","id":178366513,"number":104,"title":"RemoveFromNavigation and then popping PageModel causes ReverseInit being called on removed FreshBasePageModel, instead of the one being popped","user":{"login":"theberserker","id":322416,"avatar_url":"https://avatars.githubusercontent.com/u/322416?v=3","gravatar_id":"","url":"https://api.github.com/users/theberserker","html_url":"https://github.com/theberserker","followers_url":"https://api.github.com/users/theberserker/followers","following_url":"https://api.github.com/users/theberserker/following{/other_user}","gists_url":"https://api.github.com/users/theberserker/gists{/gist_id}","starred_url":"https://api.github.com/users/theberserker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/theberserker/subscriptions","organizations_url":"https://api.github.com/users/theberserker/orgs","repos_url":"https://api.github.com/users/theberserker/repos","events_url":"https://api.github.com/users/theberserker/events{/privacy}","received_events_url":"https://api.github.com/users/theberserker/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-09-21T14:38:42Z","updated_at":"2016-09-21T14:38:42Z","closed_at":null,"body":"Let's say we have `FirstPageModel` and `SecondPageModel` in the current page model navigation stack and we are on `ThirdPageModel`. Then if we call:\r\n\r\n```\r\nCoreMethods.RemoveFromNavigation<SecondPageModel>();\r\nawait CoreMethods.PopPageModel(data);\r\n```\r\n\r\nthe `FirstPage` and `FirstPageModel` (at PopPageModel call) are resolved correctly, but I would expect that the `ReverseInit ` is called on `FirstPageModel`, which doesn't happen. Instead it is called on `SecondPageModel`, that was removed in the `RemoveFromNavigation` call. \r\n\r\nThe problem lies in `RemoveFromNavigation<T>()` implementation that does not rewire the link of `PreviousPageModel`. \r\nBelow is the proposed solution which works for us. It keeps the track of the next page model as we are looking for a match in linked list of previous page models. As the match is found, it links the previous and next node of removed one.\r\n\r\n```\r\n/// <summary>\r\n/// Removes specific page/pagemodel from navigation\r\n/// </summary>\r\npublic void RemoveFromNavigation<TPageModel> (bool removeAll = false) where TPageModel : FreshBasePageModel\r\n{\r\n    FreshBasePageModel nextPageModel = null;\r\n    foreach (var page in this._currentPage.Navigation.NavigationStack.Reverse().ToList())\r\n    {\r\n        if (page.BindingContext is TPageModel) \r\n        {\r\n            page.GetModel()?.RaisePageWasPopped ();\r\n            this._currentPage.Navigation.RemovePage (page);\r\n\r\n            bool isPreviousPageModelMatch = typeof(TPageModel) == nextPageModel?.PreviousPageModel?.GetType();\r\n            if (isPreviousPageModelMatch)\r\n            {\r\n                nextPageModel.PreviousPageModel = nextPageModel.PreviousPageModel.PreviousPageModel;\r\n            }\r\n            if (!removeAll)\r\n                break;\r\n        }\r\n        nextPageModel = nextPageModel == null ? _currentPageModel : nextPageModel.PreviousPageModel;\r\n    }\r\n}\r\n```\r\n"}}
{"actor":{"display_login":"theberserker"}}