Skip to content

Commit c1a2ff7

Browse files
committed
Update
1 parent 337df62 commit c1a2ff7

1 file changed

Lines changed: 13 additions & 16 deletions

File tree

app/src/main/java/com/tool/tree/TextEditorActivity.kt

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ class TextEditorActivity : AppCompatActivity() {
8181
private var isNewFile = false
8282
private var isSaving = false
8383
private var noWrapContainer: HorizontalScrollView? = null
84-
private var fabBaseMarginBottom = 0
8584
private val progressBarDialog by lazy { ProgressBarDialog(this) }
8685

8786
override fun onCreate(savedInstanceState: Bundle?) {
@@ -123,28 +122,26 @@ class TextEditorActivity : AppCompatActivity() {
123122
/**
124123
* App đang dùng chế độ edge-to-edge (decorFitsSystemWindows = false) nên hệ thống sẽ
125124
* không tự đẩy layout lên khi hiện bàn phím dù có khai báo windowSoftInputMode="adjustResize"
126-
* trong manifest — phải tự lắng nghe inset của bàn phím (IME) rồi đệm (padding) đáy vùng
127-
* nội dung lên tương ứng, đồng thời đẩy FAB lên theo để nó luôn nổi trên bàn phím thay vì
128-
* bị che khuất hoặc biến mất.
125+
* trong manifest — phải tự lắng nghe inset của bàn phím (IME) rồi tự đẩy.
126+
*
127+
* Thay vì chỉ đệm (padding) đáy vùng cuộn — vốn phụ thuộc vào cách ScrollView tự tính vùng
128+
* cuộn được nên không phải lúc nào cũng chắc chắn tránh được bàn phím — cách này dịch chuyển
129+
* (translationY) thẳng toàn bộ vùng nội dung bên dưới thanh tiêu đề (gồm cả FAB) lên trên
130+
* đúng bằng phần chiều cao bị bàn phím che, đảm bảo con trỏ/văn bản luôn nổi lên trên bàn
131+
* phím chứ không bị che.
129132
*/
130133
private fun setupKeyboardInsets() {
131-
val scrollContainer = binding.mainList
132-
val fabParams = binding.editorFabRun.layoutParams as ViewGroup.MarginLayoutParams
133-
fabBaseMarginBottom = fabParams.bottomMargin
134-
135-
ViewCompat.setOnApplyWindowInsetsListener(scrollContainer) { view, insets ->
134+
ViewCompat.setOnApplyWindowInsetsListener(binding.root) { _, insets ->
136135
val imeInset = insets.getInsets(WindowInsetsCompat.Type.ime()).bottom
137136
val systemBarsInset = insets.getInsets(WindowInsetsCompat.Type.systemBars()).bottom
138-
val keyboardVisible = imeInset > systemBarsInset
139-
140-
view.setPadding(view.paddingLeft, view.paddingTop, view.paddingRight, maxOf(imeInset, systemBarsInset))
137+
val pushUp = (imeInset - systemBarsInset).coerceAtLeast(0).toFloat()
138+
val keyboardVisible = pushUp > 0
141139

142-
val fabLp = binding.editorFabRun.layoutParams as ViewGroup.MarginLayoutParams
143-
fabLp.bottomMargin = fabBaseMarginBottom + imeInset
144-
binding.editorFabRun.layoutParams = fabLp
140+
binding.mainList.animate().translationY(-pushUp).setDuration(120).start()
141+
binding.editorFabRun.animate().translationY(-pushUp).setDuration(120).start()
145142

146143
if (keyboardVisible) {
147-
view.post { scrollToCursor() }
144+
binding.mainList.post { scrollToCursor() }
148145
}
149146

150147
insets

0 commit comments

Comments
 (0)