-
Notifications
You must be signed in to change notification settings - Fork 34
fix: keyboard hiding cursor on startup #172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: keyboard hiding cursor on startup #172
Conversation
naveensingh
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The action bar and tab layout now move off-screen due to those flags. I think this should be fixed directly in the fragment (e.g., by scrolling to the end) rather than activity level.
(Is that i3wm or sway in your video?)
ah I didn't see that, good catch it's my own build of dwm |
|
I'm a little stumped on this one. I'm new to android so I'm sure that I am missing something obvious. I can't figure out where to find the callback for after the keyboard appears fully. I also was searching in the docs for a way to find out what the keyboard height would be when fully rendered so that I could just calculate where the fragment should scroll to, but I wasn't able to find that either. Currently the only thing that I can get to work is to make the scroll happen on a delay after the app/src/main/kotlin/org/fossify/notes/fragments/TextFragment.kt:165 if (config.showKeyboard && isMenuVisible && (!note!!.isLocked() || shouldShowLockedContent)) {
onGlobalLayout {
if (activity?.isDestroyed == false) {
requestFocus()
val inputManager = requireActivity().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
inputManager.showSoftInput(this, InputMethodManager.SHOW_IMPLICIT)
+
+ val rect = Rect()
+ noteEditText.getFocusedRect(rect)
+ binding.notesScrollview.postDelayed({
+ binding.notesScrollview.smoothScrollTo(0, rect.bottom)
+ }, 1000)
}
}
} |
|
How about a window inset listener? For example, see |
app/src/main/kotlin/org/fossify/notes/fragments/TextFragment.kt
Outdated
Show resolved
Hide resolved
app/src/main/kotlin/org/fossify/notes/fragments/TextFragment.kt
Outdated
Show resolved
Hide resolved
Co-authored-by: Naveen Singh <36371707+naveensingh@users.noreply.github.com>
|
There's an issue now that we moved the code over to a window inset listener. Every time we open/close the keyboard it executes the scroll |
|
I'm thinking we could keep it on the Is there a better way? |
That's what I'm also thinking: private fun setupKeyboardListener() {
requireActivity().window.decorView.apply {
setOnApplyWindowInsetsListener { view, insets ->
val windowInsets = WindowInsetsCompat.toWindowInsetsCompat(insets)
if (windowInsets.isVisible(WindowInsetsCompat.Type.ime())) {
scrollToEndOfNote()
setOnApplyWindowInsetsListener(null) // clear to avoid scrolling every time
}
view.onApplyWindowInsets(insets)
}
}
}In addition to checking keyboard visibility, we also need to check whether (This trick should work without side effects here because nothing else in this activity is calling
Nope, none that I can think of now. |
Co-authored-by: Naveen Singh <36371707+naveensingh@users.noreply.github.com>
|
There's one more issue: The scroll only works on cold starts. Exit app via back button ➜ reopen app ➜ content still behind the keyboard. |
|
looking into it more, my current code is probably not a good solution because even closing and reopening the keyboard leads to the same covering issue. I think the best way would be to always scroll right to where to cursor is on keyboard open if the cursor isn't on screen after the keyboard fully opens, then we wouldn't have to unset it, and would work in all cases. I don't know if that's easy to do or if I need to do some calculations or if that's even possible idk. |
Good idea! I have a solution, but I haven't tested it much:
|
Co-authored-by: Naveen Singh <36371707+naveensingh@users.noreply.github.com>
…ersonal/Notes into keyboard_hiding_cursor
that worked perfectly! it seems to work exactly how it should by scrolling the cursor into view every time the keyboard is opened |
naveensingh
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Type of change(s)
What changed and why
config.showKeyboardis trueI don't know if this is the cleanest place to put this, let me know if there is a better place and I'll change it!
Before/After Screenshots/Screen Record
before:
https://github.com/user-attachments/assets/871dea74-eb7e-4138-96e1-ae949ee944e1
after:
fixed2.mp4
Fixes the following issue(s)
Checklist
CHANGELOG.md(if applicable).