Skip to content

Commit

Permalink
Merge pull request #172 from yangsubinn/feature/#170
Browse files Browse the repository at this point in the history
[Feat] #170 - 스파크 보내기 토스트메세지
  • Loading branch information
yangsubinn authored Jan 21, 2022
2 parents 2afabda + 4d209c2 commit 0d707bb
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 5 deletions.
8 changes: 8 additions & 0 deletions Spark-iOS/Spark-iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,13 @@
path = Feed;
sourceTree = "<group>";
};
2BBFEFBD279ABBD900C085E4 /* HabitRoom */ = {
isa = PBXGroup;
children = (
);
path = HabitRoom;
sourceTree = "<group>";
};
2BC1726E278F54B300BA3029 /* Waiting */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -772,6 +779,7 @@
F8096F1D27841DB600B71D38 /* Views */ = {
isa = PBXGroup;
children = (
2BBFEFBD279ABBD900C085E4 /* HabitRoom */,
2B98520C2790ADDC00CE40A7 /* CreateAuth */,
);
path = Views;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "illustHandSendspark.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "illustHandSendspark@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "illustHandSendspark@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 53 additions & 0 deletions Spark-iOS/Spark-iOS/Source/Extensions/UIViewController+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,57 @@ extension UIViewController {
options: .curveEaseIn, animations: { toastLabel.alpha = 0.0 },
completion: {_ in toastLabel.removeFromSuperview() })
}

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))
let toastLabel = UILabel()
let toastImageView = UIImageView()

backgroundView.addSubviews([toastImageView, toastLabel])

toastImageView.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.top.equalToSuperview().inset(7)
make.width.height.equalTo(56)
}

toastLabel.snp.makeConstraints { make in
make.centerX.equalToSuperview()
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 0d707bb

Please sign in to comment.