{"id":13710238,"url":"https://github.com/TinyStuff/TinyNavigationHelper","last_synced_at":"2025-05-06T18:34:39.925Z","repository":{"id":53145472,"uuid":"100621623","full_name":"TinyStuff/TinyNavigationHelper","owner":"TinyStuff","description":"TinyNavigationHelper is a library that is created for you that want to abstract the navigation without installing a bigger MVVM framework.","archived":false,"fork":false,"pushed_at":"2021-04-04T16:23:05.000Z","size":163,"stargazers_count":17,"open_issues_count":3,"forks_count":2,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-11-05T14:59:36.434Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TinyStuff.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-08-17T16:00:50.000Z","updated_at":"2023-12-07T12:53:01.000Z","dependencies_parsed_at":"2022-08-27T20:02:13.904Z","dependency_job_id":null,"html_url":"https://github.com/TinyStuff/TinyNavigationHelper","commit_stats":null,"previous_names":["dhindrik/tinynavigationhelper"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TinyStuff%2FTinyNavigationHelper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TinyStuff%2FTinyNavigationHelper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TinyStuff%2FTinyNavigationHelper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TinyStuff%2FTinyNavigationHelper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TinyStuff","download_url":"https://codeload.github.com/TinyStuff/TinyNavigationHelper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224521654,"owners_count":17325274,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T23:00:53.431Z","updated_at":"2024-11-13T20:31:32.585Z","avatar_url":"https://github.com/TinyStuff.png","language":"C#","funding_links":[],"categories":["Plugins"],"sub_categories":[],"readme":"# Build status\t\t\n\u003cimg src=\"https://io2gamelabs.visualstudio.com/_apis/public/build/definitions/be16d002-5786-41a1-bf3b-3e13d5e80aa0/7/badge\" alt=\"Build status\" /\u003e\n\n# TinyNavigationHelper\nTinyNavigationHelper is a library that is created for you that want to abstract the navigation without installing a bigger MVVM framework. \n\nToday there are only an implementation for Xamarin.Forms, but it created in a way that it will be possible to create implementatons for other platforms as well.\n\n## How to install\nFor your Xamarin.Forms project install the package from NuGet:\n\n```\nInstall-Package TinyNavigationHelper.Forms\n```\n\nIf you want to use navigation from a project that not has references to Xamarin.Forms (for example if you have your ViewModels in a separete project for use on other platforms), install the abstraction package for that project.\n\n```\nInstall-Package TinyNavigationHelper.Abstraction\n```\n\n## How to configure navigation for Xamarin.Forms\n\n```cs\n// Option 1:\nvar navigationHelper = new NavigationHelper(this);\nnavigationHelper.RegisterView\u003cMainView\u003e(\"MainView\");\n\t\t\n// Option 2: Register single views\t\t\nvar navigationHelper = new FormsNavigationHelper(this);\t\t\nnavigationHelper.RegisterView(\"MainView\", typeof(MainView));\t\t\n\t\t\n// Option 3: Register all views (pages) that is inherited from Page\t\t\n// The class name will be the key. To use this, you need to add using System.Reflection;\t\t\nvar asm = typeof(App).GetTypeInfo().Assembly;\t\t\nnavigationHelper.RegisterViewsInAssembly(asm);\n```\nIf you want to use it with an IoC instance you need to register the specific instance in the IoC container. The example below is how to register in Autofac, but you can use the container you prefer.\n\n```cs\nvar containerBuilder = new ContainerBuilder();\ncontainerBuilder.RegisterInstance\u003cINavigationHelper\u003e(navigationHelper);\n\nvar container = containerBuilder.Build();\n```\n## How to use TinyNavigationHelper\nThere are two ways to use the navigation helper. To resolve the INavigationHelper interface via foreample constructor inbjection, or to access it via the Current property on the NavigationHelper class in the TinyNavigationHelper.Abstraction namespace.\n\n```cs\nvar navigationHelper = NavigationHelper.Current;\n```\n\n### Navigate\nTo navigate to a page use the NavigateTo method and the key you registered for the page.\n\n```cs\nawait navigationHelper.NavigateToAsync(\"MainView\");\n```\n\n#### Navigate with parameter\nThe NavigateTo method can take a argument if you want to pass a data to the view you're navigating to.\n\n```cs\nawait navigationHelper.NavigateToAsync(\"MainView\", \"Parameter\");\n```\nIf your view has a NavigationParameter property it will be set. \n\n```cs\npublic class MainView\n{\n     public object NavigationParameter {get;set;}\n\n     public MainView()\n     {\n          \n     }\n}\n```\n\nOtherwise the parameter will be sent to the constructor.\n```cs\npublic class MainView\n{\n     public MainView(object parameter)\n     {\n          var data = parameter as string;\n     }\n}\n```\n#### Navigate back\nTo navigate back, use the Back method.\n\n```cs\nawait navigationHelper.BackAsync();\n```\n\n#### Forms specific extensions\nOn Xamarin Forms there are a set of extension methods that allows for navigation to an instantiated page. Note that this will only work on the project that references `TinyNavigationHelper.Forms`.\n\nWARNING: This will only work in Xamarin Forms since it references `Xamarin.Forms`.\n\n```cs\n// Step 1 - Add a using to reference the extension method\nusing TinyNavigationHelper.Forms;\n\n// Step 2 - Navigate\nvar page = new NewsView();\nawait NavigationHelper.Current.NavigateToAsync(page);\n```\n\n### Modal\nTo open a modal, use the OpenModal method.\n```cs\nawait navigationHelper.OpenModalAsync(\"MainView\");\n```\nYou can send a parameter to a modal in the same way as with the NavigateTo method.\n\n```cs\nawait navigationHelper.OpenModalAsync(\"MainView\", \"parameter\");\n```\n\nIf you want the modal to have it's own navigation stack you can pass pass true the withNavigation argument.\n\n```cs\n//without parameter\nawait navigationHelper.OpenModalAsync(\"MainView\", true);\n\n//with parameter\nawait navigationHelper.OpenModalAsync(\"MainView\", \"parameter\", true);\n```\n\n### Set as root page\nIf you want to navigate to a page and reset the history in the navigation stack you can use the SetRootView method.\n\n```cs\n//without parameter and navigation stack\nnavigationHelper.SetRootView(\"MainView\");\n\n//with parameter, but without navigation stack\nnavigationHelper.SetRootView(\"MainView\", \"parameter\");\n\n//without parameter, but with navigation stack\nnavigationHelper.SetRootView(\"MainView\", true);\n\n//with parameter and navigation stack\nnavigationHelper.SetRootView(\"MainView\", \"parameter\", true);\n```\n\n### Handle view keys\nThe recommendation is to not use the string directly in your code, but instead create a class with view constants.\n\n```cs\npublic class ViewConstants\n{\n     public const string MainView = \"MainView\";\n}\n```\n\n```cs\nvar navigationHelper = new NavigationHelper(this);\nnavigationHelper.RegisterView\u003cMainView\u003e(ViewConstants.MainView);\n```\n\n```cs\nawait navigationHelper.NavigateToAsync(ViewConstants.MainView);\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FTinyStuff%2FTinyNavigationHelper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FTinyStuff%2FTinyNavigationHelper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FTinyStuff%2FTinyNavigationHelper/lists"}