beeware / briefcase-android-gradle-template

A template for generating Android Gradle projects with Briefcase
MIT License
18 stars 19 forks source link

Add onConfigurationChanged to IPythonApp #50

Closed mhsmith closed 2 years ago

mhsmith commented 2 years ago

configChanges was added to AndroidManifest.xml a few weeks ago, which prevents the activity from being restarted when the screen rotates. However, Toga still doesn't update its layout after the rotation.

To fix this we'll need to implement onConfigurationChanged. The corresponding Toga PR is https://github.com/beeware/toga/pull/1507.

It's safe for the template update and the Toga update to be deployed separately:

Example of the previous behavior:

import toga
from toga.style import Pack
from toga.style.pack import COLUMN, ROW, LEFT, CENTER, RIGHT, TOP, BOTTOM

class Hello(toga.App):
    def startup(self):
        labels = [
            [toga.Label(text, style=Pack(flex=1)) for text in row]
            for row in [
                ["NW", "N", "NE"],
                ["W",  "X", "E"],
                ["SW", "S", "SE"],
            ]
        ]
        main_box = toga.Box(
            style=Pack(direction=COLUMN),
            children=[
                toga.Box(children=labels[0]),
                toga.Box(style=Pack(flex=1)),  # Spacer
                toga.Box(children=labels[1]),
                toga.Box(style=Pack(flex=1)),  # Spacer
                toga.Box(children=labels[2]),
            ]
        )

        self.main_window = toga.MainWindow(title=self.formal_name)
        self.main_window.content = main_box
        self.main_window.show()

        # Android backend doesn't support setting alignment until after native
        # widget creation.
        for row in labels:
            for label, text_align in zip(row, [LEFT, CENTER, RIGHT]):
                label.style.update(text_align=text_align)

def main():
    return Hello()

portrait-good

landscape-bad

PR Checklist: