Skip to content

Commit

Permalink
Release 2.2.0: ScopedServices.HandlesBack + GlobalServices.Factory
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhuinden committed Dec 30, 2019
1 parent a504b8e commit e1e299e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 30 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`.
Expand Down
64 changes: 35 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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**
Expand All @@ -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
Expand All @@ -186,7 +217,7 @@ data class FirstKey(val placeholder: String = "") : DefaultViewKey {
}
```

- **Layout XML**
- and **Layout XML**

``` xml
<?xml version="1.0" encoding="utf-8"?>
Expand All @@ -212,31 +243,6 @@ data class FirstKey(val placeholder: String = "") : DefaultViewKey {
</com.zhuinden.simplestackdemoexample.FirstView>
```

- **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.
Expand Down

0 comments on commit e1e299e

Please sign in to comment.