Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Temp for watchOS AnimatedImage support, using massive private API, st…
…ill contains small issues
  • Loading branch information
dreampiggy committed Oct 19, 2019
commit bfb48ac1e86b30f352fa1195c905dfa0671dfbf9
12 changes: 6 additions & 6 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ PODS:
- libwebp/mux (1.0.3):
- libwebp/demux
- libwebp/webp (1.0.3)
- SDWebImage (5.2.3):
- SDWebImage/Core (= 5.2.3)
- SDWebImage/Core (5.2.3)
- SDWebImage (5.2.2):
- SDWebImage/Core (= 5.2.2)
- SDWebImage/Core (5.2.2)
- SDWebImageSwiftUI (0.3.1):
- SDWebImage (~> 5.1)
- SDWebImageWebPCoder (0.2.5):
Expand All @@ -22,7 +22,7 @@ DEPENDENCIES:
- SDWebImageWebPCoder

SPEC REPOS:
trunk:
https://github.com/cocoapods/specs.git:
- libwebp
- SDWebImage
- SDWebImageWebPCoder
Expand All @@ -33,10 +33,10 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
libwebp: 057912d6d0abfb6357d8bb05c0ea470301f5d61e
SDWebImage: 46a7f73228f84ce80990c786e4372cf4db5875ce
SDWebImage: 5fcdb02cc35e05fc35791ec514b191d27189f872
SDWebImageSwiftUI: 1b67183dd2ef0321b2ccf578775de8e47eaceb77
SDWebImageWebPCoder: 947093edd1349d820c40afbd9f42acb6cdecd987

PODFILE CHECKSUM: 3fb06a5173225e197f3a4bf2be7e5586a693257a

