Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 19 additions & 0 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
@@ -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
29 changes: 23 additions & 6 deletions InAppNotify/InAppNotify.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

import Foundation

let imageCache = NSCache<NSString, UIImage>()


public class InAppNotify{

/// Notify current dislayed
Expand All @@ -17,6 +20,8 @@ public class InAppNotify{

public static var theme:Theme = Themes.dark



/// Function to show notify
///
/// - Parameters:
Expand Down Expand Up @@ -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")

Expand All @@ -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{

Expand Down
2 changes: 1 addition & 1 deletion InAppNotify/NotificationFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down