Skip to content

Commit

Permalink
Implement await redraw for Android
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsmith committed Feb 26, 2023
1 parent fe92bb9 commit 73f0c5a
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions android/tests_backend/widgets/base.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
import asyncio

from java import dynamic_proxy
from pytest import skip

from android.view import ViewTreeObserver


class LayoutListener(dynamic_proxy(ViewTreeObserver.OnGlobalLayoutListener)):
def __init__(self):
super().__init__()
self.event = asyncio.Event()

def onGlobalLayout(self):
self.event.set()
self.event.clear()


class SimpleProbe:
def __init__(self, widget):
self.widget = widget
self.native = widget._impl.native
self.layout_listener = LayoutListener()
self.native.getViewTreeObserver().addOnGlobalLayoutListener(
self.layout_listener
)

# Store the device DPI, as it will be needed to scale some values
self.dpi = (
Expand All @@ -15,6 +32,11 @@ def __init__(self, widget):

assert isinstance(self.native, self.native_class)

def __del__(self):
self.native.getViewTreeObserver().removeOnGlobalLayoutListener(
self.layout_listener
)

def assert_container(self, container):
container_native = container._impl.native
for i in range(container_native.getChildCount()):
Expand All @@ -29,8 +51,8 @@ def assert_alignment_equivalent(self, actual, expected):

async def redraw(self):
"""Request a redraw of the app, waiting until that redraw has completed."""
# TODO: Wait for redraws to complete
pass
self.native.requestLayout()
await self.layout_listener.event.wait()

# If we're running slow, wait for a second
if self.widget.app.run_slow:
Expand Down

0 comments on commit 73f0c5a

Please sign in to comment.