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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
bfb48ac
Temp for watchOS AnimatedImage support, using massive private API, st…
dreampiggy Oct 6, 2019
80d2510
Update the hack for wacthKit experienment, fix the retain cycle issue…
dreampiggy Oct 11, 2019
9d5d5fd
Solve the merge conflict and try again
dreampiggy Oct 19, 2019
33fb3d3
Add support for contentMode
dreampiggy Oct 19, 2019
7f94bf6
Fix the SDAnimatedImageInterface first appear shows empty issues
dreampiggy Oct 19, 2019
cf588c8
Fix the scale factor support for SDAniamtedImageInterface
dreampiggy Oct 19, 2019
4736821
Fix the compile issue on other platforms
dreampiggy Oct 19, 2019
8441718
Merge branch 'master' of https://github.com/SDWebImage/SDWebImageSwif…
dreampiggy Oct 20, 2019
ab7a54c
Stop animtiong when dismantle for watchOS AnimatedImage
dreampiggy Oct 20, 2019
dfb9ab4
Fix the issue that stopAnimating does not stop :)
dreampiggy Oct 21, 2019
f1af6c2
Fix the warning because of Apple's bug
dreampiggy Oct 21, 2019
bdbf0a5
Use macro to integrate the watchOS Animation solution
dreampiggy Oct 21, 2019
a9fa353
Refactory code to fix that calling sd_setImage(with:) multiple times …
dreampiggy Oct 21, 2019
e456b38
Support to custom loop count on watchOS AnimatedImage
dreampiggy Oct 21, 2019
95bfc40
Fix the CocoaPods issues which does not have umbrella headers
dreampiggy Oct 21, 2019
73a9ff0
Update some of the documentations
dreampiggy Oct 21, 2019
30bc73f
Try to solve the SwiftPM issue because it does not support mixed Obje…
dreampiggy Oct 21, 2019
2e9af2f
Fix travis CI script to only build Carthage. Swift cli build can not …
dreampiggy Oct 21, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ script:
- pod install --project-directory=Example
- xcodebuild build -workspace Example/SDWebImageSwiftUI.xcworkspace -scheme SDWebImageSwiftUIDemo -sdk iphonesimulator -destination 'name=iPhone 8' ONLY_ACTIVE_ARCH=NO | xcpretty -c

- swift build
- carthage update --platform iOS
- xcodebuild build -project SDWebImageSwiftUI.xcodeproj -scheme 'SDWebImageSwiftUI' -sdk iphonesimulator -configuration Debug | xcpretty -c
2 changes: 1 addition & 1 deletion Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github "SDWebImage/SDWebImage" "5.1.0"
github "SDWebImage/SDWebImage" "5.2.3"
4 changes: 2 additions & 2 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ PODS:
- SDWebImage (5.2.3):
- SDWebImage/Core (= 5.2.3)
- SDWebImage/Core (5.2.3)
- SDWebImageSwiftUI (0.3.2):
- SDWebImageSwiftUI (0.3.3):
- SDWebImage (~> 5.1)
- SDWebImageWebPCoder (0.2.5):
- libwebp (~> 1.0)
Expand All @@ -34,7 +34,7 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
libwebp: 057912d6d0abfb6357d8bb05c0ea470301f5d61e
SDWebImage: 46a7f73228f84ce80990c786e4372cf4db5875ce
SDWebImageSwiftUI: a8a03ef596dde2e9668a76794f6c59d194289bb0
SDWebImageSwiftUI: 2284857313ca5085ab7b5310d372420d23c0817f
SDWebImageWebPCoder: 947093edd1349d820c40afbd9f42acb6cdecd987

