@@ -18,6 +18,9 @@ import android.view.ViewGroup
1818import android.view.inputmethod.InputMethodManager
1919import android.widget.ImageView
2020import android.widget.TextView
21+ import androidx.core.view.ViewCompat
22+ import androidx.core.view.WindowInsetsAnimationCompat
23+ import androidx.core.view.WindowInsetsCompat
2124import androidx.viewbinding.ViewBinding
2225import org.fossify.commons.extensions.*
2326import org.fossify.commons.views.MyEditText
@@ -170,15 +173,10 @@ class TextFragment : NoteFragment() {
170173 if (config.showKeyboard && isMenuVisible && (! note!! .isLocked() || shouldShowLockedContent)) {
171174 onGlobalLayout {
172175 if (activity?.isDestroyed == false ) {
176+ setupKeyboardListener()
173177 requestFocus()
174178 val inputManager = requireActivity().getSystemService(Context .INPUT_METHOD_SERVICE ) as InputMethodManager
175179 inputManager.showSoftInput(this , InputMethodManager .SHOW_IMPLICIT )
176-
177- val rect = Rect ()
178- noteEditText.getFocusedRect(rect)
179- binding.notesScrollview.postDelayed({
180- binding.notesScrollview.smoothScrollTo(0 , rect.bottom)
181- }, 1000 )
182180 }
183181 }
184182 }
@@ -207,6 +205,35 @@ class TextFragment : NoteFragment() {
207205 setTextWatcher()
208206 }
209207
208+ private fun setupKeyboardListener () {
209+ requireActivity().window.decorView.setOnApplyWindowInsetsListener { view, insets ->
210+ scrollToEndOfNote()
211+ view.onApplyWindowInsets(insets)
212+ }
213+
214+ val callback =
215+ object : WindowInsetsAnimationCompat .Callback (DISPATCH_MODE_CONTINUE_ON_SUBTREE ) {
216+ override fun onPrepare (animation : WindowInsetsAnimationCompat ) {
217+ super .onPrepare(animation)
218+ scrollToEndOfNote()
219+ }
220+
221+ override fun onProgress (
222+ insets : WindowInsetsCompat ,
223+ runningAnimations : MutableList <WindowInsetsAnimationCompat >,
224+ ) = insets
225+ }
226+ ViewCompat .setWindowInsetsAnimationCallback(requireActivity().window.decorView, callback)
227+ }
228+
229+ private fun scrollToEndOfNote () {
230+ val rect = Rect ()
231+ noteEditText.getFocusedRect(rect)
232+ binding.notesScrollview.post {
233+ binding.notesScrollview.scrollTo(0 , rect.bottom)
234+ }
235+ }
236+
210237 fun setTextWatcher () {
211238 noteEditText.apply {
212239 removeTextChangedListener(textWatcher)
0 commit comments