-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
feat: 모든 탭 열어놓기
- Loading branch information
Showing
6 changed files
with
121 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// | ||
// PreloadedWebView.swift | ||
// iBox | ||
// | ||
// Created by 이지현 on 1/18/24. | ||
// | ||
|
||
import UIKit | ||
import WebKit | ||
|
||
import SnapKit | ||
|
||
class PreloadedWebView: BaseView { | ||
var selectedWebsite: String? { | ||
didSet { | ||
getWebView() | ||
} | ||
} | ||
|
||
private var webView: WKWebView? | ||
|
||
override init(frame: CGRect) { | ||
super.init(frame: frame) | ||
backgroundColor = .systemBackground | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
private func getWebView() { | ||
guard let selectedWebsite else { return } | ||
webView = WebViewPreloader.shared.getWebView(for: URL(string: selectedWebsite)!) | ||
guard let webView else { return } | ||
addSubview(webView) | ||
webView.snp.makeConstraints { make in | ||
make.edges.equalToSuperview() | ||
} | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
iBox/Sources/Presenter/Web/PreloadedWebViewController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// | ||
// PreloadedWebViewController.swift | ||
// iBox | ||
// | ||
// Created by 이지현 on 1/18/24. | ||
// | ||
|
||
import UIKit | ||
|
||
class PreloadedWebViewController: BaseNavigationBarViewController<PreloadedWebView> { | ||
var selectedWebsite: String? | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
view.backgroundColor = .systemBackground | ||
navigationItem.largeTitleDisplayMode = .never | ||
|
||
guard let contentView = contentView as? PreloadedWebView else { return } | ||
contentView.selectedWebsite = selectedWebsite | ||
} | ||
|
||
override func viewWillDisappear(_ animated: Bool) { | ||
super.viewWillDisappear(animated) | ||
|
||
guard let selectedWebsite else { return } | ||
WebViewPreloader.shared.resetWebView(for: URL(string: selectedWebsite)!) | ||
} | ||
|
||
override func setupNavigationBar() { | ||
setNavigationBarHidden(true) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// | ||
// WebViewPreloader.swift | ||
// iBox | ||
// | ||
// Created by 이지현 on 1/18/24. | ||
// | ||
|
||
import Foundation | ||
import WebKit | ||
|
||
class WebViewPreloader { | ||
static let shared = WebViewPreloader() | ||
private var webViews: [URL: WKWebView] = [:] | ||
|
||
private init() {} | ||
|
||
func preload(urls: [URL]) { | ||
for url in urls { | ||
let webView = WKWebView() | ||
webView.load(URLRequest(url: url)) | ||
webViews[url] = webView | ||
} | ||
} | ||
|
||
func getWebView(for url: URL) -> WKWebView? { | ||
return webViews[url] | ||
} | ||
|
||
func resetWebView(for url: URL) { | ||
webViews[url]?.load(URLRequest(url: url)) | ||
} | ||
|
||
} |