PODFILE CHECKSUM: 3fb06a5173225e197f3a4bf2be7e5586a693257a
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
10 changes: 3 additions & 7 deletions Example/SDWebImageSwiftUIDemo/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ struct ContentView: View {
Button(action: { self.reloadCache() }) {
Text("Reload")
}
Button(action: { self.switchView() }) {
Text("Switch")
}
}
#endif
}
Expand All @@ -76,7 +79,6 @@ struct ContentView: View {
ForEach(imageURLs) { url in
NavigationLink(destination: DetailView(url: url, animated: self.animated)) {
HStack {
#if os(iOS) || os(tvOS) || os(macOS)
if self.animated {
AnimatedImage(url: URL(string:url))
.resizable()
Expand All @@ -88,12 +90,6 @@ struct ContentView: View {
.scaledToFit()
.frame(width: CGFloat(100), height: CGFloat(100), alignment: .center)
}
#else
WebImage(url: URL(string:url))
.resizable()
.scaledToFit()
.frame(width: CGFloat(100), height: CGFloat(100), alignment: .center)
#endif
Text((url as NSString).lastPathComponent)
}
}
Expand Down
18 changes: 1 addition & 17 deletions Example/SDWebImageSwiftUIDemo/DetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct DetailView: View {
contentView()
}
#endif
#if os(macOS)
#if os(macOS) || os(watchOS)
if animated {
contentView()
.contextMenu {
Expand All @@ -45,16 +45,12 @@ struct DetailView: View {
contentView()
}
#endif
#if os(watchOS)
contentView()
#endif
Spacer()
}
}

func contentView() -> some View {
HStack {
#if os(iOS) || os(tvOS) || os(macOS)
if animated {
AnimatedImage(url: URL(string:url), options: [.progressiveLoad], isAnimating: $isAnimating)
.onProgress(perform: { (receivedSize, expectedSize) in
Expand All @@ -79,18 +75,6 @@ struct DetailView: View {
.resizable()
.scaledToFit()
}
#else
WebImage(url: URL(string:url), options: [.progressiveLoad])
.onProgress(perform: { (receivedSize, expectedSize) in
if (expectedSize >= 0) {
self.progress = CGFloat(receivedSize) / CGFloat(expectedSize)
} else {
self.progress = 1
}
})
.resizable()
.scaledToFit()
#endif
}
}
}
Expand Down
11 changes: 10 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,16 @@ let package = Package(
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
.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"),
path: "SDWebImageSwiftUI/Classes/ObjC",
publicHeadersPath: "."
)
]
)
2 changes: 1 addition & 1 deletion SDWebImageSwiftUI.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Which aims to provide a better support for SwiftUI users.
s.tvos.deployment_target = '13.0'
s.watchos.deployment_target = '6.0'

s.source_files = 'SDWebImageSwiftUI/Classes/**/*'
s.source_files = 'SDWebImageSwiftUI/Classes/**/*', 'SDWebImageSwiftUI/Module/*.h'

s.frameworks = 'SwiftUI'
s.dependency 'SDWebImage', '~> 5.1'
Expand Down
44 changes: 44 additions & 0 deletions SDWebImageSwiftUI.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
objects = {

/* Begin PBXBuildFile section */
324F61C7235E07EC003973B8 /* SDAnimatedImageInterface.h in Headers */ = {isa = PBXBuildFile; fileRef = 324F61C5235E07EC003973B8 /* SDAnimatedImageInterface.h */; settings = {ATTRIBUTES = (Public, ); }; };
324F61C8235E07EC003973B8 /* SDAnimatedImageInterface.h in Headers */ = {isa = PBXBuildFile; fileRef = 324F61C5235E07EC003973B8 /* SDAnimatedImageInterface.h */; settings = {ATTRIBUTES = (Public, ); }; };
324F61C9235E07EC003973B8 /* SDAnimatedImageInterface.h in Headers */ = {isa = PBXBuildFile; fileRef = 324F61C5235E07EC003973B8 /* SDAnimatedImageInterface.h */; settings = {ATTRIBUTES = (Public, ); }; };
324F61CA235E07EC003973B8 /* SDAnimatedImageInterface.h in Headers */ = {isa = PBXBuildFile; fileRef = 324F61C5235E07EC003973B8 /* SDAnimatedImageInterface.h */; settings = {ATTRIBUTES = (Public, ); }; };
324F61CB235E07EC003973B8 /* SDAnimatedImageInterface.m in Sources */ = {isa = PBXBuildFile; fileRef = 324F61C6235E07EC003973B8 /* SDAnimatedImageInterface.m */; };
324F61CC235E07EC003973B8 /* SDAnimatedImageInterface.m in Sources */ = {isa = PBXBuildFile; fileRef = 324F61C6235E07EC003973B8 /* SDAnimatedImageInterface.m */; };
324F61CD235E07EC003973B8 /* SDAnimatedImageInterface.m in Sources */ = {isa = PBXBuildFile; fileRef = 324F61C6235E07EC003973B8 /* SDAnimatedImageInterface.m */; };
324F61CE235E07EC003973B8 /* SDAnimatedImageInterface.m in Sources */ = {isa = PBXBuildFile; fileRef = 324F61C6235E07EC003973B8 /* SDAnimatedImageInterface.m */; };
326E480A23431C0F00C633E9 /* ImageViewWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 326E480923431C0F00C633E9 /* ImageViewWrapper.swift */; };
326E480B23431C0F00C633E9 /* ImageViewWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 326E480923431C0F00C633E9 /* ImageViewWrapper.swift */; };
326E480C23431C0F00C633E9 /* ImageViewWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 326E480923431C0F00C633E9 /* ImageViewWrapper.swift */; };
Expand Down Expand Up @@ -89,6 +97,8 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
324F61C5235E07EC003973B8 /* SDAnimatedImageInterface.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDAnimatedImageInterface.h; sourceTree = "<group>"; };
324F61C6235E07EC003973B8 /* SDAnimatedImageInterface.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDAnimatedImageInterface.m; sourceTree = "<group>"; };
326E480923431C0F00C633E9 /* ImageViewWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageViewWrapper.swift; sourceTree = "<group>"; };
32C43DCC22FD540D00BE87F5 /* SDWebImageSwiftUI.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SDWebImageSwiftUI.framework; sourceTree = BUILT_PRODUCTS_DIR; };
32C43DDC22FD54C600BE87F5 /* ImageManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageManager.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -142,6 +152,15 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
324F61C4235E07EC003973B8 /* ObjC */ = {
isa = PBXGroup;
children = (
324F61C5235E07EC003973B8 /* SDAnimatedImageInterface.h */,
324F61C6235E07EC003973B8 /* SDAnimatedImageInterface.m */,
);
path = ObjC;
sourceTree = "<group>";
};
32C43DC222FD540D00BE87F5 = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -175,6 +194,7 @@
32C43DDB22FD54C600BE87F5 /* Classes */ = {
isa = PBXGroup;
children = (
324F61C4235E07EC003973B8 /* ObjC */,
32C43DDC22FD54C600BE87F5 /* ImageManager.swift */,
32C43DDE22FD54C600BE87F5 /* WebImage.swift */,
32C43DDF22FD54C600BE87F5 /* AnimatedImage.swift */,
Expand Down Expand Up @@ -202,6 +222,7 @@
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
324F61C7235E07EC003973B8 /* SDAnimatedImageInterface.h in Headers */,
32C43DE622FD54CD00BE87F5 /* SDWebImageSwiftUI.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -210,6 +231,7 @@
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
324F61C8235E07EC003973B8 /* SDAnimatedImageInterface.h in Headers */,
32C43E2222FD583A00BE87F5 /* SDWebImageSwiftUI.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -218,6 +240,7 @@
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
324F61C9235E07EC003973B8 /* SDAnimatedImageInterface.h in Headers */,
32C43E2322FD583B00BE87F5 /* SDWebImageSwiftUI.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -226,6 +249,7 @@
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
324F61CA235E07EC003973B8 /* SDAnimatedImageInterface.h in Headers */,
32C43E2422FD583C00BE87F5 /* SDWebImageSwiftUI.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -320,15 +344,19 @@
TargetAttributes = {
32C43DCB22FD540D00BE87F5 = {
CreatedOnToolsVersion = 11.0;
LastSwiftMigration = 1100;
};
32C43DF322FD57FD00BE87F5 = {
CreatedOnToolsVersion = 11.0;
LastSwiftMigration = 1100;
};
32C43E0022FD581400BE87F5 = {
CreatedOnToolsVersion = 11.0;
LastSwiftMigration = 1100;
};
32C43E0D22FD581C00BE87F5 = {
CreatedOnToolsVersion = 11.0;
LastSwiftMigration = 1100;
};
};
};
Expand Down Expand Up @@ -394,6 +422,7 @@
326E480A23431C0F00C633E9 /* ImageViewWrapper.swift in Sources */,
32C43E1622FD583700BE87F5 /* ImageManager.swift in Sources */,
32C43E1822FD583700BE87F5 /* AnimatedImage.swift in Sources */,
324F61CB235E07EC003973B8 /* SDAnimatedImageInterface.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -406,6 +435,7 @@
326E480B23431C0F00C633E9 /* ImageViewWrapper.swift in Sources */,
32C43E1922FD583700BE87F5 /* ImageManager.swift in Sources */,
32C43E1B22FD583700BE87F5 /* AnimatedImage.swift in Sources */,
324F61CC235E07EC003973B8 /* SDAnimatedImageInterface.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -418,6 +448,7 @@
326E480C23431C0F00C633E9 /* ImageViewWrapper.swift in Sources */,
32C43E1C22FD583800BE87F5 /* ImageManager.swift in Sources */,
32C43E1E22FD583800BE87F5 /* AnimatedImage.swift in Sources */,
324F61CD235E07EC003973B8 /* SDAnimatedImageInterface.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -430,6 +461,7 @@
326E480D23431C0F00C633E9 /* ImageViewWrapper.swift in Sources */,
32C43E1F22FD583800BE87F5 /* ImageManager.swift in Sources */,
32C43E2122FD583800BE87F5 /* AnimatedImage.swift in Sources */,
324F61CE235E07EC003973B8 /* SDAnimatedImageInterface.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -565,6 +597,7 @@
32C43DD522FD540D00BE87F5 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
Expand All @@ -585,6 +618,7 @@
PRODUCT_NAME = SDWebImageSwiftUI;
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
Expand All @@ -593,6 +627,7 @@
32C43DD622FD540D00BE87F5 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
Expand Down Expand Up @@ -621,6 +656,7 @@
32C43DFA22FD57FD00BE87F5 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
DEFINES_MODULE = YES;
Expand All @@ -643,13 +679,15 @@
PRODUCT_NAME = SDWebImageSwiftUI;
SDKROOT = macosx;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
};
name = Debug;
};
32C43DFB22FD57FD00BE87F5 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
DEFINES_MODULE = YES;
Expand Down Expand Up @@ -679,6 +717,7 @@
32C43E0722FD581400BE87F5 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
Expand All @@ -699,6 +738,7 @@
PRODUCT_NAME = SDWebImageSwiftUI;
SDKROOT = appletvos;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 3;
};
Expand All @@ -707,6 +747,7 @@
32C43E0822FD581400BE87F5 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
Expand Down Expand Up @@ -736,6 +777,7 @@
isa = XCBuildConfiguration;
buildSettings = {
APPLICATION_EXTENSION_API_ONLY = YES;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
Expand All @@ -756,6 +798,7 @@
PRODUCT_NAME = SDWebImageSwiftUI;
SDKROOT = watchos;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 4;
};
Expand All @@ -765,6 +808,7 @@
isa = XCBuildConfiguration;
buildSettings = {
APPLICATION_EXTENSION_API_ONLY = YES;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
Expand Down
Loading