-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(bank-sdk): Skonto + RA. Code refactor
PP-795
- Loading branch information
1 parent
f8b7d64
commit 3be6e18
Showing
3 changed files
with
52 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...re-sdk/sdk/src/main/java/net/gini/android/capture/util/compose/KeybaordPaddingProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package net.gini.android.capture.util.compose | ||
|
||
import androidx.compose.animation.core.tween | ||
import androidx.compose.foundation.ScrollState | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.State | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.platform.LocalDensity | ||
import androidx.compose.ui.unit.Dp | ||
import androidx.compose.ui.unit.dp | ||
import kotlin.math.roundToInt | ||
|
||
/** | ||
* Provides a padding based on keyboard state. If keyboard is opened the passed padding will be | ||
* returned and 0 will be returned otherwise | ||
* | ||
* In case if scrollState is passed - it will be scrolled automatically to this padding | ||
*/ | ||
@Composable | ||
fun keyboardPadding( | ||
padding: Dp, | ||
scrollState: ScrollState? = null | ||
): State<Dp> { | ||
val keybaordState by rememberImeState() | ||
|
||
val keyboardPadding = remember { mutableStateOf(padding) } | ||
val paddingPx = with(LocalDensity.current) { padding.toPx().roundToInt() } | ||
|
||
LaunchedEffect(keybaordState, paddingPx) { | ||
if (keybaordState) { | ||
keyboardPadding.value = padding | ||
scrollState?.let { scrollState -> | ||
scrollState.animateScrollTo(scrollState.value + paddingPx, tween(300)) | ||
} | ||
} else { | ||
keyboardPadding.value = 0.dp | ||
} | ||
} | ||
|
||
return keyboardPadding | ||
} |