-
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.
- Loading branch information
Showing
8 changed files
with
269 additions
and
16 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
57 changes: 57 additions & 0 deletions
57
LionHeart-iOS/LionHeart-iOS/Scenes/ArticleDetail/TestComponent.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,57 @@ | ||
// | ||
// TestComponent.swift | ||
// LionHeart-iOS | ||
// | ||
// Created by 김민재 on 1/16/24. | ||
// | ||
|
||
import UIKit | ||
|
||
import Carbon | ||
import SnapKit | ||
|
||
struct HelloItem: IdentifiableComponent { | ||
var title: String | ||
var id: String { | ||
return title | ||
} | ||
|
||
func render(in content: HelloContent) { | ||
content.nameLabel.text = title | ||
} | ||
|
||
func renderContent() -> HelloContent { | ||
return .init() | ||
} | ||
|
||
func referenceSize(in bounds: CGRect) -> CGSize? { | ||
return .init(width: UIScreen.main.bounds.width, height: 200) | ||
} | ||
} | ||
|
||
|
||
final class HelloContent: UIView { | ||
|
||
let nameLabel: UILabel = { | ||
let label = UILabel() | ||
label.font = .systemFont(ofSize: 20) | ||
return label | ||
}() | ||
|
||
init() { | ||
super.init(frame: .zero) | ||
setUI() | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
private func setUI() { | ||
addSubview(nameLabel) | ||
nameLabel.snp.makeConstraints { make in | ||
make.top.bottom.equalToSuperview() | ||
make.leading.trailing.equalToSuperview().inset(20) | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
LionHeart-iOS/LionHeart-iOS/Scenes/ArticleDetail/ThumbnailCellAdaptor.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,8 @@ | ||
// | ||
// ThumbnailCellAdaptor.swift | ||
// LionHeart-iOS | ||
// | ||
// Created by 김민재 on 1/16/24. | ||
// | ||
|
||
import Foundation |
34 changes: 34 additions & 0 deletions
34
LionHeart-iOS/LionHeart-iOS/Scenes/ArticleDetail/ThumbnailComponent.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,34 @@ | ||
// | ||
// ThumbnailComponent.swift | ||
// LionHeart-iOS | ||
// | ||
// Created by 김민재 on 1/16/24. | ||
// | ||
|
||
import UIKit | ||
import Carbon | ||
|
||
|
||
struct ThumbnailComponent: IdentifiableComponent { | ||
|
||
var model: ArticleBlockData | ||
|
||
var onSelect: (() -> Void) | ||
|
||
var id: String { | ||
ThumbnailContent.className | ||
} | ||
|
||
func renderContent() -> ThumbnailContent { | ||
return .init() | ||
} | ||
|
||
func render(in content: ThumbnailContent) { | ||
content.onSelect = onSelect | ||
content.configureCell(model) | ||
} | ||
|
||
func contentDidEndDisplay(_ content: ThumbnailContent) { | ||
content.thumbnailImageView.image = nil | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
LionHeart-iOS/LionHeart-iOS/Scenes/ArticleDetail/ThumbnailContent.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,80 @@ | ||
// | ||
// ThumbnailContent.swift | ||
// LionHeart-iOS | ||
// | ||
// Created by 김민재 on 1/16/24. | ||
// | ||
|
||
import UIKit | ||
|
||
|
||
final class ThumbnailContent: UIView { | ||
enum Size { | ||
static let thumbnailWidthHeightRatio: CGFloat = 224 / 375 | ||
} | ||
|
||
var onSelect: (() -> Void)? | ||
|
||
private let gradientImageView = LHImageView(in: ImageLiterals.Curriculum.gradient, contentMode: .scaleAspectFill) | ||
let thumbnailImageView = LHImageView(contentMode: .scaleAspectFill) | ||
private let imageCaptionLabel = LHLabel(type: .body4, color: .gray500) | ||
private lazy var bookMarkButton = LHToggleImageButton(normal: ImageLiterals.BookMark.inactiveBookmarkBig, select: ImageLiterals.BookMark.activeBookmarkBig) | ||
|
||
override init(frame: CGRect) { | ||
super.init(frame: frame) | ||
setHierarchy() | ||
setLayout() | ||
setAddTarget() | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
private func setHierarchy() { | ||
self.addSubviews(thumbnailImageView, imageCaptionLabel, bookMarkButton) | ||
thumbnailImageView.addSubview(gradientImageView) | ||
} | ||
|
||
private func setLayout() { | ||
thumbnailImageView.snp.makeConstraints { make in | ||
make.top.leading.trailing.equalToSuperview() | ||
make.width.equalTo(Constant.Screen.width) | ||
make.height.equalTo(thumbnailImageView.snp.width).multipliedBy(Size.thumbnailWidthHeightRatio) | ||
} | ||
|
||
gradientImageView.snp.makeConstraints { make in | ||
make.top.equalToSuperview() | ||
make.leading.trailing.equalToSuperview() | ||
} | ||
|
||
imageCaptionLabel.snp.makeConstraints { make in | ||
make.top.equalTo(thumbnailImageView.snp.bottom).offset(12) | ||
make.centerX.equalTo(thumbnailImageView) | ||
make.bottom.equalToSuperview().inset(22) | ||
} | ||
|
||
bookMarkButton.snp.makeConstraints{ | ||
$0.top.equalToSuperview().inset(10) | ||
$0.trailing.equalToSuperview().inset(10) | ||
} | ||
} | ||
|
||
private func setAddTarget() { | ||
bookMarkButton.addButtonAction { [weak self] _ in | ||
guard let self else { return } | ||
self.bookMarkButton.isSelected.toggle() | ||
onSelect?() | ||
} | ||
} | ||
|
||
func configureCell(_ model: ArticleBlockData?) { | ||
guard let model else { return } | ||
Task { | ||
let image = try await LHKingFisherService.fetchImage(with: model.content) | ||
thumbnailImageView.image = image | ||
} | ||
imageCaptionLabel.text = model.caption | ||
} | ||
|
||
} |
Oops, something went wrong.