fix: code review notes

This commit is contained in:
Nikita Semenov 2023-01-10 19:53:47 +03:00
parent 3e7307424a
commit e4c8118b6b
5 changed files with 29 additions and 9 deletions

View File

@ -23,14 +23,25 @@
import Foundation
public struct WebViewJSError: WebViewError, Codable {
public enum CodingKeys: String, CodingKey {
case contentURL
case name
case message
case lineNumber = "line"
case stackTrace = "stack"
}
public let contentURL: URL?
public let name: String?
public let message: Int?
public let message: String?
public let lineNumber: Int?
public let stackTrace: String?
public init(stringURL: String?,
name: String?,
message: Int?,
message: String?,
lineNumber: Int?,
stackTrace: String?) {
if let stringURL = stringURL {
@ -41,6 +52,7 @@ public struct WebViewJSError: WebViewError, Codable {
self.name = name
self.message = message
self.lineNumber = lineNumber
self.stackTrace = stackTrace
}
}

View File

@ -29,6 +29,10 @@ public enum WebViewErrorConstants {
"message"
}
static var errorLineNumber: String {
"line"
}
static var errorName: String {
"name"
}

View File

@ -50,16 +50,14 @@ public extension WebViewUrlInjector {
// MARK: - Helper methods
private func evaluteInjection(onWebView webView: WKWebView, injection: WebViewUrlInjection) {
let jsScript = makeJsScript(fromInjection: injection)
guard !jsScript.isEmpty else {
guard let jsScript = makeJsScript(fromInjection: injection) else {
return
}
webView.evaluateJavaScript(jsScript, completionHandler: nil)
}
private func makeJsScript(fromInjection injection: WebViewUrlInjection) -> String {
private func makeJsScript(fromInjection injection: WebViewUrlInjection) -> String? {
switch injection {
case let .css(css):
return cssJsScript(css: css)
@ -69,7 +67,11 @@ public extension WebViewUrlInjector {
.components(separatedBy: .newlines)
.joined()
return cssJsScript(css: css ?? "")
if let css = css, !css.isEmpty {
return cssJsScript(css: css)
}
return nil
case let .javaScript(script):
return script

View File

@ -58,7 +58,8 @@ open class DefaultWebViewModel: NSObject, WebViewModel {
let body = message.body as? [String: Any]
return WebViewJSError(stringURL: body?[WebViewErrorConstants.errorUrl] as? String,
name: body?[WebViewErrorConstants.errorName] as? String,
message: body?[WebViewErrorConstants.errorMessage] as? Int,
message: body?[WebViewErrorConstants.errorMessage] as? String,
lineNumber: body?[WebViewErrorConstants.errorLineNumber] as? Int,
stackTrace: body?[WebViewErrorConstants.errorStack] as? String)
}
}

View File

@ -22,7 +22,8 @@ ORDERED_PODSPECS="../TISwiftUtils/TISwiftUtils.podspec
../TIAppleMapUtils/TIAppleMapUtils.podspec
../TIGoogleMapUtils/TIGoogleMapUtils.podspec
../TIYandexMapUtils/TIYandexMapUtils.podspec
../TIEcommerce/TIEcommerce.podspec"
../TIEcommerce/TIEcommerce.podspec
../TIWebView/TIWebView.podspec"
for podspec_path in ${ORDERED_PODSPECS}; do
bundle exec pod repo push git@github.com:TouchInstinct/Podspecs ${podspec_path} --allow-warnings