Skip to content

Fix that AnimatedImage on watchOS, does not stop animating when disappear and cause performance issue #29

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

Merged
merged 2 commits into from
Oct 26, 2019

Conversation

dreampiggy
Copy link
Collaborator

@dreampiggy dreampiggy commented Oct 26, 2019

I don't find any documentation about How a UIViewRepresentable or WKInterfaceObjectRepresentable can response to onAppear or onDisappear Because UIViewRepresentable can not override itself with view modifier, and no public API here.

Previouslly there is a bug that watchOS does not behave correctly. (If we nagivate to detail page, list page animated images still animating and consume CPU)

One simple solution, create a extra wrapper for watchOS (which View.body is just a AnimatedImage and configed onAppear, onDisappear to control animating). But I really don't want to do so, which looks suck. 🤮

However, I found that when onAppear or onDisappear, the view's updateWKInterfaceObject method will be called. So we can use this to detect current visibility. (Using internal UIView.window to detect)

@dreampiggy dreampiggy force-pushed the bugfix_watchOS_animatedimage_stop_when_disappear branch from 17af6d5 to 5582b33 Compare October 26, 2019 19:02
@dreampiggy dreampiggy merged commit 7d4030a into master Oct 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant