Skip to content

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
1 participant