-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
keyboard issue when switching between TextInput widgets on android #7698
Comments
Hello, I have just fixed this bug here using the When you click on When you click on textfield_1 and then you click on textfield_2, you have two possibilities:
Isn't the two possibilities the same? The solution I found was modifying the from kivy.app import App
from kivy.clock import Clock
from kivy.lang import Builder
from kivy.factory import Factory as F
from kivy.uix.textinput import TextInput
from kivy.core.window import Window
Window.softinput_mode = "below_target"
class TextInputFixed(TextInput):
def on_focus(self, instance, value, *args):
if value:
Clock.schedule_once(self.create_keyboard, .1)
else:
self.hide_keyboard()
def create_keyboard(self, *args):
self.show_keyboard()
def remove_focus_decorator(function):
def wrapper(self, touch):
if not self.collide_point(*touch.pos):
self.focus = False
function(self, touch)
return wrapper
@remove_focus_decorator
def on_touch_down(self, touch):
super().on_touch_down(touch)
class ScreenOne(F.Screen):
pass
Builder.load_string("""
<ScreenOne>:
BoxLayout:
orientation: 'vertical'
Button:
Label:
text: 'Username:'
size_hint_y: None
height: self.texture_size[1]
TextInputFixed:
pos_hint: {'center_x': .5}
foreground_color: 1,0,0,1
keyboard_mode: 'managed'
on_text_validate: tf.focus = True
multiline: False
Label:
text: 'Password:'
size_hint_y: None
height: self.texture_size[1]
TextInputFixed:
id: tf
pos_hint: {'center_x': .5}
keyboard_mode: 'managed'
Widget:
""")
class MainApp(App):
def build(self):
self.screen_one = ScreenOne()
return ScreenOne()
MainApp().run() record-20220511-090709.mp4 |
https://github.com/kivy/kivy/blob/master/kivy/uix/behaviors/focus.py#L400 Can you confirm the issue is here? Would explain why (prior to example above) it wasn't replicated. Or were you seeing the same prior to setting keyboard_mode to managed? |
Yes, it is happening due to Sometimes T2 would say "I will create keyboard now", and afterwards T1 would say "I will destroy keyboard now", but the order should always be 1) The keyboard disappears; 2) The keyboard appears. But I have never used keyboard_mode 'manage' before and the bug was always happening on my current phone, but other users haven't reported the same issue until this week. I didn't even knew it 'manage' existed. During this night I was able to reproduce the issue both on computer and smartphone deterministically, and the code I posted prevented the bug on both. Sorry if my explanation is not the best, but using the debugger makes it clear what is really happening there, probably there is a better fix but I will use this workaround ('manage') for now |
Not seeing where your debug prints were sort of limits the usefulness; it probably is somewhat a race condition - needing a wait for the subsequent request yea would've been how I would've interpreted what you were seeing too. Did you try with On the other hand/further thinking; if that retains the issue then presumably due to it being a property change; on two widgets both being propagated on next tick (which I believe is the case now, rather than an immediate firing) with the order being unspecified. |
I've tested with |
Software Versions
using python for android
Describe the bug
when we have more then on
TextInput
in same screen on android the keyboard some times not appears when switching directly fromTextInput
to another only work fine if I close the keyboard and focus the other oneCode and Logs and screenshots
Additional context
the video will show the issue on android
Screen_Recording_20211119-184400_Pydroid.3.mp4
The text was updated successfully, but these errors were encountered: