161 lines
5.1 KiB
Swift
161 lines
5.1 KiB
Swift
//
|
|
// NRNovelReadMoreView.swift
|
|
// ReaderHive
|
|
//
|
|
// Created by 长沙鸿瑶 on 2025/11/28.
|
|
//
|
|
|
|
import UIKit
|
|
import HWPanModal
|
|
import SnapKit
|
|
|
|
class NRNovelReadMoreView: NRPanModalContentView {
|
|
|
|
weak var viewModel: NRNovelReadViewModel? {
|
|
didSet {
|
|
let progress = CGFloat(viewModel?.currentPageIndexPath.section ?? 0) / CGFloat(viewModel?.chapterCatalogList.count ?? 0)
|
|
self.progressView.progress = progress
|
|
}
|
|
}
|
|
|
|
lazy var catalogButton: UIButton = {
|
|
let button = self.createButton(title: "Catalog".localized, icon: UIImage(named: "catalog_icon_01"))
|
|
return button
|
|
}()
|
|
|
|
lazy var nightButton: UIButton = {
|
|
let button = self.createButton(title: "Night".localized, icon: UIImage(named: "night_icon_01"))
|
|
return button
|
|
}()
|
|
|
|
lazy var settingsButton: UIButton = {
|
|
let button = self.createButton(title: "Settings".localized, icon: UIImage(named: "settings_icon_01"))
|
|
button.addAction(UIAction(handler: { [weak self] _ in
|
|
guard let self = self else { return }
|
|
self.dismiss(animated: true) { }
|
|
|
|
self.viewModel?.showSettingView()
|
|
}), for: .touchUpInside)
|
|
return button
|
|
}()
|
|
|
|
lazy var stackView: UIStackView = {
|
|
let view = UIStackView(arrangedSubviews: [catalogButton, nightButton, settingsButton])
|
|
view.axis = .horizontal
|
|
view.distribution = .equalSpacing
|
|
return view
|
|
}()
|
|
|
|
lazy var prevLabel: UILabel = {
|
|
let label = UILabel()
|
|
label.font = .font(ofSize: 12, weight: .regular)
|
|
label.textColor = .black
|
|
label.text = "Prev".localized
|
|
label.setContentHuggingPriority(.required, for: .horizontal)
|
|
label.setContentCompressionResistancePriority(.required, for: .horizontal)
|
|
return label
|
|
}()
|
|
|
|
lazy var nextLabel: UILabel = {
|
|
let label = UILabel()
|
|
label.font = .font(ofSize: 12, weight: .regular)
|
|
label.textColor = .black
|
|
label.text = "Next".localized
|
|
label.setContentHuggingPriority(.required, for: .horizontal)
|
|
label.setContentCompressionResistancePriority(.required, for: .horizontal)
|
|
return label
|
|
}()
|
|
|
|
lazy var progressView: NRProgressView = {
|
|
let view = NRProgressView()
|
|
view.thumbImage = UIImage(named: "Progress-handle")
|
|
view.insets = .init(top: 6, left: 0, bottom: 6, right: 0)
|
|
view.panFinish = { [weak self] progress in
|
|
self?.progressView.progress = progress
|
|
let totalCount = self?.viewModel?.chapterCatalogList.count ?? 0
|
|
let index = Int(floor(CGFloat(totalCount) * progress))
|
|
self?.viewModel?.skip(chapterIndex: index)
|
|
}
|
|
return view
|
|
}()
|
|
|
|
override init(frame: CGRect) {
|
|
super.init(frame: frame)
|
|
contentHeight = UIScreen.safeBottom + 105
|
|
|
|
backgroundColor = .white
|
|
|
|
nr_setupUI()
|
|
}
|
|
|
|
@MainActor required init?(coder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
override func backgroundConfig() -> HWBackgroundConfig {
|
|
let config = HWBackgroundConfig()
|
|
config.backgroundAlpha = 0
|
|
return config
|
|
}
|
|
|
|
override func cornerRadius() -> CGFloat {
|
|
return 0
|
|
}
|
|
|
|
private func createButton(title: String, icon: UIImage?) -> UIButton {
|
|
var configuration = UIButton.Configuration.plain()
|
|
configuration.contentInsets = .zero
|
|
configuration.image = icon
|
|
configuration.imagePadding = 2
|
|
configuration.imagePlacement = .top
|
|
configuration.attributedTitle = AttributedString(title, attributes: AttributeContainer([
|
|
.font : UIFont.font(ofSize: 10, weight: .regular),
|
|
.foregroundColor : UIColor.black
|
|
]))
|
|
|
|
let button = UIButton(configuration: configuration)
|
|
button.snp.makeConstraints { make in
|
|
make.width.equalTo(72)
|
|
}
|
|
|
|
return button
|
|
}
|
|
|
|
}
|
|
|
|
extension NRNovelReadMoreView {
|
|
|
|
private func nr_setupUI() {
|
|
addSubview(stackView)
|
|
addSubview(progressView)
|
|
addSubview(prevLabel)
|
|
addSubview(nextLabel)
|
|
|
|
stackView.snp.makeConstraints { make in
|
|
make.left.equalToSuperview().offset(28)
|
|
make.centerX.equalToSuperview()
|
|
make.top.equalToSuperview().offset(48)
|
|
make.height.equalTo(56)
|
|
}
|
|
|
|
progressView.snp.makeConstraints { make in
|
|
make.top.equalToSuperview().offset(8)
|
|
make.centerX.equalToSuperview()
|
|
make.right.lessThanOrEqualTo(nextLabel.snp.left).offset(0)
|
|
make.left.greaterThanOrEqualTo(prevLabel.snp.right).offset(0)
|
|
}
|
|
|
|
prevLabel.snp.makeConstraints { make in
|
|
make.centerY.equalTo(progressView)
|
|
make.left.equalToSuperview().offset(20)
|
|
}
|
|
|
|
nextLabel.snp.makeConstraints { make in
|
|
make.centerY.equalTo(progressView)
|
|
make.right.equalToSuperview().offset(-20)
|
|
}
|
|
}
|
|
|
|
}
|
|
|