Skip to content

Commit

Permalink
[Feat] #58 - 게시글 상세 버튼 action 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
yeonsu0-0 committed Jan 14, 2024
1 parent 7474325 commit 667b194
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ final class PostViewController: UIViewController {
var tabBarHeight: CGFloat = 0
private lazy var postUserNickname = postView.postNicknameLabel.text
private lazy var postDividerView = postView.horizontalDivierView
private lazy var ghostButton = postView.ghostButton
var deleteBottomsheet = DontBeBottomSheetView(singleButtonImage: ImageLiterals.Posting.btnDelete)
var transparentPopupVC = TransparentPopupViewController()
var deletePostPopupVC = CancelReplyPopupViewController()

// MARK: - UI Components

Expand Down Expand Up @@ -49,6 +53,7 @@ final class PostViewController: UIViewController {
setDelegate()
setTextFieldGesture()
setNotification()
setAddTarget()

}

Expand Down Expand Up @@ -78,6 +83,9 @@ extension PostViewController {
textFieldView.replyTextFieldLabel.text = (postUserNickname ?? "") + StringLiterals.Post.textFieldLabel

self.view.backgroundColor = .donWhite

transparentPopupVC.modalPresentationStyle = .overFullScreen
deletePostPopupVC.modalPresentationStyle = .overFullScreen
}

private func setHierarchy() {
Expand Down Expand Up @@ -179,6 +187,44 @@ extension PostViewController {
self.navigationController?.popViewController(animated: true)
}

private func setAddTarget() {
ghostButton.addTarget(self, action: #selector(transparentShowPopupButton), for: .touchUpInside)
deleteBottomsheet.deleteButton.addTarget(self, action: #selector(deletePost), for: .touchUpInside)
postView.deleteBottomsheet.deleteButton.addTarget(self, action: #selector(deletePost), for: .touchUpInside)
}

@objc
func deletePost() {
popView()
presentView()
}

func popView() {
if UIApplication.shared.keyWindowInConnectedScenes != nil {
UIView.animate(withDuration: 0.3, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .curveEaseOut, animations: {
self.deleteBottomsheet.dimView.alpha = 0
self.postView.deleteBottomsheet.dimView.alpha = 0
if let window = UIApplication.shared.keyWindowInConnectedScenes {
self.deleteBottomsheet.bottomsheetView.frame = CGRect(x: 0, y: window.frame.height, width: self.deleteBottomsheet.frame.width, height: self.deleteBottomsheet.bottomsheetView.frame.height)
self.postView.deleteBottomsheet.bottomsheetView.frame = CGRect(x: 0, y: window.frame.height, width: self.postView.deleteBottomsheet.frame.width, height: self.postView.deleteBottomsheet.bottomsheetView.frame.height)
}
})
deleteBottomsheet.dimView.removeFromSuperview()
deleteBottomsheet.bottomsheetView.removeFromSuperview()
postView.deleteBottomsheet.dimView.removeFromSuperview()
postView.deleteBottomsheet.bottomsheetView.removeFromSuperview()
}
}

func presentView() {
self.present(self.deletePostPopupVC, animated: false, completion: nil)
}

@objc
func transparentShowPopupButton() {
self.present(self.transparentPopupVC, animated: false, completion: nil)
}

private func setTextFieldGesture() {
greenTextField.isUserInteractionEnabled = true
let gesture = UITapGestureRecognizer(target: self, action: #selector(textFieldDidTapped))
Expand All @@ -199,6 +245,7 @@ extension PostViewController {
private func dismissViewController() {
self.dismiss(animated: false)
}

}

// MARK: - Network
Expand All @@ -220,6 +267,18 @@ extension PostViewController: UICollectionViewDataSource {
let cell =
PostReplyCollectionViewCell.dequeueReusableCell(collectionView: collectionView, indexPath: indexPath)

cell.KebabButtonAction = {
self.deleteBottomsheet.showSettings()
}
cell.LikeButtonAction = {
cell.isLiked.toggle()
cell.likeButton.setImage(cell.isLiked ? ImageLiterals.Posting.btnFavoriteActive : ImageLiterals.Posting.btnFavoriteInActive, for: .normal)
}
cell.TransparentButtonAction = {
// present
self.present(self.transparentPopupVC, animated: false, completion: nil)
}

return cell
}

Expand Down
17 changes: 6 additions & 11 deletions DontBe-iOS/DontBe-iOS/Presentation/Post/Views/PostView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ final class PostView: UIView {

// MARK: - Properties

var KebabButtonAction: (() -> Void) = {}
var LikeButtonAction: (() -> Void) = {}
var TransparentButtonAction: (() -> Void) = {}
var deleteBottomsheet = DontBeBottomSheetView(singleButtonImage: ImageLiterals.Posting.btnDelete)
var isLiked: Bool = false

// MARK: - UI Components
Expand Down Expand Up @@ -128,7 +126,7 @@ final class PostView: UIView {
return label
}()

private let ghostButton: UIButton = {
let ghostButton: UIButton = {
let button = UIButton()
button.setImage(ImageLiterals.Posting.btnTransparent, for: .normal)
return button
Expand Down Expand Up @@ -272,21 +270,18 @@ extension PostView {
func setAddTarget() {
kebabButton.addTarget(self, action: #selector(showButtons), for: .touchUpInside)
likeButton.addTarget(self, action: #selector(likeToggleButton), for: .touchUpInside)
ghostButton.addTarget(self, action: #selector(transparentShowPopupButton), for: .touchUpInside)
}

@objc
func showButtons() {
KebabButtonAction()
self.deleteBottomsheet.showSettings()
}

@objc
func likeToggleButton() {
LikeButtonAction()
}
@objc
func transparentShowPopupButton() {
TransparentButtonAction()
isLiked.toggle()
likeButton.setImage(isLiked ? ImageLiterals.Posting.btnFavoriteActive : ImageLiterals.Posting.btnFavoriteInActive, for: .normal)

}

private func setRegisterCell() {
Expand Down

0 comments on commit 667b194

Please sign in to comment.