From 470043d36024d3301d3329569465b19b1d4ae75d Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 7 Nov 2023 02:28:23 +0600 Subject: [PATCH] continue fill navigation docs --- docs/navigation/getting-started.md | 101 +++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 docs/navigation/getting-started.md diff --git a/docs/navigation/getting-started.md b/docs/navigation/getting-started.md new file mode 100644 index 0000000..b47cca8 --- /dev/null +++ b/docs/navigation/getting-started.md @@ -0,0 +1,101 @@ +# Getting started + +[![Maven Central](https://img.shields.io/maven-central/v/dev.inmo/navigation.core?label=navigation&style=flat-square)](https://github.com/InsanusMokrassar/navigation) + +Traditionally, you need to add dependency to your project. Currently, there are two types of artifacts: + +* `Core` - only necessary tools for your projects +* `MVVM` - Model-View-ViewModel architecture tools + `Core` components + +| Artifact | Purpose | Dependency | +|:--------:|-------------------------------------------------------------|-----------------------------------------------------------------| +| `Core` | Only necessary tools for your projects | `implementation "dev.inmo:navigation.core:$navigation_version"` | +| `MVVM` | Model-View-ViewModel architecture tools + `Core` components | `implementation "dev.inmo:navigation.mvvm:$navigation_version"` | + +# Initialization + +After you have added your dependency, you should initialize navigation. + +There are several important things: + +1. `Config` - it is an instance of any class which extending the `NavigationNodeDefaultConfig` in common case +2. `Factory` - usually object which may create a node or some required part for node + +For example: lets imagine that we have a node `Main`. Here what should we do to create a node and make it workable in +navigation: + +```kotlin +data class MainConfig( + // this id will be used to search an html element by id in JS + // and Fragment by tag in Android + override val id: String = "main" +) : NavigationNodeDefaultConfig +``` + +### JS part + +```kotlin +// Core variant without MVVM or Compose +class MainNode( + config: MainConfig, + chain: NavigationChain, +) : JsNavigationNode( + chain, + config +) { + // Some code + // In htmlElementStateFlow will be found `HTMLElement` where node should be binded +} +// MVVM Compose variant +class MainNodeView( + config: MainConfig, + chain: NavigationChain, +) : View( + config, + chain +) { + // Some code + // In htmlElementStateFlow will be found `HTMLElement` where node should be binded + + @Composable + override onDraw() { + Text("Hello world") + } +} + +object MainNodeFactory : NavigationNodeFactory { + override fun createNode( + navigationChain: NavigationChain, + config: Base + ): NavigationNode? = if (config is MainConfig) { + MainNode(config, chain) // Or `MainNodeView(config, chain)` for MVVM + } else { + null + } +} +``` + +### Android + +In Android there is one important note: you will not directly work with nodes. In fact it will be required to create +special `NodeFragment`: + +```kotlin +// Core variant +class MainFragment : NodeFragment() { + // Your code + // Here will be available: node with type `AndroidFragmentNode`, config: `MainConfig` +} +``` + +Initialization is different on the platforms, so, lets take a look at each one. + +## JS + +In `JavaScript` it looks like: + +```kotlin +initNavigation( + +) +```