Skip to content

Commit 375eb96

Browse files
committed
Rename | Add documentation | Add composeutils-permissions stuff to README
1 parent 0cfa249 commit 375eb96

File tree

5 files changed

+97
-4
lines changed

5 files changed

+97
-4
lines changed

README.md

Lines changed: 89 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@
2626
- [Modifiers](#modifiers)
2727
- [Flow Collectors](#flow-collectors)
2828
- [Lifecycle Observers](#lifecycle-observers)
29-
- [Orientation Utilities](#orientation-utilities)
29+
- [Orientation](#orientation)
3030
- [Dimension Conversion](#dimension-conversion)
3131
- [Color Conversion](#color-conversion)
32+
- [Map Conversion](#map-conversion)
3233
- [Drawer State](#drawer-state)
34+
- [Permission States](#permission-states)
3335

3436
## State Savers
3537

@@ -152,7 +154,7 @@ Runs a callback when removed from composition.
152154
fun OnRemoveFromComposition(callback: () -> Unit)
153155
```
154156

155-
## Orientation Utilities
157+
## Orientation
156158

157159
### `isLandscapeModeActive`
158160

@@ -214,6 +216,12 @@ Converts a hex color string to `Color`.
214216
fun String.toComposeColor(): Color
215217
```
216218

219+
## Map Conversion
220+
221+
```kotlin
222+
fun <K, V> Map<K, V>.toMutableStateMap(): SnapshotStateMap<K, V>
223+
```
224+
217225
## Drawer State
218226

219227
### `DrawerState.visibilityPercentage()`
@@ -230,3 +238,82 @@ fun DrawerState.visibilityPercentage(@FloatRange(from = 0.0) maxWidthPx: Float):
230238
@Composable
231239
fun DrawerState.rememberVisibilityPercentage(@FloatRange(from = 0.0) maxWidthPx: Float = DrawerDefaults.MaximumDrawerWidth.toPx()): State<Float> =
232240
```
241+
242+
## Permission States
243+
244+
### `ExtendedPermissionState`
245+
246+
```kotlin
247+
/**
248+
* Permission state which, as opposed to the accompanist ones,
249+
* - exposes a [grantedFromRequest] shared flow to allow for distributed subscription and callback invocation, instead of only being able to pass a onPermissionResult callback upon instantiation, which needs to cover all granting reactions, possibly impacting various components
250+
* - allows for callbacks upon permission requesting being suppressed
251+
*/
252+
253+
@Stable
254+
interface ExtendedPermissionState {
255+
val granted: Boolean
256+
257+
/**
258+
* The result of a launched permission request.
259+
*/
260+
val grantedFromRequest: SharedFlow<Boolean>
261+
262+
/**
263+
* Launches the permission request if launching is not suppressed, otherwise invokes [onSuppressed].
264+
*/
265+
fun launchRequest(onSuppressed: (() -> Unit)? = null)
266+
}
267+
```
268+
269+
with the implementations
270+
271+
#### `ExtendedSinglePermissionState`
272+
273+
```kotlin
274+
@Stable
275+
open class ExtendedSinglePermissionState(
276+
private val requestLaunchedBefore: StateFlow<Boolean>,
277+
permissionState: PermissionState,
278+
override val grantedFromRequest: SharedFlow<Boolean>,
279+
private val defaultOnLaunchingSuppressed: () -> Unit = {}
280+
) : PermissionState by permissionState,
281+
ExtendedPermissionState
282+
283+
@Composable
284+
fun rememberExtendedSinglePermissionState(
285+
permission: String,
286+
requestLaunchedBefore: StateFlow<Boolean>,
287+
saveRequestLaunched: () -> Unit,
288+
defaultOnPermissionResult: (Boolean) -> Unit = {},
289+
defaultOnLaunchingSuppressed: () -> Unit = {},
290+
scope: CoroutineScope = rememberCoroutineScope()
291+
): ExtendedSinglePermissionState
292+
```
293+
294+
and
295+
296+
#### `ExtendedMultiplePermissionsState`
297+
298+
```kotlin
299+
@Stable
300+
open class ExtendedMultiplePermissionsState(
301+
private val requestLaunchedBefore: StateFlow<Boolean>,
302+
multiplePermissionsState: MultiplePermissionsState,
303+
override val grantedFromRequest: SharedFlow<Boolean>,
304+
private val defaultOnLaunchingSuppressed: () -> Unit = {}
305+
) : MultiplePermissionsState by multiplePermissionsState,
306+
ExtendedPermissionState
307+
308+
@SuppressLint("ComposeUnstableCollections")
309+
@Composable
310+
fun rememberExtendedMultiplePermissionsState(
311+
permissions: List<String>,
312+
requestLaunchedBefore: StateFlow<Boolean>,
313+
saveRequestLaunched: () -> Unit,
314+
defaultOnPermissionResult: (Map<String, Boolean>) -> Unit = {},
315+
defaultOnLaunchingSuppressed: () -> Unit = {},
316+
scope: CoroutineScope = rememberCoroutineScope()
317+
): ExtendedMultiplePermissionsState
318+
```
319+

composeutils-permissions/src/main/kotlin/com/w2sv/composeutils/permissions/extendedpermissionstate/ExtendedPermissionState.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
package com.w2sv.composeutils.permissions.extendedpermissionstate
22

33
import androidx.compose.runtime.Stable
4+
import com.google.accompanist.permissions.PermissionState
45
import kotlinx.coroutines.flow.SharedFlow
56

7+
/**
8+
* Permission state which, as opposed to the accompanist ones,
9+
* - exposes a [grantedFromRequest] shared flow to allow for distributed subscription and callback invocation, instead of only being able to pass a onPermissionResult callback upon instantiation, which needs to cover all granting reactions, possibly impacting various components
10+
* - allows for callbacks upon permission requesting being suppressed
11+
*/
612
@Stable
713
interface ExtendedPermissionState {
814
val granted: Boolean

composeutils-permissions/src/main/kotlin/com/w2sv/composeutils/permissions/extendedpermissionstate/ExtendedSinglePermissionState.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ open class ExtendedSinglePermissionState(
4444
}
4545

4646
@Composable
47-
fun rememberExtendedPermissionState(
47+
fun rememberExtendedSinglePermissionState(
4848
permission: String,
4949
requestLaunchedBefore: StateFlow<Boolean>,
5050
saveRequestLaunched: () -> Unit,

composeutils/src/main/kotlin/com/w2sv/composeutils/extensions/Collection.kt renamed to composeutils/src/main/kotlin/com/w2sv/composeutils/extensions/Map.kt

File renamed without changes.

composeutils/src/test/kotlin/com/w2sv/composeutils/extensions/CollectionKtTest.kt renamed to composeutils/src/test/kotlin/com/w2sv/composeutils/extensions/MapKtTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package com.w2sv.composeutils.extensions
33
import org.junit.Assert.assertEquals
44
import org.junit.Test
55

6-
class CollectionKtTest {
6+
class MapKtTest {
77

88
@Test
99
fun toMutableStateMap() {

0 commit comments

Comments
 (0)