Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor] #209 - 코스 공유와, 커스텀 바텀시트 부분을 수정 하였습니다. #211

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

/* Begin PBXBuildFile section */
0AEBD608F3973389E8E1C6D6 /* Pods_Runnect_iOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 015778D02D5CDE0838284CD7 /* Pods_Runnect_iOS.framework */; };
2349CD532B026EA500EE7C4A /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 2349CD512B024E5B00EE7C4A /* GoogleService-Info.plist */; };
23EE06C12AC1AD5200CB3FF8 /* LocationSelectView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23EE06C02AC1AD5200CB3FF8 /* LocationSelectView.swift */; };
23EE06C52AC1AE1900CB3FF8 /* BaseView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23EE06C42AC1AE1900CB3FF8 /* BaseView.swift */; };
23EE06C92AC1DED100CB3FF8 /* GesturePublisher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23EE06C82AC1DED100CB3FF8 /* GesturePublisher.swift */; };
23EE06CB2AC2AF3E00CB3FF8 /* KakaoAddressSearchingResponseDto.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23EE06CA2AC2AF3E00CB3FF8 /* KakaoAddressSearchingResponseDto.swift */; };
23EE06D12AC2F44E00CB3FF8 /* TmapAddressSearchingResponseDto.swift in Sources */ = {isa = PBXBuildFile; fileRef = 23EE06D02AC2F44E00CB3FF8 /* TmapAddressSearchingResponseDto.swift */; };
712F661D2A7B7BAB00D9539B /* Config.swift in Sources */ = {isa = PBXBuildFile; fileRef = 712F661C2A7B7BAB00D9539B /* Config.swift */; };
7136BF8A2AF921A900679364 /* CustomBottomSheetVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7136BF892AF921A900679364 /* CustomBottomSheetVC.swift */; };
71717B072B063E14004EA8DA /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 71DBF23D2ABB255A0013415B /* GoogleService-Info.plist */; };
A3305A97296EF58C000B1A10 /* GoalRewardInfoDto.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3305A96296EF58C000B1A10 /* GoalRewardInfoDto.swift */; };
A3BC2F2B2962C3D500198261 /* GoalRewardInfoVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3BC2F2A2962C3D500198261 /* GoalRewardInfoVC.swift */; };
A3BC2F2D2962C3F200198261 /* ActivityRecordInfoVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3BC2F2C2962C3F200198261 /* ActivityRecordInfoVC.swift */; };
Expand Down Expand Up @@ -168,7 +168,6 @@

