diff --git a/CHANGELOG.md b/CHANGELOG.md index 197801e9..80238797 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Change log --Simple Stack X.X.X (XXXX-XX-XX) +-Simple Stack 2.2.0 (2019-12-30) -------------------------------- - ADDED: `ScopedService.HandlesBack`. diff --git a/README.md b/README.md index 9b4241cf..33f3b213 100644 --- a/README.md +++ b/README.md @@ -128,14 +128,14 @@ and then, add the dependency to your module's `build.gradle.kts` (or `build.grad ``` kotlin // build.gradle.kts -implementation("com.github.Zhuinden:simple-stack:2.1.2") +implementation("com.github.Zhuinden:simple-stack:2.2.0") ``` or ``` groovy // build.gradle -implementation 'com.github.Zhuinden:simple-stack:2.1.2' +implementation 'com.github.Zhuinden:simple-stack:2.2.0' ``` ## How does it work? @@ -152,6 +152,10 @@ Afterwards, the Backstack operators allow changing between states. ## Example setup +### Fragments + +See the `simple-stack-example-basic-kotlin-example`. + ### Compound ViewGroups - **Activity** @@ -176,7 +180,34 @@ class MainActivity : AppCompatActivity() { } ``` -- **DefaultViewKey** +Now you can do: + +- **Custom ViewGroup** + +``` kotlin +import kotlinx.android.synthetic.main.first_view.view.* + +val View.backstack + get() = Navigator.getBackstack(context) + +class FirstView : FrameLayout { + constructor(context: Context) : super(context) + constructor(context: Context, attrs: AttributeSet) : super(context, attrs) + constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) + @TargetApi(21) + constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) + + override fun onFinishInflate() { + super.onFinishInflate() + + buttonFirst.onClick { + backstack.goTo(SecondKey()) + } + } +} +``` + +- By using the **DefaultViewKey** ``` kotlin @Parcelize @@ -186,7 +217,7 @@ data class FirstKey(val placeholder: String = "") : DefaultViewKey { } ``` -- **Layout XML** +- and **Layout XML** ``` xml @@ -212,31 +243,6 @@ data class FirstKey(val placeholder: String = "") : DefaultViewKey { ``` -- **Custom ViewGroup** - -``` kotlin -import kotlinx.android.synthetic.main.first_view.view.* - -val View.backstack - get() = Navigator.getBackstack(context) - -class FirstView : FrameLayout { - constructor(context: Context) : super(context) - constructor(context: Context, attrs: AttributeSet) : super(context, attrs) - constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) - @TargetApi(21) - constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) - - override fun onFinishInflate() { - super.onFinishInflate() - - buttonFirst.onClick { - backstack.goTo(SecondKey()) - } - } -} -``` - ## Scopes To simplify sharing data/state between screens, a screen key can also be associated with a ScopeKey.