Skip to content
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

Make container automatically resize on orientation change #2161

Merged
merged 5 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/2161.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
iOS container views are now set to automatically resize with their parent view
4 changes: 4 additions & 0 deletions iOS/src/toga_iOS/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
UIApplication,
UINavigationController,
UIView,
UIViewAutoresizing,
UIViewController,
)

Expand Down Expand Up @@ -65,6 +66,9 @@ def __init__(self, content=None, layout_native=None, on_refresh=None):
super().__init__(content=content, on_refresh=on_refresh)
self.native = UIView.alloc().init()
self.native.translatesAutoresizingMaskIntoConstraints = True
self.native.autoresizingMask = (
UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight
)

self.layout_native = self.native if layout_native is None else layout_native

Expand Down
12 changes: 11 additions & 1 deletion iOS/src/toga_iOS/libs/uikit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# System/Library/Frameworks/UIKit.framework
##########################################################################
from ctypes import POINTER, c_char_p, c_int, c_void_p, cdll, util
from enum import Enum
from enum import Enum, IntEnum

from rubicon.objc import ObjCClass, ObjCProtocol, objc_const

Expand Down Expand Up @@ -452,6 +452,16 @@ class UIViewContentMode(Enum):
BottomRight = 12


class UIViewAutoresizing(IntEnum):
NoResizing = 0
FlexibleLeftMargin = 1 << 0
FlexibleWidth = 1 << 1
FlexibleRightMargin = 1 << 2
FlexibleTopMargin = 1 << 3
FlexibleHeight = 1 << 4
FlexibleBottomMargin = 1 << 5


######################################################################
# UIViewController.h
UIViewController = ObjCClass("UIViewController")
Expand Down