Skip to content

Commit

Permalink
Merge pull request #2829 from maranas/activityindicator-ios
Browse files Browse the repository at this point in the history
Added ActivityIndicator implementation for iOS
  • Loading branch information
freakboy3742 committed Sep 12, 2024
2 parents dbda4d4 + 8cbd5f9 commit a48204f
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 5 deletions.
1 change: 1 addition & 0 deletions changes/2829.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The ActivityIndicator widget is now supported on iOS.
6 changes: 4 additions & 2 deletions docs/reference/api/widgets/activityindicator.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ usually rendered as a "spinner" animation.

Not supported

.. group-tab:: iOS |no|
.. group-tab:: iOS

Not supported
.. figure:: /reference/images/activityindicator-iOS.png
:align: center
:width: 100px

.. group-tab:: Web |beta|

Expand Down
2 changes: 1 addition & 1 deletion docs/reference/data/widgets_by_platform.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Application,Core Component,:class:`~toga.App`,The application itself,|y|,|y|,|y|
Window,Core Component,:class:`~toga.Window`,An operating system-managed container of widgets.,|y|,|y|,|y|,|y|,|y|,|b|,|b|
DocumentWindow,Core Component,:class:`~toga.DocumentWindow`,A window that can be used as the main interface to a document-based app.,|y|,|y|,|y|,,,,
MainWindow,Core Component,:class:`~toga.MainWindow`,A window that can use the full set of window-level user interface elements.,|y|,|y|,|y|,|y|,|y|,|b|,|b|
ActivityIndicator,General Widget,:class:`~toga.ActivityIndicator`,A spinning activity animation,|y|,|y|,,,,|b|,
ActivityIndicator,General Widget,:class:`~toga.ActivityIndicator`,A spinning activity animation,|y|,|y|,,|y|,,|b|,
Button,General Widget,:class:`~toga.Button`,Basic clickable Button,|y|,|y|,|y|,|y|,|y|,|b|,|b|
Canvas,General Widget,:class:`~toga.Canvas`,A drawing area for 2D vector graphics.,|y|,|y|,|y|,|y|,|y|,,
DateInput,General Widget,:class:`~toga.DateInput`,A widget to select a calendar date,,,|y|,,|y|,,
Expand Down
Binary file added docs/reference/images/activityindicator-iOS.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion gtk/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ root = ".."
dependencies = [
"gbulb >= 0.5.3",
"pycairo >= 1.17.0",
"pygobject >= 3.46.0",
# New asyncio handling introduced in 3.50.0; that code is incompatible
# with gbulb, See #2550 for the code that replaces GBulb with the new
# asyncio code.
"pygobject < 3.50.0",
"toga-core == {version}",
]

Expand Down
2 changes: 2 additions & 0 deletions iOS/src/toga_iOS/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from .statusicons import MenuStatusIcon, SimpleStatusIcon, StatusIconSet

# Widgets
from .widgets.activityindicator import ActivityIndicator
from .widgets.box import Box
from .widgets.button import Button
from .widgets.canvas import Canvas
Expand Down Expand Up @@ -47,6 +48,7 @@ def not_implemented(feature):

__all__ = [
"not_implemented",
"ActivityIndicator",
"App",
"Command",
# Resources
Expand Down
4 changes: 4 additions & 0 deletions iOS/src/toga_iOS/libs/uikit.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ def NSTextAlignment(alignment):

UIKeyInput = ObjCProtocol("UIKeyInput")

######################################################################
# UIActivityIndicatorView.h
UIActivityIndicatorView = ObjCClass("UIActivityIndicatorView")

######################################################################
# UIAlertController.h
UIAlertController = ObjCClass("UIAlertController")
Expand Down
31 changes: 31 additions & 0 deletions iOS/src/toga_iOS/widgets/activityindicator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from rubicon.objc import CGSize

from toga_iOS.libs import UIActivityIndicatorView
from toga_iOS.widgets.base import Widget


class ActivityIndicator(Widget):
def create(self):
self.native = UIActivityIndicatorView.new()
self.native.hidesWhenStopped = True
self.native.translatesAutoresizingMaskIntoConstraints = False
self.native.sizeToFit()

self.add_constraints()

def set_hidden(self, hidden):
self.native.setHidden((not self.is_running()) or hidden)

def is_running(self):
return self.native.isAnimating()

def start(self):
self.native.startAnimating()

def stop(self):
self.native.stopAnimating()

def rehint(self):
fitting_size = self.native.systemLayoutSizeFittingSize(CGSize(0, 0))
self.interface.intrinsic.width = fitting_size.width
self.interface.intrinsic.height = fitting_size.height
7 changes: 7 additions & 0 deletions iOS/tests_backend/widgets/activityindicator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from toga_iOS.libs import UIActivityIndicatorView

from .base import SimpleProbe


class ActivityIndicatorProbe(SimpleProbe):
native_class = UIActivityIndicatorView
2 changes: 1 addition & 1 deletion testbed/tests/widgets/test_activityindicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

@pytest.fixture
async def widget():
skip_on_platforms("android", "iOS", "windows")
skip_on_platforms("android", "windows")
return toga.ActivityIndicator()


Expand Down

0 comments on commit a48204f

Please sign in to comment.