/* Begin PBXFileReference section */
015778D02D5CDE0838284CD7 /* Pods_Runnect_iOS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runnect_iOS.framework; sourceTree = BUILT_PRODUCTS_DIR; };
2349CD512B024E5B00EE7C4A /* GoogleService-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = "GoogleService-Info.plist"; path = "Runnect-iOS/GoogleService-Info.plist"; sourceTree = "<group>"; };
23EE06C02AC1AD5200CB3FF8 /* LocationSelectView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationSelectView.swift; sourceTree = "<group>"; };
23EE06C42AC1AE1900CB3FF8 /* BaseView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseView.swift; sourceTree = "<group>"; };
23EE06C82AC1DED100CB3FF8 /* GesturePublisher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GesturePublisher.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -798,7 +797,6 @@
CE4545BC295D7AF4003201E1 = {
isa = PBXGroup;
children = (
2349CD512B024E5B00EE7C4A /* GoogleService-Info.plist */,
CE665614295D989A00C64E12 /* .swiftlint.yml */,
CE4545C7295D7AF4003201E1 /* Runnect-iOS */,
CE4545C6295D7AF4003201E1 /* Products */,
Expand Down Expand Up @@ -1274,9 +1272,9 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
2349CD532B026EA500EE7C4A /* GoogleService-Info.plist in Resources */,
CE665615295D989A00C64E12 /* .swiftlint.yml in Resources */,
CE17F0342961BEF800E1DED0 /* Pretendard-Bold.otf in Resources */,
71717B072B063E14004EA8DA /* GoogleService-Info.plist in Resources */,
CE17F0352961BEF800E1DED0 /* Pretendard-SemiBold.otf in Resources */,
CE17F0332961BEF800E1DED0 /* Pretendard-Medium.otf in Resources */,
CE6655BF295D82E200C64E12 /* .gitkeep in Resources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,17 @@ import CombineCocoa

@frozen
enum SheetType {
case Image // 가운에 이미지가 있는 시트
case TextField // 가운데 텍스트필드가 있는 시트
case image // 가운에 이미지가 있는 시트
case textField // 가운데 텍스트필드가 있는 시트
}

final class CustomBottomSheetVC: UIViewController {

// MARK: - Properties

private let backgroundView = UIView().then {
$0.backgroundColor = .black.withAlphaComponent(0.65)
}
private let titleNameMaxLength = 20
private var BottomsheetType: SheetType!

private var bottomSheetType: SheetType!
var backgroundTapAction: (() -> Void)?
var completeButtonTapAction: ((String) -> Void)?

Expand All @@ -33,34 +30,31 @@ final class CustomBottomSheetVC: UIViewController {
private var cancelBag = CancelBag()

// MARK: - UI Components

private let bottomSheetView = UIView().then {
$0.backgroundColor = .w1
$0.layer.cornerRadius = 20
$0.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner]
}

private let contentsLabel = UILabel().then {
$0.text = "코스 이름"
$0.font = .h5
$0.textColor = .g1
}

private let dismissIndicatorView = UIView().then {
$0.backgroundColor = .g3
$0.backgroundColor = .g4
$0.layer.cornerRadius = 3
}

private let completeButton = CustomButton(title: "완료").setColor(bgColor: .m1, disableColor: .g3).setEnabled(false)

private let mainImageView = UIImageView().then {
$0.image = ImageLiterals.imgSpaceship
}

private lazy var bottomSheetTextField = UITextField().then {
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = .center
$0.attributedPlaceholder = NSAttributedString(string: "코스의 이름을 입력해 주세요", attributes: [.font: UIFont.h5, .foregroundColor: UIColor.g3, .paragraphStyle: paragraphStyle])
$0.attributedPlaceholder = NSAttributedString(
string: "코스의 이름을 입력해 주세요",
attributes: [.font: UIFont.h5, .foregroundColor: UIColor.g3, .paragraphStyle: paragraphStyle]
)
$0.font = .h5
$0.textColor = .g1
$0.textAlignment = .center
Expand All @@ -70,56 +64,47 @@ final class CustomBottomSheetVC: UIViewController {
$0.addTarget(self, action: #selector(textFieldTextDidChange), for: .editingChanged)
}

// MARK: - initializtion
// MARK: - Initialization
init(type: SheetType) {
super.init(nibName: nil, bundle: nil)
self.BottomsheetType = type
self.bottomSheetType = type
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

// MARK: - View Life Cycle

override func viewDidLoad() {
super.viewDidLoad()
self.setUI()
self.setLayout(BottomsheetType)
self.setLayout(bottomSheetType)
self.setDelegate()
self.setTapGesture()
self.setAddTarget()
self.setBinding()
if BottomsheetType == .TextField {
if bottomSheetType == .textField {
showBottomSheet()
setupGestureRecognizer()
}
}

}

// MARK: - Methods

extension CustomBottomSheetVC {

/// 바텀 시트의 라벨에 들어갈 텍스트 설정
// MARK: - Methods
@discardableResult
func setContentsText(text: String) -> Self {
self.contentsLabel.text = text
contentsLabel.text = text
return self
}

/// 하단 버튼의 텍스트 변경
@discardableResult
public func setBottomButtonTitle(_ title: NSAttributedString) -> Self {
self.completeButton.changeTitle(attributedString: title)
func setBottomButtonTitle(_ title: NSAttributedString) -> Self {
completeButton.changeTitle(attributedString: title)
return self
}

/// 이미지 교체
@discardableResult
public func setImage(_ image: UIImage) -> Self {
self.mainImageView.image = image
func setImage(_ image: UIImage) -> Self {
mainImageView.image = image
return self
}

Expand All @@ -133,7 +118,6 @@ extension CustomBottomSheetVC {
}, completion: nil)
}

// 중복 작업 통일 필요 (1. 배경화면 누를시, 2.스와이프 할시)
private func setTapGesture() {
let tap = UITapGestureRecognizer(target: view, action: #selector(UIView.endEditing))
tap.cancelsTouchesInView = false
Expand All @@ -148,17 +132,18 @@ extension CustomBottomSheetVC {
self,
selector: #selector(keyboardWillShow),
name: UIResponder.keyboardWillShowNotification,
object: nil)
object: nil
)
NotificationCenter.default.addObserver(
self,
selector: #selector(keyboardWillHide),
name: UIResponder.keyboardWillHideNotification,
object: nil)
object: nil
)
}
}

// MARK: - UI & Layout

extension CustomBottomSheetVC {
private func setUI() {
view.addSubview(backgroundView)
Expand All @@ -169,9 +154,9 @@ extension CustomBottomSheetVC {

private func setLayout(_ type: SheetType) {
switch type {
case .TextField:
case .textField:
setTextFieldLayout()
case .Image:
case .image:
setImageLayout()
}
}
Expand Down Expand Up @@ -203,7 +188,7 @@ extension CustomBottomSheetVC {
make.leading.trailing.equalToSuperview().inset(16)
}
}

private func setTextFieldLayout() {
view.addSubviews(bottomSheetView)

Expand All @@ -218,9 +203,9 @@ extension CustomBottomSheetVC {
}

dismissIndicatorView.snp.makeConstraints { make in
make.width.equalTo(102)
make.height.equalTo(7)
make.top.equalTo(bottomSheetView.snp.top).inset(12)
make.width.equalTo(42)
make.height.equalTo(4)
make.top.equalTo(bottomSheetView.snp.top).inset(16)
make.centerX.equalToSuperview()
}

Expand Down Expand Up @@ -252,7 +237,6 @@ extension CustomBottomSheetVC {
}

private func showBottomSheet() {

let safeAreaHeight: CGFloat = view.safeAreaLayoutGuide.layoutFrame.height
let bottomPadding: CGFloat = view.safeAreaInsets.bottom

Expand All @@ -268,10 +252,8 @@ extension CustomBottomSheetVC {
self.backgroundView.alpha = 0.65
self.view.layoutIfNeeded()
}, completion: nil)

}

// 바텀 시트 사라지는 애니메이션
private func hideBottomSheetAndGoBack() {
let safeAreaHeight = view.safeAreaLayoutGuide.layoutFrame.height
let bottomPadding = view.safeAreaInsets.bottom
Expand All @@ -283,7 +265,7 @@ extension CustomBottomSheetVC {
make.top.equalTo(view.snp.top).offset(topConst)
make.height.equalTo(bottomHeight)
}

UIView.animate(withDuration: 0.25, delay: 0, options: .curveEaseIn, animations: {
self.backgroundView.alpha = 0.0
self.view.layoutIfNeeded()
Expand All @@ -294,33 +276,28 @@ extension CustomBottomSheetVC {
}
}

// GestureRecognizer 세팅 작업
private func setupGestureRecognizer() {
// 흐린 부분 탭할 때, 바텀시트를 내리는 TapGesture
let dimmedTap = UITapGestureRecognizer(target: self, action: #selector(dimmedViewTapped(_:)))
backgroundView.addGestureRecognizer(dimmedTap)
backgroundView.isUserInteractionEnabled = true

// 스와이프 했을 때, 바텀시트를 내리는 swipeGesture
let swipeGesture = UISwipeGestureRecognizer(target: self, action: #selector(panGesture))
swipeGesture.direction = .down
view.addGestureRecognizer(swipeGesture)
}
}

// MARK: - @objc Function

extension CustomBottomSheetVC {

@objc private func keyboardWillShow(_ sender: Notification) {
self.view.frame.origin.y = -341
self.view.frame.origin.y = -291
}

@objc private func keyboardWillHide(_ sender: Notification) {
self.view.frame.origin.y = 0
}

@objc private func endEditing() { /// return 누를시 키보드 종료
@objc private func endEditing() {
bottomSheetTextField.resignFirstResponder()
}

Expand All @@ -342,12 +319,10 @@ extension CustomBottomSheetVC {
}
}

// UITapGestureRecognizer 연결 함수 부분
@objc private func dimmedViewTapped(_ tapRecognizer: UITapGestureRecognizer) {
hideBottomSheetAndGoBack()
}

// UISwipeGestureRecognizer 연결 함수 부분
@objc func panGesture(_ recognizer: UISwipeGestureRecognizer) {
if recognizer.state == .ended {
switch recognizer.direction {
Expand All @@ -358,13 +333,10 @@ extension CustomBottomSheetVC {
}
}
}

}

// MARK: - UITextFieldDelegate

extension CustomBottomSheetVC: UITextFieldDelegate {

func textFieldShouldReturn(_ textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true
Expand Down
Loading