Skip to content

Commit

Permalink
feature(bank-sdk): Skonto + RA. Code refactor
Browse files Browse the repository at this point in the history
PP-795
  • Loading branch information
ndubkov-distcotech committed Dec 3, 2024
1 parent f8b7d64 commit 3be6e18
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ import net.gini.android.capture.ui.components.topbar.GiniTopBar
import net.gini.android.capture.ui.components.topbar.GiniTopBarColors
import net.gini.android.capture.ui.theme.GiniTheme
import net.gini.android.capture.ui.theme.modifier.tabletMaxWidth
import net.gini.android.capture.util.compose.keyboardPadding
import net.gini.android.capture.view.InjectedViewAdapterInstance
import org.koin.core.parameter.parametersOf
import org.orbitmvi.orbit.compose.collectAsState
Expand Down Expand Up @@ -286,6 +287,8 @@ private fun ScreenReadyState(
) {

val scrollState = rememberScrollState()
val keyboardPadding by keyboardPadding(108.dp, scrollState)

Scaffold(
modifier = modifier,
containerColor = screenColorScheme.backgroundColor,
Expand All @@ -310,7 +313,8 @@ private fun ScreenReadyState(
Column(
modifier = Modifier
.padding(it)
.verticalScroll(scrollState),
.verticalScroll(scrollState)
.padding(bottom = keyboardPadding),
horizontalAlignment = Alignment.CenterHorizontally,
) {
Column(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@

package net.gini.android.bank.sdk.capture.skonto

import android.app.Activity
import android.content.res.Configuration.UI_MODE_NIGHT_YES
import android.icu.util.Calendar
import android.util.Log
import android.widget.FrameLayout
import androidx.activity.compose.BackHandler
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.tween
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.focusable
Expand Down Expand Up @@ -56,8 +53,6 @@ import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.graphics.vector.rememberVectorPainter
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.pluralStringResource
import androidx.compose.ui.res.stringResource
Expand All @@ -66,8 +61,6 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.viewinterop.AndroidView
import androidx.compose.ui.window.Dialog
import androidx.compose.ui.window.DialogProperties
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import net.gini.android.bank.sdk.R
import net.gini.android.bank.sdk.capture.skonto.colors.SkontoScreenColors
import net.gini.android.bank.sdk.capture.skonto.colors.section.SkontoFooterSectionColors
Expand Down Expand Up @@ -95,7 +88,7 @@ import net.gini.android.capture.ui.components.topbar.GiniTopBarColors
import net.gini.android.capture.ui.theme.GiniTheme
import net.gini.android.capture.ui.theme.modifier.tabletMaxWidth
import net.gini.android.capture.ui.theme.typography.bold
import net.gini.android.capture.util.compose.rememberImeState
import net.gini.android.capture.util.compose.keyboardPadding
import net.gini.android.capture.view.InjectedViewAdapterInstance
import org.orbitmvi.orbit.compose.collectAsState
import org.orbitmvi.orbit.compose.collectSideEffect
Expand Down Expand Up @@ -224,26 +217,7 @@ private fun ScreenReadyState(
screenColorScheme: SkontoScreenColors = SkontoScreenColors.colors(),
) {
val scrollState = rememberScrollState()
val imeState = rememberImeState()
val activity = LocalView.current.context as? Activity
val insets = ViewCompat.getRootWindowInsets(activity!!.window.decorView)
val textInputHeightPx = with(LocalDensity.current) { 8.dp.toPx() }

//Enjoy your keyboard height
val keyboardHeight = with(LocalDensity.current) {
insets!!.getInsets(WindowInsetsCompat.Type.ime()).bottom.toDp()
}

LaunchedEffect(key1 = imeState.value) {
if (imeState.value) {
scrollState.animateScrollTo(
scrollState.value + textInputHeightPx.toInt(),
tween(300)
)
}
}

Log.d("AAAAAA", "$keyboardHeight")
val keyboardPadding by keyboardPadding(108.dp, scrollState)

Scaffold(modifier = modifier,
containerColor = screenColorScheme.backgroundColor,
Expand Down Expand Up @@ -275,7 +249,7 @@ private fun ScreenReadyState(
.padding(it)
.verticalScroll(scrollState)
.fillMaxSize()
.padding(bottom = keyboardHeight),
.padding(bottom = keyboardPadding),
horizontalAlignment = Alignment.CenterHorizontally,
) {
Column(
Expand Down
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
}

0 comments on commit 3be6e18

Please sign in to comment.