31
31
# late import
32
32
VKeyboard = None
33
33
android = None
34
-
34
+ Animation = None
35
35
36
36
class Keyboard (EventDispatcher ):
37
37
'''Keyboard interface that is returned by
@@ -523,13 +523,27 @@ def _set_rotation(self, x):
523
523
'''
524
524
525
525
_keyboard_changed = BooleanProperty (False )
526
+ _kheight = NumericProperty (0 )
527
+
528
+ def _animate_content (self ):
529
+ '''Animate content to IME height.
530
+ '''
531
+ kargs = self .keyboard_anim_args
532
+ global Animation
533
+ if not Animation :
534
+ from kivy .animation import Animation
535
+ Animation .cancel_all (self )
536
+ Animation (
537
+ _kheight = self .keyboard_height + self .keyboard_padding ,
538
+ d = kargs ['d' ], t = kargs ['t' ]).start (self )
526
539
527
540
def _upd_kbd_height (self , * kargs ):
528
541
self ._keyboard_changed = not self ._keyboard_changed
529
- self .update_viewport ()
542
+ self ._animate_content ()
530
543
531
544
def _get_ios_kheight (self ):
532
- return 0
545
+ import ios
546
+ return ios .get_kheight ()
533
547
534
548
def _get_android_kheight (self ):
535
549
if USE_SDL2 : # Placeholder until the SDL2 bootstrap supports this
@@ -547,8 +561,7 @@ def _get_kheight(self):
547
561
return 0
548
562
549
563
keyboard_height = AliasProperty (_get_kheight , None ,
550
- bind = ('_keyboard_changed' ,),
551
- cache = True )
564
+ bind = ('_keyboard_changed' ,), cached = True )
552
565
'''Rerturns the height of the softkeyboard/IME on mobile platforms.
553
566
Will return 0 if not on mobile platform or if IME is not active.
554
567
@@ -558,6 +571,26 @@ def _get_kheight(self):
558
571
:class:`~kivy.propertries.AliasProperty` and defaults to 0.
559
572
'''
560
573
574
+ keyboard_anim_args = {'t' : 'in_out_quart' , 'd' : .5 }
575
+ '''The attributes for animating softkeyboard/IME.
576
+ `t` = `transition`, `d` = `duration`. Will have no effect on desktops.
577
+
578
+ .. versionadded:: 1.9.2
579
+
580
+ :attr:`keyboard_anim_args` is a dict with values
581
+ 't': 'in_out_quart', 'd': `.5`.
582
+ '''
583
+
584
+ keyboard_padding = NumericProperty (0 )
585
+ '''The padding to have between the softkeyboard/IME & target
586
+ or bottom of window. Will have no effect on desktops.
587
+
588
+ .. versionadded:: 1.9.2
589
+
590
+ :attr:`keyboard_padding` is a
591
+ :class:`~kivy.propertries.NumericProperty` and defaults to 0.
592
+ '''
593
+
561
594
def _set_system_size (self , size ):
562
595
self ._size = size
563
596
@@ -685,6 +718,7 @@ def __init__(self, **kwargs):
685
718
# Create a trigger for updating the keyboard height
686
719
self .trigger_keyboard_height = Clock .create_trigger (
687
720
self ._upd_kbd_height , .5 )
721
+ self .bind (_kheight = lambda * args : self .update_viewport ())
688
722
689
723
# set the default window parameter according to the configuration
690
724
if 'borderless' not in kwargs :
@@ -1092,7 +1126,7 @@ def update_viewport(self):
1092
1126
smode = self .softinput_mode
1093
1127
target = self ._system_keyboard .target
1094
1128
targettop = max (0 , target .to_window (0 , target .y )[1 ]) if target else 0
1095
- kheight = self .keyboard_height
1129
+ kheight = self ._kheight
1096
1130
1097
1131
w2 , h2 = w / 2. , h / 2.
1098
1132
r = radians (self .rotation )
0 commit comments