Skip to content

Commit e1f449f

Browse files
authored
Merge pull request #17 from LDRAlighieri/release/1.9.0
Release 1.9.0. New back events, update kotlin, coroutines, material and other dependencies
2 parents 67f5d59 + 9360f91 commit e1f449f

File tree

42 files changed

+548
-123
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+548
-123
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
# ChangeLog
22

33

4+
## Version 1.9.0
5+
6+
* New: Bindings list:
7+
* AndroidX library bindings:
8+
* `corbind-activity`:
9+
* `OnBackPressedDispatcher`:
10+
* `backProgressed`
11+
* `backEvents`
12+
* Update: Kotlin to v1.9.10.
13+
* Update: Kotlin coroutines to v1.7.3.
14+
* Update: Material components to v1.10.0.
15+
* Update: Minor update of other libraries.
16+
17+
418
## Version 1.8.0
519

620
* New: Bindings list:

README.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[![Corbind](logo.svg)](https://ldralighieri.github.io/Corbind)
22

33
[![Maven Central](https://img.shields.io/maven-central/v/ru.ldralighieri.corbind/corbind.svg)](https://search.maven.org/search?q=g:ru.ldralighieri.corbind)
4-
[![Kotlin Version](https://img.shields.io/badge/Kotlin-v1.8.21-blue.svg?logo=kotlin)](https://kotlinlang.org)
5-
[![Kotlin Coroutines Version](https://img.shields.io/badge/Coroutines-v1.7.0-blue.svg)](https://kotlinlang.org/docs/reference/coroutines-overview.html)
4+
[![Kotlin Version](https://img.shields.io/badge/Kotlin-v1.9.10-blue.svg?logo=kotlin)](https://kotlinlang.org)
5+
[![Kotlin Coroutines Version](https://img.shields.io/badge/Coroutines-v1.7.3-blue.svg)](https://kotlinlang.org/docs/reference/coroutines-overview.html)
66
[![GitHub license](https://img.shields.io/badge/license-Apache%20License%202.0-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)
77

88
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/a1c9a1b1d1ce4ca7a201ab93492bf6e0)](https://app.codacy.com/gh/LDRAlighieri/Corbind)
@@ -28,33 +28,33 @@ Please consider giving this repository a star ⭐ if you like the project.
2828
Platform bindings:
2929
```kotlin
3030
dependencies {
31-
implementation("ru.ldralighieri.corbind:corbind:1.8.0")
31+
implementation("ru.ldralighieri.corbind:corbind:1.9.0")
3232
}
3333
```
3434

3535
AndroidX library bindings:
3636
```kotlin
3737
dependencies {
38-
implementation("ru.ldralighieri.corbind:corbind-activity:1.8.0")
39-
implementation("ru.ldralighieri.corbind:corbind-appcompat:1.8.0")
40-
implementation("ru.ldralighieri.corbind:corbind-core:1.8.0")
41-
implementation("ru.ldralighieri.corbind:corbind-drawerlayout:1.8.0")
42-
implementation("ru.ldralighieri.corbind:corbind-fragment:1.8.0")
43-
implementation("ru.ldralighieri.corbind:corbind-leanback:1.8.0")
44-
implementation("ru.ldralighieri.corbind:corbind-lifecycle:1.8.0")
45-
implementation("ru.ldralighieri.corbind:corbind-navigation:1.8.0")
46-
implementation("ru.ldralighieri.corbind:corbind-recyclerview:1.8.0")
47-
implementation("ru.ldralighieri.corbind:corbind-slidingpanelayout:1.8.0")
48-
implementation("ru.ldralighieri.corbind:corbind-swiperefreshlayout:1.8.0")
49-
implementation("ru.ldralighieri.corbind:corbind-viewpager:1.8.0")
50-
implementation("ru.ldralighieri.corbind:corbind-viewpager2:1.8.0")
38+
implementation("ru.ldralighieri.corbind:corbind-activity:1.9.0")
39+
implementation("ru.ldralighieri.corbind:corbind-appcompat:1.9.0")
40+
implementation("ru.ldralighieri.corbind:corbind-core:1.9.0")
41+
implementation("ru.ldralighieri.corbind:corbind-drawerlayout:1.9.0")
42+
implementation("ru.ldralighieri.corbind:corbind-fragment:1.9.0")
43+
implementation("ru.ldralighieri.corbind:corbind-leanback:1.9.0")
44+
implementation("ru.ldralighieri.corbind:corbind-lifecycle:1.9.0")
45+
implementation("ru.ldralighieri.corbind:corbind-navigation:1.9.0")
46+
implementation("ru.ldralighieri.corbind:corbind-recyclerview:1.9.0")
47+
implementation("ru.ldralighieri.corbind:corbind-slidingpanelayout:1.9.0")
48+
implementation("ru.ldralighieri.corbind:corbind-swiperefreshlayout:1.9.0")
49+
implementation("ru.ldralighieri.corbind:corbind-viewpager:1.9.0")
50+
implementation("ru.ldralighieri.corbind:corbind-viewpager2:1.9.0")
5151
}
5252
```
5353

5454
Google 'material' library bindings:
5555
```kotlin
5656
dependencies {
57-
implementation("ru.ldralighieri.corbind:corbind-material:1.8.0")
57+
implementation("ru.ldralighieri.corbind:corbind-material:1.9.0")
5858
}
5959
```
6060

build-logic/convention/src/main/kotlin/ru/ldralighieri/corbind/Project+configureKotlinAndroid.kt

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package ru.ldralighieri.corbind
2020

2121
import com.android.build.api.dsl.CommonExtension
22-
import org.gradle.api.JavaVersion
2322
import org.gradle.api.Project
2423
import org.gradle.api.plugins.ExtensionAware
2524
import org.gradle.kotlin.dsl.configure
@@ -28,7 +27,7 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension
2827
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions
2928

3029
internal fun Project.configureKotlinAndroid(
31-
commonExtension: CommonExtension<*, *, *, *>,
30+
commonExtension: CommonExtension<*, *, *, *, *>,
3231
) {
3332
val compileSdk: String by project
3433
val minSdk: String by project
@@ -44,13 +43,6 @@ internal fun Project.configureKotlinAndroid(
4443
jvmToolchain(17)
4544
}
4645

47-
// Remove this after https://issuetracker.google.com/issues/260059413 is fixed
48-
// https://kotlinlang.org/docs/gradle-configure-project.html#gradle-java-toolchains-support
49-
compileOptions {
50-
sourceCompatibility = JavaVersion.VERSION_17
51-
targetCompatibility = JavaVersion.VERSION_17
52-
}
53-
5446
kotlinOptions {
5547
allWarningsAsErrors = true
5648
freeCompilerArgs = freeCompilerArgs + listOf(
@@ -63,6 +55,6 @@ internal fun Project.configureKotlinAndroid(
6355
private fun Project.kotlin(action: KotlinAndroidProjectExtension.() -> Unit) =
6456
extensions.configure(action)
6557

66-
private fun CommonExtension<*, *, *, *>.kotlinOptions(block: KotlinJvmOptions.() -> Unit) {
58+
private fun CommonExtension<*, *, *, *, *>.kotlinOptions(block: KotlinJvmOptions.() -> Unit) {
6759
(this as ExtensionAware).extensions.configure("kotlinOptions", block)
6860
}

corbind-activity/README.md

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,37 @@ To add androidx activity bindings, import `corbind-activity` module:
55

66
```kotlin
77
dependencies {
8-
implementation("ru.ldralighieri.corbind:corbind-activity:1.8.0")
8+
implementation("ru.ldralighieri.corbind:corbind-activity:1.9.0")
99
}
1010
```
1111

1212
## List of extensions
1313

1414
Component | Extension | Description
1515
--|---|--
16-
**OnBackPressedDispatcher** | [`backPresses`][OnBackPressedDispatcher_backPresses] | Called when OnBackPressedDispatcher.onBackPressed triggered.
16+
**OnBackPressedDispatcher** | [`backPresses`][OnBackPressedDispatcher_backPresses] | Called when OnBackPressedDispatcher.onBackPressed triggered. OnBackPressed events only
17+
**OnBackPressedDispatcher** | [`backProgressed`][OnBackPressedDispatcher_backProgressed] | Called when OnBackPressedDispatcher.dispatchOnBackProgressed triggered. OnBackProgressed event only
18+
**OnBackPressedDispatcher** | [`backEvents`][OnBackPressedDispatcher_backEvents] | Called when any callback event triggered. All events
1719

1820

1921
## Simple examples
2022

2123
```kotlin
22-
onBackPressedDispatcher.backPresses(lifecycleOwner = this) // Flow<Unit>
23-
.onEach { /* handle onBackPressed event */ }
24-
.flowWithLifecycle(lifecycle)
25-
.launchIn(lifecycleScope) // lifecycle-runtime-ktx
24+
onBackPressedDispatcher.backEvents(lifecycleOwner = this)
25+
.onEach { event ->
26+
when (event) {
27+
is OnBackPressed -> { /* handle back pressed event */ }
28+
is OnBackCanceled -> { /* handle back cancel event */ }
29+
is OnBackStarted -> { /* handle back started event */ }
30+
is OnBackProgressed -> { /* handle back progressed event */ }
31+
}
32+
}
33+
.flowWithLifecycle(lifecycle)
34+
.launchIn(lifecycleScope) // lifecycle-runtime-ktx
2635
```
2736

2837
More examples in source code
2938

3039
[OnBackPressedDispatcher_backPresses]: https://github.com/LDRAlighieri/Corbind/blob/master/corbind-activity/src/main/kotlin/ru/ldralighieri/corbind/activity/OnBackPressedDispatcherBackPresses.kt
40+
[OnBackPressedDispatcher_backProgressed]: https://github.com/LDRAlighieri/Corbind/blob/master/corbind-activity/src/main/kotlin/ru/ldralighieri/corbind/activity/OnBackPressedDispatcherBackProgressed.kt
41+
[OnBackPressedDispatcher_backEvents]: https://github.com/LDRAlighieri/Corbind/blob/master/corbind-activity/src/main/kotlin/ru/ldralighieri/corbind/activity/OnBackPressedDispatcherOnBackEvents.kt

corbind-activity/api/corbind-activity.api

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
public final class ru/ldralighieri/corbind/activity/OnBackCanceled : ru/ldralighieri/corbind/activity/OnBackEvent {
2+
public static final field INSTANCE Lru/ldralighieri/corbind/activity/OnBackCanceled;
3+
public fun equals (Ljava/lang/Object;)Z
4+
public fun hashCode ()I
5+
public fun toString ()Ljava/lang/String;
6+
}
7+
8+
public abstract interface class ru/ldralighieri/corbind/activity/OnBackEvent {
9+
}
10+
11+
public final class ru/ldralighieri/corbind/activity/OnBackPressed : ru/ldralighieri/corbind/activity/OnBackEvent {
12+
public static final field INSTANCE Lru/ldralighieri/corbind/activity/OnBackPressed;
13+
public fun equals (Ljava/lang/Object;)Z
14+
public fun hashCode ()I
15+
public fun toString ()Ljava/lang/String;
16+
}
17+
118
public final class ru/ldralighieri/corbind/activity/OnBackPressedDispatcherBackPressesKt {
219
public static final fun backPresses (Landroidx/activity/OnBackPressedDispatcher;Landroidx/lifecycle/LifecycleOwner;)Lkotlinx/coroutines/flow/Flow;
320
public static final fun backPresses (Landroidx/activity/OnBackPressedDispatcher;Landroidx/lifecycle/LifecycleOwner;ILkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
@@ -8,3 +25,45 @@ public final class ru/ldralighieri/corbind/activity/OnBackPressedDispatcherBackP
825
public static synthetic fun backPresses$default (Landroidx/activity/OnBackPressedDispatcher;Lkotlinx/coroutines/CoroutineScope;Landroidx/lifecycle/LifecycleOwner;ILkotlin/jvm/functions/Function1;ILjava/lang/Object;)V
926
}
1027

28+
public final class ru/ldralighieri/corbind/activity/OnBackPressedDispatcherBackProgressedKt {
29+
public static final fun backProgressed (Landroidx/activity/OnBackPressedDispatcher;Landroidx/lifecycle/LifecycleOwner;)Lkotlinx/coroutines/flow/Flow;
30+
public static final fun backProgressed (Landroidx/activity/OnBackPressedDispatcher;Landroidx/lifecycle/LifecycleOwner;ILkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
31+
public static final fun backProgressed (Landroidx/activity/OnBackPressedDispatcher;Lkotlinx/coroutines/CoroutineScope;Landroidx/lifecycle/LifecycleOwner;I)Lkotlinx/coroutines/channels/ReceiveChannel;
32+
public static final fun backProgressed (Landroidx/activity/OnBackPressedDispatcher;Lkotlinx/coroutines/CoroutineScope;Landroidx/lifecycle/LifecycleOwner;ILkotlin/jvm/functions/Function2;)V
33+
public static synthetic fun backProgressed$default (Landroidx/activity/OnBackPressedDispatcher;Landroidx/lifecycle/LifecycleOwner;ILkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
34+
public static synthetic fun backProgressed$default (Landroidx/activity/OnBackPressedDispatcher;Lkotlinx/coroutines/CoroutineScope;Landroidx/lifecycle/LifecycleOwner;IILjava/lang/Object;)Lkotlinx/coroutines/channels/ReceiveChannel;
35+
public static synthetic fun backProgressed$default (Landroidx/activity/OnBackPressedDispatcher;Lkotlinx/coroutines/CoroutineScope;Landroidx/lifecycle/LifecycleOwner;ILkotlin/jvm/functions/Function2;ILjava/lang/Object;)V
36+
}
37+
38+
public final class ru/ldralighieri/corbind/activity/OnBackPressedDispatcherOnBackEventsKt {
39+
public static final fun backEvents (Landroidx/activity/OnBackPressedDispatcher;Landroidx/lifecycle/LifecycleOwner;)Lkotlinx/coroutines/flow/Flow;
40+
public static final fun backEvents (Landroidx/activity/OnBackPressedDispatcher;Landroidx/lifecycle/LifecycleOwner;ILkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
41+
public static final fun backEvents (Landroidx/activity/OnBackPressedDispatcher;Lkotlinx/coroutines/CoroutineScope;Landroidx/lifecycle/LifecycleOwner;I)Lkotlinx/coroutines/channels/ReceiveChannel;
42+
public static final fun backEvents (Landroidx/activity/OnBackPressedDispatcher;Lkotlinx/coroutines/CoroutineScope;Landroidx/lifecycle/LifecycleOwner;ILkotlin/jvm/functions/Function2;)V
43+
public static synthetic fun backEvents$default (Landroidx/activity/OnBackPressedDispatcher;Landroidx/lifecycle/LifecycleOwner;ILkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
44+
public static synthetic fun backEvents$default (Landroidx/activity/OnBackPressedDispatcher;Lkotlinx/coroutines/CoroutineScope;Landroidx/lifecycle/LifecycleOwner;IILjava/lang/Object;)Lkotlinx/coroutines/channels/ReceiveChannel;
45+
public static synthetic fun backEvents$default (Landroidx/activity/OnBackPressedDispatcher;Lkotlinx/coroutines/CoroutineScope;Landroidx/lifecycle/LifecycleOwner;ILkotlin/jvm/functions/Function2;ILjava/lang/Object;)V
46+
}
47+
48+
public final class ru/ldralighieri/corbind/activity/OnBackProgressed : ru/ldralighieri/corbind/activity/OnBackEvent {
49+
public fun <init> (Landroidx/activity/BackEventCompat;)V
50+
public final fun component1 ()Landroidx/activity/BackEventCompat;
51+
public final fun copy (Landroidx/activity/BackEventCompat;)Lru/ldralighieri/corbind/activity/OnBackProgressed;
52+
public static synthetic fun copy$default (Lru/ldralighieri/corbind/activity/OnBackProgressed;Landroidx/activity/BackEventCompat;ILjava/lang/Object;)Lru/ldralighieri/corbind/activity/OnBackProgressed;
53+
public fun equals (Ljava/lang/Object;)Z
54+
public final fun getBackEvent ()Landroidx/activity/BackEventCompat;
55+
public fun hashCode ()I
56+
public fun toString ()Ljava/lang/String;
57+
}
58+
59+
public final class ru/ldralighieri/corbind/activity/OnBackStarted : ru/ldralighieri/corbind/activity/OnBackEvent {
60+
public fun <init> (Landroidx/activity/BackEventCompat;)V
61+
public final fun component1 ()Landroidx/activity/BackEventCompat;
62+
public final fun copy (Landroidx/activity/BackEventCompat;)Lru/ldralighieri/corbind/activity/OnBackStarted;
63+
public static synthetic fun copy$default (Lru/ldralighieri/corbind/activity/OnBackStarted;Landroidx/activity/BackEventCompat;ILjava/lang/Object;)Lru/ldralighieri/corbind/activity/OnBackStarted;
64+
public fun equals (Ljava/lang/Object;)Z
65+
public final fun getBackEvent ()Landroidx/activity/BackEventCompat;
66+
public fun hashCode ()I
67+
public fun toString ()Ljava/lang/String;
68+
}
69+

corbind-activity/src/main/kotlin/ru/ldralighieri/corbind/activity/OnBackPressedDispatcherBackPresses.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ suspend fun OnBackPressedDispatcher.backPresses(
7777
*
7878
* ```
7979
* launch {
80-
* onBackPressedDispatcher.backPresses(lifecycleOwner = this)
81-
* .consumeEach { /* handle onBackPressed event */ }
80+
* onBackPressedDispatcher.backPresses(scope, lifecycleOwner = this)
81+
* .consumeEach { /* handle back pressed event */ }
8282
* }
8383
* ```
8484
*
@@ -103,7 +103,7 @@ fun OnBackPressedDispatcher.backPresses(
103103
*
104104
* ```
105105
* onBackPressedDispatcher.backPresses(lifecycleOwner = this)
106-
* .onEach { /* handle onBackPressed event */ }
106+
* .onEach { /* handle back pressed event */ }
107107
* .flowWithLifecycle(lifecycle)
108108
* .launchIn(lifecycleScope) // lifecycle-runtime-ktx
109109
* ```
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
/*
2+
* Copyright 2023 Vladimir Raupov
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package ru.ldralighieri.corbind.activity
18+
19+
import androidx.activity.BackEventCompat
20+
import androidx.activity.OnBackPressedCallback
21+
import androidx.activity.OnBackPressedDispatcher
22+
import androidx.annotation.CheckResult
23+
import androidx.lifecycle.LifecycleOwner
24+
import kotlinx.coroutines.CoroutineScope
25+
import kotlinx.coroutines.Dispatchers
26+
import kotlinx.coroutines.channels.Channel
27+
import kotlinx.coroutines.channels.ReceiveChannel
28+
import kotlinx.coroutines.channels.actor
29+
import kotlinx.coroutines.channels.awaitClose
30+
import kotlinx.coroutines.coroutineScope
31+
import kotlinx.coroutines.flow.Flow
32+
import kotlinx.coroutines.flow.channelFlow
33+
import kotlinx.coroutines.isActive
34+
import ru.ldralighieri.corbind.internal.corbindReceiveChannel
35+
36+
/**
37+
* Perform an action on [OnBackPressedDispatcher.dispatchOnBackProgressed] call.
38+
*
39+
* @param scope Root coroutine scope
40+
* @param lifecycleOwner The LifecycleOwner which controls when the callback should be invoked
41+
* @param capacity Capacity of the channel's buffer (no buffer by default)
42+
* @param action An action to perform
43+
*/
44+
fun OnBackPressedDispatcher.backProgressed(
45+
scope: CoroutineScope,
46+
lifecycleOwner: LifecycleOwner,
47+
capacity: Int = Channel.RENDEZVOUS,
48+
action: suspend (Float) -> Unit
49+
) {
50+
val events = scope.actor<Float>(Dispatchers.Main.immediate, capacity) {
51+
for (progress in channel) action(progress)
52+
}
53+
54+
val callback = callback(scope, events::trySend)
55+
addCallback(lifecycleOwner, callback)
56+
events.invokeOnClose { callback.remove() }
57+
}
58+
59+
/**
60+
* Perform an action on [OnBackPressedDispatcher.dispatchOnBackProgressed] call, inside new
61+
* [CoroutineScope].
62+
*
63+
* @param lifecycleOwner The LifecycleOwner which controls when the callback should be invoked
64+
* @param capacity Capacity of the channel's buffer (no buffer by default)
65+
* @param action An action to perform
66+
*/
67+
suspend fun OnBackPressedDispatcher.backProgressed(
68+
lifecycleOwner: LifecycleOwner,
69+
capacity: Int = Channel.RENDEZVOUS,
70+
action: suspend (Float) -> Unit
71+
) = coroutineScope {
72+
backProgressed(this, lifecycleOwner, capacity, action)
73+
}
74+
75+
/**
76+
* Create a channel which emits back progress on [OnBackPressedDispatcher.dispatchOnBackProgressed]
77+
* call.
78+
*
79+
* Example:
80+
*
81+
* ```
82+
* launch {
83+
* onBackPressedDispatcher.backProgressed(scope, lifecycleOwner = this)
84+
* .consumeEach { /* handle back progressed event */ }
85+
* }
86+
* ```
87+
*
88+
* @param scope Root coroutine scope
89+
* @param lifecycleOwner The LifecycleOwner which controls when the callback should be invoked
90+
* @param capacity Capacity of the channel's buffer (no buffer by default)
91+
*/
92+
fun OnBackPressedDispatcher.backProgressed(
93+
scope: CoroutineScope,
94+
lifecycleOwner: LifecycleOwner,
95+
capacity: Int = Channel.RENDEZVOUS
96+
): ReceiveChannel<Float> = corbindReceiveChannel(capacity) {
97+
val callback = callback(scope, ::trySend)
98+
addCallback(lifecycleOwner, callback)
99+
invokeOnClose { callback.remove() }
100+
}
101+
102+
/**
103+
* Create a flow which emits back progress on [OnBackPressedDispatcher.dispatchOnBackProgressed]
104+
* call.
105+
*
106+
* Example:
107+
*
108+
* ```
109+
* onBackPressedDispatcher.backProgressed(lifecycleOwner = this)
110+
* .onEach { /* handle back progressed event */ }
111+
* .flowWithLifecycle(lifecycle)
112+
* .launchIn(lifecycleScope) // lifecycle-runtime-ktx
113+
* ```
114+
*
115+
* @param lifecycleOwner The LifecycleOwner which controls when the callback should be invoked
116+
*/
117+
fun OnBackPressedDispatcher.backProgressed(lifecycleOwner: LifecycleOwner): Flow<Float> =
118+
channelFlow {
119+
val callback = callback(this, ::trySend)
120+
addCallback(lifecycleOwner, callback)
121+
awaitClose { callback.remove() }
122+
}
123+
124+
@CheckResult
125+
private fun callback(
126+
scope: CoroutineScope,
127+
emitter: (Float) -> Unit
128+
) = object : OnBackPressedCallback(true) {
129+
130+
override fun handleOnBackProgressed(backEvent: BackEventCompat) {
131+
if (scope.isActive) { emitter(backEvent.progress) }
132+
}
133+
134+
override fun handleOnBackPressed() = Unit
135+
}

0 commit comments

Comments
 (0)