-
-
Notifications
You must be signed in to change notification settings - Fork 672
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
Added ActivityIndicator implementation for iOS #2829
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
eb93558
Added ActivityIndicator implementation for iOS
maranas 2469ecf
Updated documentation for the iOS ActivityIndicatorWidget
maranas c5e7963
Enabled tests for the iOS ActivityIndicator
maranas bf5869a
Updated widgets_by_platform.csv to include ActivityIndicator for iOS
maranas 42d7fb5
Update changes/2829.feature.rst
maranas 791691b
Update docs/reference/api/widgets/activityindicator.rst
maranas 7d98567
Added implementation note for ActivityIndicator on iOS explaining the…
maranas c2d0ebd
ActivityIndicator for iOS - Fixed the initial hidden state issue by o…
maranas d2c6f07
Updated ActivityIndicator test backend for iOS with the correct nativ…
maranas fdca33b
Updated documentation formatting
maranas e927828
Deleted activityindicator-ios.png (incorrect case)
maranas 48ace84
Added activityindicator-iOS.png with correct case (git issues, so had…
maranas 8cbd5f9
Add upper version pin to PyGObject.
freakboy3742 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
The ActivityIndicator widget is now supported on iOS. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason that both the UIView and UIActivatorView is needed? Is it not possible to use UIActivityIndicatorView directly as the native widget? If it isn't, there should be a docstring here describing the reason; if it is... then that's an easy cleanup :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this one I had to wrap it in a parent UIView, because for some reason the UIActivityIndicatorView shows up even when stopped, regardless of whether I set the
hidesWhenStopped
property totrue
- I'll add it in the docstrings in case someone figures out what is wrong, but for now this was the only way I could think of that was relatively cleanThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@freakboy3742 I added some information about the issue in a comment here: 7d98567
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok - you successfully nerd sniped me here :-)
I've worked out what is going on.
hidesWhenStopped
is implemented as a wrapper around the literalsetHidden()
implementation - so stopping the spinner isn't just making the image disappear, it's literally hiding the widget.The catch: when Toga starts up, it applies styles to all widgets - and one of the styles it applies is visibility. So - when you don't have the wrapper, Toga creates the widget, sets
hiddenWhenStopped
, and then sets the widget to be visible... which means you can then see it.This doesn't happen when the widget is wrapped by the UIView because the hidden attribute of the container view is separate from the hidden attribute of the spinner itself.
So - the fix here is to override
set_hidden()
on the iOS ActivityIndicator so that it takes into account whether the spinner is running before applying visibility on the underlying widget.This might have an impact on the testbed test - the probe evaluating visibility might also need to be adjusted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation! I was too stuck at thinking that it may be an issue with the bridge calls that I didn't think to look at the base widget 😅 I'll investigate, will have a look at the potential testbed changes as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've just pushed the changes @freakboy3742 - it seems the testbed didn't require any changes because the activityindicator test does not check for the visibility when stopped. This will need updating, but if it's fine on your end I'd like to do that in a separate change as I might need to implement probes for the other platforms too (gtk and cocoa)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy for the test improvement to be a separate PR.