Skip to content

Commit

Permalink
fix: Simple Icons 이미지 캐싱되지 않는 현상 및 아이콘 무한로딩 증상 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
heonha committed Dec 2, 2023
1 parent c5138a4 commit 363b113
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 34 deletions.
2 changes: 1 addition & 1 deletion koget.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2017,7 +2017,7 @@
repositoryURL = "https://github.com/firebase/firebase-ios-sdk.git";
requirement = {
kind = upToNextMinorVersion;
minimumVersion = 10.11.0;
minimumVersion = 10.18.0;
};
};
/* End XCRemoteSwiftPackageReference section */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
"version" : "1.2022062300.0"
}
},
{
"identity" : "app-check",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/app-check.git",
"state" : {
"revision" : "5746b2d35c91c50581590ed97abe4c06b5037274",
"version" : "10.18.0"
}
},
{
"identity" : "cocoalumberjack",
"kind" : "remoteSourceControl",
Expand All @@ -23,17 +32,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/firebase/firebase-ios-sdk.git",
"state" : {
"revision" : "e700a8f40c87c31cab7984875fcc1225d96b25bf",
"version" : "10.11.0"
"revision" : "5de0369ee79ad096c164eb3afeb7921d92a43b58",
"version" : "10.18.0"
}
},
{
"identity" : "googleappmeasurement",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/GoogleAppMeasurement.git",
"state" : {
"revision" : "62e3a0c09a75e2637f5300d46f05a59313f1c286",
"version" : "10.11.0"
"revision" : "6b332152355c372ace9966d8ee76ed191f97025e",
"version" : "10.17.0"
}
},
{
Expand All @@ -50,17 +59,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/GoogleUtilities.git",
"state" : {
"revision" : "0543562f85620b5b7c510c6bcbef75b562a5127b",
"version" : "7.11.0"
"revision" : "bc27fad73504f3d4af235de451f02ee22586ebd3",
"version" : "7.12.1"
}
},
{
"identity" : "grpc-binary",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/grpc-binary.git",
"state" : {
"revision" : "f1b366129d1125be7db83247e003fc333104b569",
"version" : "1.50.2"
"revision" : "a673bc2937fbe886dd1f99c401b01b6d977a9c98",
"version" : "1.49.1"
}
},
{
Expand All @@ -72,6 +81,15 @@
"version" : "3.1.0"
}
},
{
"identity" : "interop-ios-for-google-sdks",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/interop-ios-for-google-sdks.git",
"state" : {
"revision" : "2d12673670417654f08f5f90fdd62926dc3a2648",
"version" : "100.0.0"
}
},
{
"identity" : "kingfisher",
"kind" : "remoteSourceControl",
Expand Down Expand Up @@ -113,8 +131,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/promises.git",
"state" : {
"revision" : "ec957ccddbcc710ccc64c9dcbd4c7006fcf8b73a",
"version" : "2.2.0"
"revision" : "e70e889c0196c76d22759eb50d6a0270ca9f1d9e",
"version" : "2.3.1"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion koget/Extensions/Foundation/String+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation
extension String {

func replaceOnlyAlphabetAndNumbers() -> String {
return self.replacingOccurrences(of: "[^a-zA-Z0-9]", with: "").replacingOccurrences(of: " ", with: "")
return self.replacingOccurrences(of: "[^a-zA-Z0-9.]", with: "", options: [.regularExpression, .caseInsensitive]).replacingOccurrences(of: " ", with: "")
}

func deletingPrefix(_ prefix: String) -> String {
Expand Down
7 changes: 6 additions & 1 deletion koget/Services/FBService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ class FBService {
let endpoint = "/deeplink/deeplink.json"

networkService
.request(method: .GET, headerType: .applicationJson, urlString: self.fbStorageBaseUrl, endPoint: endpoint, parameters: [:], returnType: DeepLinkAPIResponse.self)
.request(method: .GET,
headerType: .applicationJson,
urlString: self.fbStorageBaseUrl,
endPoint: endpoint, parameters: [:],
returnType: DeepLinkAPIResponse.self)

.receive(on: DispatchQueue.main)
.sink { completion in
switch completion {
Expand Down
2 changes: 1 addition & 1 deletion koget/UI/IconGrids/IconGridView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ extension IconGridView {
}

case .simpleIcons:
ForEach($viewModel.iconNames.wrappedValue, id: \.self) { name in
ForEach(viewModel.iconNames, id: \.self) { name in
simpleIconCell(name: name)
.onAppear {
print("\(self.cellCount = CGFloat(viewModel.iconNames.count))")
Expand Down
23 changes: 17 additions & 6 deletions koget/UI/IconGrids/IconGridViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,12 @@ extension IconGridViewModel {
size: CGSize(width: 192, height: 192),
completion: { image in
if let image = image {
target.widgetIcon = image
if let resizedImage = image.addClearBackground() {
target.widgetIcon = resizedImage
}
} else {
target.widgetIcon = UIImage(systemName: "autostartstop.trianglebadge.exclamationmark")?.withTintColor(.systemYellow, renderingMode: .alwaysOriginal)
target.widgetIcon = UIImage(systemName: "autostartstop.trianglebadge.exclamationmark")?
.withTintColor(.systemYellow, renderingMode: .alwaysOriginal)
}
})
}
Expand All @@ -139,7 +142,12 @@ extension IconGridViewModel {
if simpleIconNameIndex == devidedNames.endIndex { return }
if !searchText.isEmpty { return }
let names = self.devidedNames[self.simpleIconNameIndex]

.compactMap { string in
string.lowercased().replaceOnlyAlphabetAndNumbers()
}



self.iconNames += names
self.simpleIconNameIndex += 1

Expand Down Expand Up @@ -177,9 +185,9 @@ extension IconGridViewModel {

// MARK: - ImageProcessing
extension IconGridViewModel {

private func getIconNames() {
let urlString = "https://raw.githubusercontent.com/simple-icons/simple-icons/develop/_data/simple-icons.json"
let urlString = "https://storage.googleapis.com/koget-253ee.appspot.com/simple-icons.json"

guard let url = URL(string: urlString) else {
print("Invalid URL")
Expand All @@ -200,8 +208,11 @@ extension IconGridViewModel {
break
}
}, receiveValue: { [weak self] receivedIcons in
let names = receivedIcons.compactMap { $0.title.lowercased().replaceOnlyAlphabetAndNumbers() }
let names = receivedIcons
.compactMap { $0.title }
.shuffled()
print("NAME: \(names)")

self?.allNames = names
self?.devidedNames = names.chunked(into: 50)
})
Expand Down
24 changes: 10 additions & 14 deletions koget/Utility/ImageLoader/ImageLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,54 +13,50 @@ class ImageLoader: ObservableObject {
@Published var image: UIImage?
private let url: URL?

private var cancellables: AnyCancellable?
private var cancellables = Set<AnyCancellable>()

init(url: URL?) {
self.url = url
}

deinit {
cancel()
cancellables = .init()
}

func load() {
cancellables = URLSession.shared.dataTaskPublisher(for: url!)
URLSession.shared.dataTaskPublisher(for: url!)
.map { UIImage(data: $0.data) }
.replaceError(with: nil)
.receive(on: DispatchQueue.main)
.sink { [weak self] in self?.image = $0; print("imageProcessing") }
.store(in: &cancellables)
}

func loadSVG() {
let size = CGSize(width: 64, height: 64)

guard let url = self.url else { return }

self.cancellables = URLSession.shared
.dataTaskPublisher(for: url)
URLSession.shared.dataTaskPublisher(for: url)
.compactMap { (data: $0.data, response: $0.response as? HTTPURLResponse) }
.filter{ $0.response?.statusCode == 200 }
.compactMap { SVGKImage(data: $0.data) }
.compactMap { svgImage in
svgImage.size = size
return svgImage.uiImage
}
.receive(on: RunLoop.main)
.receive(on: DispatchQueue.main)
.sink(receiveCompletion: { completion in
switch completion {
case .finished:
break
return
case .failure(let error):
print(error.localizedDescription)
print(error)
break
}
}, receiveValue: { [weak self] uiImage in
if let resizedImage = uiImage.addClearBackground() {
print("이미지 로드됨 \(url)")
self?.image = resizedImage
}
self?.image = uiImage
})
.store(in: &cancellables)
}

func cancel() {}
}

0 comments on commit 363b113

Please sign in to comment.