diff --git a/.github/workflows/swift.yml b/.github/workflows/swift.yml new file mode 100644 index 0000000..5dbdb4f --- /dev/null +++ b/.github/workflows/swift.yml @@ -0,0 +1,19 @@ +name: Swift + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: macos-latest + + steps: + - uses: actions/checkout@v2 + - name: Build + run: swift build -v + - name: Run tests + run: swift test -v diff --git a/InAppNotify/InAppNotify.swift b/InAppNotify/InAppNotify.swift index adb827f..674010d 100644 --- a/InAppNotify/InAppNotify.swift +++ b/InAppNotify/InAppNotify.swift @@ -8,6 +8,9 @@ import Foundation +let imageCache = NSCache() + + public class InAppNotify{ /// Notify current dislayed @@ -17,6 +20,8 @@ public class InAppNotify{ public static var theme:Theme = Themes.dark + + /// Function to show notify /// /// - Parameters: @@ -202,12 +207,13 @@ public struct NotificationSize { // MARK: - UIImageView extension UIImageView{ - + /// Set an image in UIImageView from remote URL /// /// - Parameter url: url of the image func setImageFromURL(stringImageUrl url: String){ + //Placeholder image image = #imageLiteral(resourceName: "user_blank") @@ -216,12 +222,23 @@ extension UIImageView{ if let url = URL(string: url) { do{ - let data = try Data.init(contentsOf: url) - - //Set image in the main thread - DispatchQueue.main.async { - self.image = UIImage(data: data) + //get from cache + if let cachedImage = imageCache.object(forKey: url.absoluteString as NSString) { + //Set image in the main thread + DispatchQueue.main.async { + self.image = cachedImage + } + + }else{ + let data = try Data.init(contentsOf: url) + + //Set image in the main thread + DispatchQueue.main.async { + self.image = UIImage(data: data) + imageCache.setObject(self.image!, forKey: url.absoluteString as NSString) + } } + }catch{ diff --git a/InAppNotify/NotificationFactory.swift b/InAppNotify/NotificationFactory.swift index 8f5deda..07d4e60 100644 --- a/InAppNotify/NotificationFactory.swift +++ b/InAppNotify/NotificationFactory.swift @@ -25,7 +25,7 @@ open class NotificationFactory: UIView,UITextViewDelegate { let view = UIView() view.backgroundColor = InAppNotify.theme.backgroundColor - view.alpha = 0.8 + view.alpha = 1 view.clipsToBounds = true return view