COCOAPODS: 1.8.3
COCOAPODS: 1.7.5
3 changes: 3 additions & 0 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 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
36 changes: 36 additions & 0 deletions SDWebImageSwiftUI.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@
32C43E3322FD5DF400BE87F5 /* SDWebImageSwiftUI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32C43E3122FD5DE100BE87F5 /* SDWebImageSwiftUI.swift */; };
32C43E3422FD5DF400BE87F5 /* SDWebImageSwiftUI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32C43E3122FD5DE100BE87F5 /* SDWebImageSwiftUI.swift */; };
32C43E3522FD5DF400BE87F5 /* SDWebImageSwiftUI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32C43E3122FD5DE100BE87F5 /* SDWebImageSwiftUI.swift */; };
32D9204E2349DBFC00C9CBE9 /* SDAnimatedImageInterface.h in Headers */ = {isa = PBXBuildFile; fileRef = 32D9204C2349DBFC00C9CBE9 /* SDAnimatedImageInterface.h */; settings = {ATTRIBUTES = (Public, ); }; };
32D9204F2349DBFC00C9CBE9 /* SDAnimatedImageInterface.h in Headers */ = {isa = PBXBuildFile; fileRef = 32D9204C2349DBFC00C9CBE9 /* SDAnimatedImageInterface.h */; settings = {ATTRIBUTES = (Public, ); }; };
32D920502349DBFC00C9CBE9 /* SDAnimatedImageInterface.h in Headers */ = {isa = PBXBuildFile; fileRef = 32D9204C2349DBFC00C9CBE9 /* SDAnimatedImageInterface.h */; settings = {ATTRIBUTES = (Public, ); }; };
32D920512349DBFC00C9CBE9 /* SDAnimatedImageInterface.h in Headers */ = {isa = PBXBuildFile; fileRef = 32D9204C2349DBFC00C9CBE9 /* SDAnimatedImageInterface.h */; settings = {ATTRIBUTES = (Public, ); }; };
32D920522349DBFC00C9CBE9 /* SDAnimatedImageInterface.m in Sources */ = {isa = PBXBuildFile; fileRef = 32D9204D2349DBFC00C9CBE9 /* SDAnimatedImageInterface.m */; };
32D920532349DBFC00C9CBE9 /* SDAnimatedImageInterface.m in Sources */ = {isa = PBXBuildFile; fileRef = 32D9204D2349DBFC00C9CBE9 /* SDAnimatedImageInterface.m */; };
32D920542349DBFC00C9CBE9 /* SDAnimatedImageInterface.m in Sources */ = {isa = PBXBuildFile; fileRef = 32D9204D2349DBFC00C9CBE9 /* SDAnimatedImageInterface.m */; };
32D920552349DBFC00C9CBE9 /* SDAnimatedImageInterface.m in Sources */ = {isa = PBXBuildFile; fileRef = 32D9204D2349DBFC00C9CBE9 /* SDAnimatedImageInterface.m */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
Expand Down Expand Up @@ -104,6 +112,8 @@
32C43E2922FD586200BE87F5 /* SDWebImage.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SDWebImage.framework; path = Carthage/Build/tvOS/SDWebImage.framework; sourceTree = "<group>"; };
32C43E2D22FD586E00BE87F5 /* SDWebImage.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SDWebImage.framework; path = Carthage/Build/watchOS/SDWebImage.framework; sourceTree = "<group>"; };
32C43E3122FD5DE100BE87F5 /* SDWebImageSwiftUI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SDWebImageSwiftUI.swift; sourceTree = "<group>"; };
32D9204C2349DBFC00C9CBE9 /* SDAnimatedImageInterface.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SDAnimatedImageInterface.h; sourceTree = "<group>"; };
32D9204D2349DBFC00C9CBE9 /* SDAnimatedImageInterface.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SDAnimatedImageInterface.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -180,6 +190,8 @@
32C43DDF22FD54C600BE87F5 /* AnimatedImage.swift */,
32C43E3122FD5DE100BE87F5 /* SDWebImageSwiftUI.swift */,
326E480923431C0F00C633E9 /* ImageViewWrapper.swift */,
32D9204C2349DBFC00C9CBE9 /* SDAnimatedImageInterface.h */,
32D9204D2349DBFC00C9CBE9 /* SDAnimatedImageInterface.m */,
);
path = Classes;
sourceTree = "<group>";
Expand All @@ -202,6 +214,7 @@
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
32D9204E2349DBFC00C9CBE9 /* SDAnimatedImageInterface.h in Headers */,
32C43DE622FD54CD00BE87F5 /* SDWebImageSwiftUI.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -210,6 +223,7 @@
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
32D9204F2349DBFC00C9CBE9 /* SDAnimatedImageInterface.h in Headers */,
32C43E2222FD583A00BE87F5 /* SDWebImageSwiftUI.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -218,6 +232,7 @@
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
32D920502349DBFC00C9CBE9 /* SDAnimatedImageInterface.h in Headers */,
32C43E2322FD583B00BE87F5 /* SDWebImageSwiftUI.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -226,6 +241,7 @@
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
32D920512349DBFC00C9CBE9 /* SDAnimatedImageInterface.h in Headers */,
32C43E2422FD583C00BE87F5 /* SDWebImageSwiftUI.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -320,15 +336,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 +414,7 @@
326E480A23431C0F00C633E9 /* ImageViewWrapper.swift in Sources */,
32C43E1622FD583700BE87F5 /* ImageManager.swift in Sources */,
32C43E1822FD583700BE87F5 /* AnimatedImage.swift in Sources */,
32D920522349DBFC00C9CBE9 /* SDAnimatedImageInterface.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -406,6 +427,7 @@
326E480B23431C0F00C633E9 /* ImageViewWrapper.swift in Sources */,
32C43E1922FD583700BE87F5 /* ImageManager.swift in Sources */,
32C43E1B22FD583700BE87F5 /* AnimatedImage.swift in Sources */,
32D920532349DBFC00C9CBE9 /* SDAnimatedImageInterface.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -418,6 +440,7 @@
326E480C23431C0F00C633E9 /* ImageViewWrapper.swift in Sources */,
32C43E1C22FD583800BE87F5 /* ImageManager.swift in Sources */,
32C43E1E22FD583800BE87F5 /* AnimatedImage.swift in Sources */,
32D920542349DBFC00C9CBE9 /* SDAnimatedImageInterface.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -430,6 +453,7 @@
326E480D23431C0F00C633E9 /* ImageViewWrapper.swift in Sources */,
32C43E1F22FD583800BE87F5 /* ImageManager.swift in Sources */,
32C43E2122FD583800BE87F5 /* AnimatedImage.swift in Sources */,
32D920552349DBFC00C9CBE9 /* SDAnimatedImageInterface.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -565,6 +589,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 +610,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 +619,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 +648,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 +671,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 +709,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 +730,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 +739,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 +769,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 +790,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 +800,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
33 changes: 26 additions & 7 deletions SDWebImageSwiftUI/Classes/AnimatedImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import SwiftUI
import SDWebImage

#if !os(watchOS)

// Data Binding Object
final class AnimatedImageModel : ObservableObject {
@Published var image: PlatformImage?
Expand Down Expand Up @@ -90,7 +88,7 @@ public struct AnimatedImage : PlatformViewRepresentable {
/// - Parameter isAnimating: The binding for animation control
public init(name: String, bundle: Bundle? = nil, isAnimating: Binding<Bool>) {
self._isAnimating = isAnimating
#if os(macOS)
#if os(macOS) || os(watchOS)
let image = SDAnimatedImage(named: name, in: bundle)
#else
let image = SDAnimatedImage(named: name, in: bundle, compatibleWith: nil)
Expand All @@ -117,8 +115,10 @@ public struct AnimatedImage : PlatformViewRepresentable {

#if os(macOS)
public typealias NSViewType = AnimatedImageViewWrapper
#else
#elseif os(iOS) || os(tvOS)
public typealias UIViewType = AnimatedImageViewWrapper
#elseif os(watchOS)
public typealias WKInterfaceObjectType = SDAnimatedImageInterface
#endif

#if os(macOS)
Expand All @@ -129,7 +129,7 @@ public struct AnimatedImage : PlatformViewRepresentable {
public func updateNSView(_ nsView: AnimatedImageViewWrapper, context: NSViewRepresentableContext<AnimatedImage>) {
updateView(nsView, context: context)
}
#else
#elseif os(iOS) || os(tvOS)
public func makeUIView(context: UIViewRepresentableContext<AnimatedImage>) -> AnimatedImageViewWrapper {
makeView(context: context)
}
Expand All @@ -139,6 +139,26 @@ public struct AnimatedImage : PlatformViewRepresentable {
}
#endif

#if os(watchOS)
public func makeWKInterfaceObject(context: WKInterfaceObjectRepresentableContext<AnimatedImage>) -> SDAnimatedImageInterface {
SDAnimatedImageInterface()
}

public func updateWKInterfaceObject(_ view: SDAnimatedImageInterface, context: WKInterfaceObjectRepresentableContext<AnimatedImage>) {
view.setImage(imageModel.image)
if let url = imageModel.url {
view.sd_setImage(with: url, completed: nil)
}

// if self.isAnimating {
// view.startAnimating()
// } else {
// view.stopAnimating()
// }
}
#endif

#if os(iOS) || os(tvOS) || os(macOS)
func makeView(context: PlatformViewRepresentableContext<AnimatedImage>) -> AnimatedImageViewWrapper {
AnimatedImageViewWrapper()
}
Expand Down Expand Up @@ -304,6 +324,7 @@ public struct AnimatedImage : PlatformViewRepresentable {
view.wrapped.shouldCustomLoopCount = false
}
}
#endif
}

// Layout
Expand Down Expand Up @@ -463,5 +484,3 @@ struct AnimatedImage_Previews : PreviewProvider {
}
}
#endif

#endif
Loading