Skip to content

Commit

Permalink
fix battery keyboard
Browse files Browse the repository at this point in the history
  • Loading branch information
polstianka committed Sep 29, 2024
1 parent 7f36de4 commit 4914bf6
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ abstract class BaseHolderWalletScreen<C: ScreenContext>(

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
view.doKeyboardAnimation(::onKeyboardAnimation)
view.doKeyboardAnimation(block = ::onKeyboardAnimation)
childFragmentManager.addOnBackStackChangedListener(backStackChangedListener)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.tonapps.tonkeeper.extensions.toast
import com.tonapps.tonkeeper.koin.walletViewModel
import com.tonapps.tonkeeper.ui.base.BaseListWalletScreen
import com.tonapps.tonkeeper.ui.base.ScreenContext
import com.tonapps.tonkeeper.ui.screen.battery.BatteryScreen
import com.tonapps.tonkeeper.ui.screen.battery.recharge.entity.BatteryRechargeEvent
import com.tonapps.tonkeeper.ui.screen.battery.recharge.list.Adapter
import com.tonapps.tonkeeper.ui.screen.root.RootViewModel
Expand All @@ -40,7 +41,9 @@ import org.koin.androidx.viewmodel.ext.android.viewModel
import org.koin.core.parameter.parametersOf
import uikit.base.BaseFragment
import uikit.extensions.collectFlow
import uikit.extensions.doKeyboardAnimation
import uikit.extensions.hideKeyboard
import uikit.extensions.pinToBottomInsets
import uikit.widget.FrescoView
import uikit.widget.InputView
import java.util.UUID
Expand Down Expand Up @@ -106,13 +109,23 @@ class BatteryRechargeScreen(wallet: WalletEntity): BaseListWalletScreen<ScreenCo
true -> getString(Localization.battery_gift_title)
false -> getString(Localization.battery_recharge_title)
}

view.doKeyboardAnimation(true) { offset, _, _ ->
view.translationY = -offset.toFloat()
}

collectFlow(viewModel.tokenFlow) { token ->
tokenTitleView.text = token.symbol
tokenIconView.setImageURI(token.imageUri, this)
}
collectFlow(viewModel.eventFlow, ::onEvent)
}

override fun onDragging() {
super.onDragging()
activity?.hideKeyboard()
}

private fun onContinue() {
requireContext().hideKeyboard()
viewModel.onContinue()
Expand Down Expand Up @@ -144,6 +157,7 @@ class BatteryRechargeScreen(wallet: WalletEntity): BaseListWalletScreen<ScreenCo
private fun onSuccess() {
requireContext().showToast(Localization.battery_please_wait)
navigation?.openURL("tonkeeper://activity")
navigation?.removeByClass(BatteryScreen::class.java)
finish()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ class AmountHolder(
amountView.suffix = item.symbol
currencyView.text = item.formattedCharges
applyAvailable(item.formattedRemaining, item.isInsufficientBalance, item.isLessThanMin)
amountView.focus()
}


private fun applyAvailable(
formattedRemaining: CharSequence,
isInsufficientBalance: Boolean,
Expand Down
14 changes: 8 additions & 6 deletions ui/uikit/core/src/main/java/uikit/extensions/View.kt
Original file line number Diff line number Diff line change
Expand Up @@ -288,12 +288,14 @@ fun View.reject() {
hapticReject()
}

inline fun View.doKeyboardAnimation(crossinline block: (
offset: Int,
progress: Float,
isShowing: Boolean
) -> Unit) {
val animationCallback = object : KeyboardAnimationCallback(this) {
inline fun View.doKeyboardAnimation(
ignoreNavBar: Boolean = false,
crossinline block: (
offset: Int,
progress: Float,
isShowing: Boolean) -> Unit
) {
val animationCallback = object : KeyboardAnimationCallback(this, ignoreNavBar) {
override fun onKeyboardOffsetChanged(offset: Int, progress: Float, isShowing: Boolean) {
block(offset, progress, isShowing)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package uikit.insets

import android.util.Log
import android.view.View
import androidx.core.view.WindowInsetsAnimationCompat
import androidx.core.view.WindowInsetsCompat
Expand All @@ -10,11 +9,16 @@ import uikit.extensions.getRootWindowInsetsCompat
import uikit.extensions.insetsBottomTypeMask

abstract class KeyboardAnimationCallback(
private val view: View
): InsetsAnimationCallback(view, insetsBottomTypeMask) {
private val view: View,
private val ignoreNavBar: Boolean,
): InsetsAnimationCallback(view, if (ignoreNavBar) WindowInsetsCompat.Type.ime() else insetsBottomTypeMask) {

private val navigationOffset: Int by lazy {
view.getRootWindowInsetsCompat()?.getInsets(WindowInsetsCompat.Type.systemBars())?.bottom ?: 0
if (ignoreNavBar) {
0
} else {
view.getRootWindowInsetsCompat()?.getInsets(WindowInsetsCompat.Type.systemBars())?.bottom ?: 0
}
}

private val imeOffset: Int
Expand All @@ -36,7 +40,11 @@ abstract class KeyboardAnimationCallback(

override fun onUpdateInsets(insets: WindowInsetsCompat, animation: WindowInsetsAnimationCompat) {
val fraction = animation.interpolatedFraction
val offset = insets.bottomBarsOffset
val offset = if (ignoreNavBar) {
insets.getInsets(WindowInsetsCompat.Type.ime()).bottom
} else {
insets.bottomBarsOffset
}
keyboardOffsetChanged(offset, fraction)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import android.view.inputmethod.EditorInfo
import androidx.appcompat.R
import androidx.appcompat.widget.AppCompatEditText
import com.tonapps.uikit.color.accentBlueColor
import uikit.extensions.focusWithKeyboard
import uikit.extensions.setCursorColor

open class InputTextView @JvmOverloads constructor(
Expand Down Expand Up @@ -35,6 +36,10 @@ open class InputTextView @JvmOverloads constructor(
}
}

fun focus() {
focusWithKeyboard()
}

fun setFormattingInputFilter(filter: InputFilter) {
removePreviousFormattingInputFilter()
formattingInputFilter = filter
Expand Down
1 change: 1 addition & 0 deletions ui/uikit/core/src/main/res/layout/fragment_list.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<uikit.widget.ColumnLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/list_container"
android:layout_width="match_parent"
android:layout_height="match_parent">

Expand Down

0 comments on commit 4914bf6

Please sign in to comment.