Skip to content

Commit

Permalink
[Feat] #170 - 스파크 보내기 토스트메세지 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
yangsubinn committed Jan 21, 2022
1 parent 391dfc5 commit 4d209c2
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 19 deletions.
49 changes: 35 additions & 14 deletions Spark-iOS/Spark-iOS/Source/Extensions/UIViewController+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,15 @@ extension UIViewController {
completion: {_ in toastLabel.removeFromSuperview() })
}

func showSparkToast(x: CGFloat, y: CGFloat, message: String, font: UIFont) {
var backgroundView = UIView(frame: CGRect(x: x,
func showSparkToast(x: CGFloat, y: CGFloat, message: String) {
let backgroundView = UIView(frame: CGRect(x: x,
y: y,
width: self.view.frame.size.width - 40,
height: 100))
var toastLabel = UILabel()
var toastImageView = UIImageView()
let toastLabel = UILabel()
let toastImageView = UIImageView()

backgroundView.backgroundColor = .sparkWhite
backgroundView.layer.cornerRadius = 2
backgroundView.layer.shadowColor = UIColor.sparkBlack.cgColor

toastLabel.text = message
toastLabel.textColor = .sparkBlack
toastLabel.font = .p2Subtitle
toastImageView.image = UIImage(named: "illustHandSendSpark")

view.addSubviews([toastImageView, toastLabel])
backgroundView.addSubviews([toastImageView, toastLabel])

toastImageView.snp.makeConstraints { make in
make.centerX.equalToSuperview()
Expand All @@ -59,5 +50,35 @@ extension UIViewController {
make.top.equalTo(toastImageView.snp.bottom)
make.leading.equalToSuperview().inset(16)
}

backgroundView.backgroundColor = .sparkWhite
backgroundView.layer.cornerRadius = 2
backgroundView.clipsToBounds = true
backgroundView.layer.shadowColor = UIColor.sparkBlack.cgColor
backgroundView.layer.shadowOffset = CGSize(width: 0, height: 4)
backgroundView.layer.shadowRadius = 10
backgroundView.layer.masksToBounds = false
backgroundView.layer.shadowOpacity = 0.15

toastLabel.text = message
toastLabel.textColor = .sparkBlack
toastLabel.textAlignment = .center
toastLabel.font = .p2Subtitle
toastImageView.image = UIImage(named: "illustHandSendSpark")

self.view.addSubview(backgroundView)
backgroundView.alpha = 0.0
UIView.animate(withDuration: 0.2, delay: 0.2,
options: .curveEaseInOut) {
backgroundView.alpha = 1.0
} completion: { _ in
UIView.animate(withDuration: 0.8, delay: 1.0,
options:
.curveEaseInOut) {
backgroundView.alpha = 0.0
} completion: { _ in
backgroundView.removeFromSuperview()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,14 @@ extension HabitRoomVC {
}
}

private func presentToSendSparkVC(recordID: Int) {
private func presentToSendSparkVC(recordID: Int, nickname: String) {
guard let nextVC = UIStoryboard(name: Const.Storyboard.Name.sendSpark, bundle: nil).instantiateViewController(withIdentifier: Const.ViewController.Identifier.sendSpark) as? SendSparkVC else { return }
nextVC.modalPresentationStyle = .overFullScreen
nextVC.modalTransitionStyle = .crossDissolve
nextVC.roomID = habitRoomDetail?.roomID
nextVC.recordID = recordID

nextVC.userName = nickname

self.present(nextVC, animated: true, completion: nil)
}

Expand Down Expand Up @@ -345,7 +346,7 @@ extension HabitRoomVC: UICollectionViewDataSource {
profileImg: habitRoomDetail?.otherRecords[indexPath.item - 1]?.profileImg ?? "",
nickname: habitRoomDetail?.otherRecords[indexPath.item - 1]?.nickname ?? "",
status: habitRoomDetail?.otherRecords[indexPath.item - 1]?.status ?? "",
leftDay: habitRoomDetail?.leftDay ?? 0) { self.presentToSendSparkVC(recordID: self.habitRoomDetail?.otherRecords[indexPath.item - 1]?.recordID ?? 0) }
leftDay: habitRoomDetail?.leftDay ?? 0) { self.presentToSendSparkVC(recordID: self.habitRoomDetail?.otherRecords[indexPath.item - 1]?.recordID ?? 0, nickname: self.habitRoomDetail?.otherRecords[indexPath.item - 1]?.nickname ?? "") }

return cell
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class SendSparkVC: UIViewController {
var secondButton = StatusButton()
var thirdButton = StatusButton()
var fourthButton = StatusButton()
var userName: String?

// MARK: IBoutlet properties

Expand Down Expand Up @@ -106,7 +107,8 @@ extension SendSparkVC {

// MARK: - @objc Function

@objc func setSelectedButton(sender: StatusButton) {
@objc
func setSelectedButton(sender: StatusButton) {

let status = sender.status

Expand Down Expand Up @@ -174,7 +176,10 @@ extension SendSparkVC {
RoomAPI.shared.sendSpark(roomID: roomID ?? 0, recordID: recordID ?? 0, content: selectedMessage) { response in
switch response {
case .success(_):
self.dismiss(animated: true)
let presentVC = self.presentingViewController
self.dismiss(animated: true) {
presentVC?.showSparkToast(x: 20, y: 44, message: "\(self.userName ?? "")에게 스파크를 보냈어요!")
}
case .requestErr(let message):
print("sendSparkWithAPI - requestErr: \(message)")
case .pathErr:
Expand Down

0 comments on commit 4d209c2

Please sign in to comment.