Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed back-pressed module #84

Merged
merged 1 commit into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 0 additions & 63 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -467,69 +467,6 @@ if (!backDispatcher.back()) {
}
```

## BackPressedDispatcher

> ⚠️ `BackPressedHandler` and `BackPressedDispatcher` API (the `back-pressed` module) is entirely deprecated. Please use `BackHandler` and `BackDispatcher` described above.

The `BackPressedDispatcher` API provides ability to handle back button events (e.g. an Android device's back button), in common code. This API is similar to AndroidX [OnBackPressedDispatcher](https://developer.android.com/reference/androidx/activity/OnBackPressedDispatcher).

### Setup

Groovy:
```groovy
// Add the dependency, typically under the commonMain source set
implementation "com.arkivanov.essenty:back-pressed:<essenty_version>"
```

Kotlin:
```kotlin
// Add the dependency, typically under the commonMain source set
implementation("com.arkivanov.essenty:back-pressed:<essenty_version>")
```

### Content

The [BackPressedHandler](https://github.com/arkivanov/Essenty/blob/master/back-pressed/src/commonMain/kotlin/com/arkivanov/essenty/backpressed/BackPressedHandler.kt) interface provides ability to register/unregister back button handlers. When the device's back button is clicked, all registered handlers are called in reverse order. If a handler returns `true` then the event is considered as handled and the handling process stops, the remaining handlers are not called. If none of the handlers returned `true` then the event is considered as unhandled.

The [BackPressedDispatcher](https://github.com/arkivanov/Essenty/blob/master/back-pressed/src/commonMain/kotlin/com/arkivanov/essenty/backpressed/BackPressedDispatcher.kt) interface extends `BackPressedHandler` and is responsible for triggering the registered handlers. The `BackPressedDispatcher.onBackPressed()` triggers all registered handlers in reverse order, returns `true` if the event is handled, and `false` if the event is unhandled.

#### Android extensions

From Android side, `BackPressedDispatcher` can be obtained by using special functions, can be found [here](https://github.com/arkivanov/Essenty/blob/master/back-pressed/src/androidMain/kotlin/com/arkivanov/essenty/backpressed/AndroidExt.kt).

> ⚠️ Due to the nature of AndroidX `OnBackPressedDispatcher` API, it is not possible to map it 1-1 to `BackPressedHandler`. Please keep in mind some possible side effects described in the [corresponding KDocs](https://github.com/arkivanov/Essenty/blob/master/back-pressed/src/androidMain/kotlin/com/arkivanov/essenty/backpressed/AndroidExt.kt).

### Usage example

#### Using the BackPressedHandler

```kotlin
class SomeLogic(backPressedHandler: BackPressedHandler) {
init {
backPressedHandler.register {
// Called when the back button is pressed
true // Return true to consume the event, or false to allow other registered callbacks
}
}
}
```

#### Using the BackPressedDispatcher manually

A default implementation of the `BackPressedDispatcher` interface can be instantiated using the corresponding builder function:

```kotlin
import com.arkivanov.essenty.backpressed.BackPressedDispatcher
import com.arkivanov.essenty.backpressed.BackPressedHandler

val backPressedDispatcher = BackPressedDispatcher()
val someLogic = SomeLogic(backPressedDispatcher)

if (!backPressedDispatcher.onBackPressed()) {
// The back pressed event was not handled
}
```

## Author

Twitter: [@arkann1985](https://twitter.com/arkann1985)
Expand Down
1 change: 0 additions & 1 deletion back-pressed/.gitignore

This file was deleted.

33 changes: 0 additions & 33 deletions back-pressed/api/android/back-pressed.api

This file was deleted.

21 changes: 0 additions & 21 deletions back-pressed/api/jvm/back-pressed.api

This file was deleted.

29 changes: 0 additions & 29 deletions back-pressed/build.gradle.kts

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading