Skip to content

Commit 92d1de3

Browse files
committed
Merge pull request kivy#4316 from kivy/animate_window_content
Animate the window content based on `softinput_mode`, introducing
2 parents 86f2232 + 40067a6 commit 92d1de3

File tree

1 file changed

+40
-6
lines changed

1 file changed

+40
-6
lines changed

kivy/core/window/__init__.py

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
# late import
3232
VKeyboard = None
3333
android = None
34-
34+
Animation = None
3535

3636
class Keyboard(EventDispatcher):
3737
'''Keyboard interface that is returned by
@@ -523,13 +523,27 @@ def _set_rotation(self, x):
523523
'''
524524

525525
_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)
526539

527540
def _upd_kbd_height(self, *kargs):
528541
self._keyboard_changed = not self._keyboard_changed
529-
self.update_viewport()
542+
self._animate_content()
530543

531544
def _get_ios_kheight(self):
532-
return 0
545+
import ios
546+
return ios.get_kheight()
533547

534548
def _get_android_kheight(self):
535549
if USE_SDL2: # Placeholder until the SDL2 bootstrap supports this
@@ -547,8 +561,7 @@ def _get_kheight(self):
547561
return 0
548562

549563
keyboard_height = AliasProperty(_get_kheight, None,
550-
bind=('_keyboard_changed',),
551-
cache=True)
564+
bind=('_keyboard_changed',), cached=True)
552565
'''Rerturns the height of the softkeyboard/IME on mobile platforms.
553566
Will return 0 if not on mobile platform or if IME is not active.
554567
@@ -558,6 +571,26 @@ def _get_kheight(self):
558571
:class:`~kivy.propertries.AliasProperty` and defaults to 0.
559572
'''
560573

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+
561594
def _set_system_size(self, size):
562595
self._size = size
563596

@@ -685,6 +718,7 @@ def __init__(self, **kwargs):
685718
# Create a trigger for updating the keyboard height
686719
self.trigger_keyboard_height = Clock.create_trigger(
687720
self._upd_kbd_height, .5)
721+
self.bind(_kheight=lambda *args: self.update_viewport())
688722

689723
# set the default window parameter according to the configuration
690724
if 'borderless' not in kwargs:
@@ -1092,7 +1126,7 @@ def update_viewport(self):
10921126
smode = self.softinput_mode
10931127
target = self._system_keyboard.target
10941128
targettop = max(0, target.to_window(0, target.y)[1]) if target else 0
1095-
kheight = self.keyboard_height
1129+
kheight = self._kheight
10961130

10971131
w2, h2 = w / 2., h / 2.
10981132
r = radians(self.rotation)

0 commit comments

Comments
 (0)