onevcat пре 8 година
родитељ
комит
7816a2c15e

+ 68 - 69
Sources/ImageModifier.swift

@@ -110,83 +110,82 @@ public struct AnyImageModifier: ImageModifier {
 #if os(iOS) || os(tvOS) || os(watchOS)
 import UIKit
 
-    /// Modifier for setting the rendering mode of images.
-    /// Only UI-based images are supported; if a non-UI image is passed in, the
-    /// modifier will do nothing.
-    public struct RenderingModeImageModifier: ImageModifier {
-
-        /// The rendering mode to apply to the image.
-        public let renderingMode: UIImageRenderingMode
-
-        /// Initialize a `RenderingModeImageModifier`
-        ///
-        /// - parameter renderingMode: The rendering mode to apply to the image.
-        ///                            Default is .automatic
-        public init(renderingMode: UIImageRenderingMode = .automatic) {
-            self.renderingMode = renderingMode
-        }
+/// Modifier for setting the rendering mode of images.
+/// Only UI-based images are supported; if a non-UI image is passed in, the
+/// modifier will do nothing.
+public struct RenderingModeImageModifier: ImageModifier {
 
-        /// Modify an input `Image`.
-        ///
-        /// - parameter image:   Image which will be modified by `self`
-        ///
-        /// - returns: The modified image.
-        ///
-        /// - Note: See documentation of `ImageModifier` protocol for more.
-        public func modify(_ image: Image) -> Image {
-            return image.withRenderingMode(renderingMode)
-        }
-    }
+    /// The rendering mode to apply to the image.
+    public let renderingMode: UIImageRenderingMode
 
-    /// Modifier for setting the `flipsForRightToLeftLayoutDirection` property of images.
-    /// Only UI-based images are supported; if a non-UI image is passed in, the
-    /// modifier will do nothing.
-    public struct FlipsForRightToLeftLayoutDirectionImageModifier: ImageModifier {
-        /// Initialize a `FlipsForRightToLeftLayoutDirectionImageModifier`
-        ///
-        /// - Note: On versions of iOS lower than 9.0, the image will be returned
-        ///         unmodified.
-        public init() {}
-
-        /// Modify an input `Image`.
-        ///
-        /// - parameter image:   Image which will be modified by `self`
-        ///
-        /// - returns: The modified image.
-        ///
-        /// - Note: See documentation of `ImageModifier` protocol for more.
-        public func modify(_ image: Image) -> Image {
-            if #available(iOS 9.0, *) {
-                return image.imageFlippedForRightToLeftLayoutDirection()
-            } else {
-                return image
-            }
-        }
+    /// Initialize a `RenderingModeImageModifier`
+    ///
+    /// - parameter renderingMode: The rendering mode to apply to the image.
+    ///                            Default is .automatic
+    public init(renderingMode: UIImageRenderingMode = .automatic) {
+        self.renderingMode = renderingMode
     }
 
-    /// Modifier for setting the `alignmentRectInsets` property of images.
-    /// Only UI-based images are supported; if a non-UI image is passed in, the
-    /// modifier will do nothing.
-    public struct AlignmentRectInsetsImageModifier: ImageModifier {
+    /// Modify an input `Image`.
+    ///
+    /// - parameter image:   Image which will be modified by `self`
+    ///
+    /// - returns: The modified image.
+    ///
+    /// - Note: See documentation of `ImageModifier` protocol for more.
+    public func modify(_ image: Image) -> Image {
+        return image.withRenderingMode(renderingMode)
+    }
+}
 
-        /// The alignment insets to apply to the image
-        public let alignmentInsets: UIEdgeInsets
+/// Modifier for setting the `flipsForRightToLeftLayoutDirection` property of images.
+/// Only UI-based images are supported; if a non-UI image is passed in, the
+/// modifier will do nothing.
+public struct FlipsForRightToLeftLayoutDirectionImageModifier: ImageModifier {
+    /// Initialize a `FlipsForRightToLeftLayoutDirectionImageModifier`
+    ///
+    /// - Note: On versions of iOS lower than 9.0, the image will be returned
+    ///         unmodified.
+    public init() {}
 
-        /// Initialize a `AlignmentRectInsetsImageModifier`
-        public init(alignmentInsets: UIEdgeInsets) {
-            self.alignmentInsets = alignmentInsets
+    /// Modify an input `Image`.
+    ///
+    /// - parameter image:   Image which will be modified by `self`
+    ///
+    /// - returns: The modified image.
+    ///
+    /// - Note: See documentation of `ImageModifier` protocol for more.
+    public func modify(_ image: Image) -> Image {
+        if #available(iOS 9.0, *) {
+            return image.imageFlippedForRightToLeftLayoutDirection()
+        } else {
+            return image
         }
+    }
+}
 
-        /// Modify an input `Image`.
-        ///
-        /// - parameter image:   Image which will be modified by `self`
-        ///
-        /// - returns: The modified image.
-        ///
-        /// - Note: See documentation of `ImageModifier` protocol for more.
-        public func modify(_ image: Image) -> Image {
-            return image.withAlignmentRectInsets(alignmentInsets)
-        }
+/// Modifier for setting the `alignmentRectInsets` property of images.
+/// Only UI-based images are supported; if a non-UI image is passed in, the
+/// modifier will do nothing.
+public struct AlignmentRectInsetsImageModifier: ImageModifier {
+
+    /// The alignment insets to apply to the image
+    public let alignmentInsets: UIEdgeInsets
+
+    /// Initialize a `AlignmentRectInsetsImageModifier`
+    public init(alignmentInsets: UIEdgeInsets) {
+        self.alignmentInsets = alignmentInsets
     }
 
+    /// Modify an input `Image`.
+    ///
+    /// - parameter image:   Image which will be modified by `self`
+    ///
+    /// - returns: The modified image.
+    ///
+    /// - Note: See documentation of `ImageModifier` protocol for more.
+    public func modify(_ image: Image) -> Image {
+        return image.withAlignmentRectInsets(alignmentInsets)
+    }
+}
 #endif

+ 3 - 0
Tests/KingfisherTests/ImageCacheTests.swift

@@ -351,6 +351,7 @@ class ImageCacheTests: XCTestCase {
         waitForExpectations(timeout: 5, handler: nil)
     }
 
+#if os(iOS) || os(tvOS) || os(watchOS)
     func testGettingMemoryCachedImageCouldBeModified() {
 
         let expectation = self.expectation(description: "wait for retrieving image")
@@ -359,6 +360,7 @@ class ImageCacheTests: XCTestCase {
         let modifier = AnyImageModifier { image in
             modifierCalled = true
             return image.withRenderingMode(.alwaysTemplate)
+            image.isTemplate = true
         }
 
         cache.store(testImage, original: testImageData as Data?, forKey: testKeys[0]) {
@@ -392,6 +394,7 @@ class ImageCacheTests: XCTestCase {
         }
         waitForExpectations(timeout: 5, handler: nil)
     }
+#endif
 
     // MARK: - Helper
     func storeMultipleImages(_ completionHandler:@escaping ()->()) {

+ 2 - 0
Tests/KingfisherTests/ImageDownloaderTests.swift

@@ -401,6 +401,7 @@ class ImageDownloaderTests: XCTestCase {
         waitForExpectations(timeout: 5, handler: nil)
     }
 
+#if os(iOS) || os(tvOS) || os(watchOS)
     func testDownloadedImageCouldBeModified() {
         let expectation = self.expectation(description: "wait for downloading image")
 
@@ -424,6 +425,7 @@ class ImageDownloaderTests: XCTestCase {
 
         waitForExpectations(timeout: 5, handler: nil)
     }
+#endif
 }
 
 extension ImageDownloaderTests: ImageDownloaderDelegate {

+ 2 - 0
Tests/KingfisherTests/KingfisherManagerTests.swift

@@ -549,6 +549,7 @@ class KingfisherManagerTests: XCTestCase {
         waitForExpectations(timeout: 5, handler: nil)
     }
 
+#if os(iOS) || os(tvOS) || os(watchOS)
     func testShouldApplyImageModifierWhenDownload() {
         let expectation = self.expectation(description: "waiting for downloading and cache")
 
@@ -615,6 +616,7 @@ class KingfisherManagerTests: XCTestCase {
         }
         waitForExpectations(timeout: 5, handler: nil)
     }
+#endif
 }
 
 class SimpleProcessor: ImageProcessor {