Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

๐Ÿ”€ :: (#1244) PDF ๋กœ๋“œ ์‹คํŒจ ์ฒ˜๋ฆฌ #1256

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
//

import DesignSystem
import LogManager
import NVActivityIndicatorView
import PDFKit
import RxCocoa
import RxSwift
import SnapKit
import UIKit
import Utility

Expand Down Expand Up @@ -47,16 +49,17 @@ public final class ContractViewController: UIViewController, ViewControllerFromS
@IBOutlet weak var activityIndicator: NVActivityIndicatorView!

var type: ContractType = .privacy
var disposeBag = DisposeBag()
private let disposeBag = DisposeBag()

deinit {
LogManager.printDebug("โŒ \(Self.self) deinit")
}

override public func viewDidLoad() {
super.viewDidLoad()
configureUI()
bindRx()
}

deinit {
DEBUG_LOG("โŒ \(Self.self) deinit")
loadPDF()
}

public static func viewController(type: ContractType) -> ContractViewController {
Expand All @@ -66,8 +69,8 @@ public final class ContractViewController: UIViewController, ViewControllerFromS
}
}

extension ContractViewController {
private func bindRx() {
private extension ContractViewController {
func bindRx() {
Observable.merge(
closeButton.rx.tap.map { _ in () },
confirmButton.rx.tap.map { _ in () }
Expand All @@ -79,19 +82,9 @@ extension ContractViewController {
.disposed(by: disposeBag)
}

private func loadPdf(document: PDFDocument) {
let pdfView = PDFView(frame: self.fakeView.bounds)
pdfView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
pdfView.autoScales = true
pdfView.displayMode = .singlePageContinuous
pdfView.displayDirection = .vertical
pdfView.document = document
self.fakeView.addSubview(pdfView)
activityIndicator.stopAnimating()
}

private func configureUI() {
self.navigationController?.setNavigationBarHidden(true, animated: false)
func configureUI() {
navigationController?.setNavigationBarHidden(true, animated: false)
closeButton.setImage(DesignSystemAsset.Navigation.crossClose.image, for: .normal)

activityIndicator.type = .circleStrokeSpin
activityIndicator.color = DesignSystemAsset.PrimaryColor.point.color
Expand All @@ -104,22 +97,52 @@ extension ContractViewController {
string: "ํ™•์ธ",
attributes: [
.font: DesignSystemFontFamily.Pretendard.medium.font(size: 18),
.foregroundColor: DesignSystemAsset.GrayColor.gray25.color,
.foregroundColor: DesignSystemAsset.BlueGrayColor.gray25.color,
.kern: -0.5
]
), for: .normal)
closeButton.setImage(DesignSystemAsset.Navigation.crossClose.image, for: .normal)

titleLabel.text = type.title
titleLabel.textColor = DesignSystemAsset.GrayColor.gray900.color
titleLabel.textColor = DesignSystemAsset.BlueGrayColor.gray900.color
titleLabel.font = DesignSystemFontFamily.Pretendard.medium.font(size: 16)
titleLabel.setTextWithAttributes(kernValue: -0.5)
}
}

private extension ContractViewController {
func loadPDF() {
DispatchQueue.global(qos: .default).async {
if let url = URL(string: self.type.url), let document = PDFDocument(url: url) {
DispatchQueue.main.async {
self.loadPdf(document: document) // UI ์ž‘์—…์ด๋ผ main ์Šค๋ ˆ๋“œ๋กœ
}
guard let url = URL(string: self.type.url),
let document = PDFDocument(url: url) else {
self.loadFailPDF()
return
}
self.configurePDF(document: document)
}
}

func configurePDF(document: PDFDocument) {
DispatchQueue.main.async {
let pdfView = PDFView(frame: self.fakeView.bounds)
pdfView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
pdfView.autoScales = true
pdfView.displayMode = .singlePageContinuous
pdfView.displayDirection = .vertical
pdfView.document = document
self.fakeView.addSubview(pdfView)
self.activityIndicator.stopAnimating()
}
}

func loadFailPDF() {
DispatchQueue.main.async {
self.activityIndicator.stopAnimating()
self.fakeView.backgroundColor = DesignSystemAsset.BlueGrayColor.gray100.color
let warningView = WMWarningView(text: "ํŒŒ์ผ์„ ๋ถˆ๋Ÿฌ์˜ค๋Š” ๋ฐ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.")
self.view.addSubview(warningView)
warningView.snp.makeConstraints {
$0.top.equalTo(self.view.frame.height / 3)
$0.centerX.equalToSuperview()
}
}
}
Expand Down
Loading