Skip to content

Support AnimatedImage on watchOS - Using WatchKit bridge #22

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 18 commits into from
Oct 21, 2019

Conversation

dreampiggy
Copy link
Collaborator

This feature implements the AnimatedImage view on watchOS via SwiftUI.

The implementation is based on a implementation of SDAnimatedImageInterface, which subclass the WKInterfaceImage (which Apple's documentation does not recommend). This is the temporary solution to fit our usage and because of the hack, this may not be compatible for future watchOS 7 release.

See my tweet about this: https://twitter.com/DreamingPiggy/status/1185582862583488514

In long term, the Native UIView bridge is not a general solution. In the future, when SDWebImage this PR is ready: SDWebImage/SDWebImage#2861

The SwifUI port will use native Image struct with Animated Player, to refresh and render each frames, which may be better than current solution.

@dreampiggy
Copy link
Collaborator Author

dreampiggy commented Oct 21, 2019

This PR, actually, show all the current Swift, SwiftPM and SwiftUI's pain and bugs.

To say, this is a good experiment, which show How hard it is for user to write a framework like Apple, which contains real world code and edge cases.

  1. SwiftPM does not support mixed language code like Swift/Objective-C, Swift/C.
    Workaround: Create each language code a different target, then using target dependencies.
        .target(
            name: "SDWebImageSwiftUI",
            dependencies: ["SDWebImage", "SDWebImageSwiftUIObjC"],
            path: "SDWebImageSwiftUI/Classes",
            exclude: ["ObjC"]
        ),
        // This is implementation detail because SwiftPM does not support mixed Objective-C/Swift code, don't dependent this target
        .target(
            name: "SDWebImageSwiftUIObjC",
            dependencies: ["SDWebImage"],
            path: "SDWebImageSwiftUI/Classes/ObjC",
            sources: ["SDAnimatedImageInterface.h", "SDAnimatedImageInterface.m"],
            publicHeadersPath: "."
        )
  1. SwiftUI lack of robust test on watchOS. Many many bugs that only appears on watchOS, like WKInterfaceRepresentable. The WKInterfaceRepresentable will always leak on watchOS 6.0, See radar FB7395006:

image

  1. CGAnimateImageDataWithBlock is not callable from Swift. Because Apple does not write correct ImageIO.modulemap to include its headers. We have to use Objective-C. Good Apple, another radar FB7252319:

image

@dreampiggy dreampiggy requested a review from kinarobin October 21, 2019 16:03
@dreampiggy dreampiggy force-pushed the feature_watchOS_animation branch 2 times, most recently from 4cdcbe8 to 7563ccd Compare October 21, 2019 16:21
…works on Objective-C code import syntax, but works on Xcode
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