Skip to content

Commit

Permalink
Merge pull request #192 from Link-MIND/fix/#191
Browse files Browse the repository at this point in the history
[Fix] #191 - 기존 링크 제목 불러오기
  • Loading branch information
mcrkgus authored Jul 7, 2024
2 parents 136210b + 1e466b0 commit df7fcad
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ final class DetailClipListCollectionViewCell: UICollectionViewCell {

// MARK: - Properties

var buttonAction: (() -> Void)?

private var toastId: Int = 0
private var isReadDimmedView: Bool = false {
didSet {
Expand Down Expand Up @@ -143,6 +145,7 @@ private extension DetailClipListCollectionViewCell {

modifiedButton.do {
$0.setImage(.icMore24, for: .normal)
$0.frame = contentView.bounds
}

dimmedView.do {
Expand All @@ -158,11 +161,14 @@ private extension DetailClipListCollectionViewCell {
}

func setupHierarchy() {
addSubviews(linkImage, clipNameLabel, linkTitleLabel, linkLabel, modifiedButton)
contentView.addSubviews(linkImage, clipNameLabel, linkTitleLabel, linkLabel, modifiedButton)
linkImage.addSubviews(dimmedView, readLabel)
}

func setupLayout() {
contentView.snp.makeConstraints {
$0.edges.equalToSuperview()
}
linkImage.snp.makeConstraints {
$0.centerY.equalToSuperview()
$0.top.leading.equalToSuperview().inset(12)
Expand Down Expand Up @@ -223,6 +229,7 @@ private extension DetailClipListCollectionViewCell {

@objc
func buttonTapped() {
buttonAction?()
detailClipListCollectionViewCellDelegate?.modifiedButtonTapped(toastId: toastId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ final class EditLinkBottomSheetView: UIView {

// MARK: - UI Components

let addClipTextField = UITextField()
let editClipTitleTextField = UITextField()
private let editClipButton = UIButton()
private let errorMessage = UILabel()
private let clearButton = UIButton()
Expand Down Expand Up @@ -80,8 +80,9 @@ final class EditLinkBottomSheetView: UIView {

extension EditLinkBottomSheetView {
func resetTextField() {
addClipTextField.text = nil
addClipTextField.becomeFirstResponder()
editClipTitleTextField.text = nil
editClipTitleTextField.becomeFirstResponder()
isButtonClicked = true
}

func changeTextField(addButton: Bool, border: Bool, error: Bool, clearButton: Bool) {
Expand All @@ -96,7 +97,8 @@ extension EditLinkBottomSheetView {
}

func setupTextField(message: String) {
addClipTextField.text = message
editClipTitleTextField.text = message
editClipTitleTextField.placeholder = message
}

func setupConfirmBottomSheetButtonAction(_ action: (() -> Void)?) {
Expand All @@ -110,7 +112,7 @@ private extension EditLinkBottomSheetView {
func setupStyle() {
backgroundColor = .toasterWhite

addClipTextField.do {
editClipTitleTextField.do {
$0.attributedPlaceholder = NSAttributedString(string: StringLiterals.Placeholder.addClip,
attributes: [.foregroundColor: UIColor.gray400,
.font: UIFont.suitRegular(size: 16)])
Expand Down Expand Up @@ -145,20 +147,20 @@ private extension EditLinkBottomSheetView {
}

func setupHierarchy() {
addSubviews(addClipTextField, editClipButton, errorMessage)
addClipTextField.addSubview(clearButton)
addSubviews(editClipTitleTextField, editClipButton, errorMessage)
editClipTitleTextField.addSubview(clearButton)
}

func setupLayout() {
addClipTextField.snp.makeConstraints {
editClipTitleTextField.snp.makeConstraints {
$0.top.equalToSuperview()
$0.leading.trailing.equalToSuperview().inset(20)
$0.height.equalTo(54)
}

errorMessage.snp.makeConstraints {
$0.top.equalTo(addClipTextField.snp.bottom).offset(6)
$0.leading.equalTo(addClipTextField)
$0.top.equalTo(editClipTitleTextField.snp.bottom).offset(6)
$0.leading.equalTo(editClipTitleTextField)
}

editClipButton.snp.makeConstraints {
Expand All @@ -175,8 +177,8 @@ private extension EditLinkBottomSheetView {
}

func setupKeyboard() {
if !addClipTextField.isFirstResponder {
addClipTextField.becomeFirstResponder()
if !editClipTitleTextField.isFirstResponder {
editClipTitleTextField.becomeFirstResponder()
}
}

Expand All @@ -192,11 +194,11 @@ private extension EditLinkBottomSheetView {

func setupTextFieldBorder() {
if isBorderColor {
addClipTextField.layer.borderColor = UIColor.toasterError.cgColor
addClipTextField.layer.borderWidth = 1.0
editClipTitleTextField.layer.borderColor = UIColor.toasterError.cgColor
editClipTitleTextField.layer.borderWidth = 1.0
} else {
addClipTextField.layer.borderColor = UIColor.clear.cgColor
addClipTextField.layer.borderWidth = 0.0
editClipTitleTextField.layer.borderColor = UIColor.clear.cgColor
editClipTitleTextField.layer.borderWidth = 0.0
}
}

Expand All @@ -221,7 +223,7 @@ private extension EditLinkBottomSheetView {
@objc
func buttonTapped() {
confirmBottomSheetViewButtonAction?()
editLinkBottomSheetViewDelegate?.dismissButtonTapped(title: addClipTextField.text ?? "")
editLinkBottomSheetViewDelegate?.dismissButtonTapped(title: editClipTitleTextField.text ?? "")
}

@objc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import SnapKit

final class DetailClipViewController: UIViewController {

var indexNumber: Int?

// MARK: - UI Properties

private let viewModel = DetailClipViewModel()
Expand Down Expand Up @@ -146,6 +148,11 @@ extension DetailClipViewController: UICollectionViewDataSource {

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: DetailClipListCollectionViewCell.className, for: indexPath) as? DetailClipListCollectionViewCell else { return UICollectionViewCell() }

cell.buttonAction = { [weak self] in
self?.buttonTappedAtIndexPath(indexPath)
}

cell.detailClipListCollectionViewCellDelegate = self
if viewModel.categoryId == 0 {
cell.configureCell(forModel: viewModel.toastList, index: indexPath.item, isClipHidden: false)
Expand All @@ -164,9 +171,9 @@ extension DetailClipViewController: UICollectionViewDataSource {
filter: DetailCategoryFilter.all)
self.editBottom.hideBottomSheet()
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
self.viewModel.segmentIndex = indexPath.item - 1
self.editLinkBottom.modalPresentationStyle = .overFullScreen
self.present(self.editLinkBottom, animated: true)
self.editLinkBottomSheetView.setupTextField(message: self.viewModel.linkTitle)
}
}
return cell
Expand All @@ -187,12 +194,17 @@ extension DetailClipViewController: UICollectionViewDataSource {
}
return headerView
}

func buttonTappedAtIndexPath(_ indexPath: IndexPath) {
self.editLinkBottomSheetView.setupTextField(message: self.viewModel.toastList.toastList[indexPath.item].title)
}
}

// MARK: - CollectionView Delegate

extension DetailClipViewController: UICollectionViewDelegate {
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
indexNumber = indexPath.item
let nextVC = LinkWebViewController()
nextVC.hidesBottomBarWhenPushed = true
nextVC.setupDataBind(linkURL: viewModel.toastList.toastList[indexPath.item].url,
Expand Down

0 comments on commit df7fcad

Please sign in to comment.