From a75fc9f1dd4e1b1bd5b6733855c1584d4d7ef5d6 Mon Sep 17 00:00:00 2001 From: Do-hyun-Kim Date: Fri, 25 Oct 2024 20:11:01 +0900 Subject: [PATCH 1/9] =?UTF-8?q?feat:=20BBBaseToolTipView,=20BBThumbnailToo?= =?UTF-8?q?lTipView=20=EC=B6=94=EA=B0=80=20-=20BBAnimatable=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=88=98=EC=A0=95=20-=20BBToolTipType=20xPosition,?= =?UTF-8?q?=20yPosition=20=EB=B6=84=EB=A6=AC=20-=20BBToolTipAction=20Neste?= =?UTF-8?q?d=20Type=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BBCommons/BBToolTip/BBAnimatable.swift | 18 +- .../BBCommons/BBToolTip/BBDrawable.swift | 2 +- .../BBToolTip/BBToolTipConfiguration.swift | 12 +- .../BBCommons/BBToolTip/BBToolTipType.swift | 36 +++- .../BBCommons/BBToolTip/BBToolTipView.swift | 197 ++++++++++++------ 5 files changed, 180 insertions(+), 85 deletions(-) diff --git a/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBAnimatable.swift b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBAnimatable.swift index 9cd47602b..b04379956 100644 --- a/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBAnimatable.swift +++ b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBAnimatable.swift @@ -28,30 +28,30 @@ public protocol BBComponentClosable { //MARK: - Extensions -public extension BBComponentShowable where Self: UIView { +public extension BBComponentShowable where Self: BBToolTip { /// showPopover 메서드 호출 시 Popover 애니메이션 효과를 실행합니다. func showPopover(duration: TimeInterval = 0.3, options: UIView.AnimationOptions = [.curveEaseInOut], transform: CGAffineTransform = CGAffineTransform(scaleX: 0.1, y: 0.1), alpha: CGFloat = 1) { - self.transform = transform - self.alpha = alpha + self.contentView.transform = transform + self.contentView.alpha = alpha UIView.animate(withDuration: duration, delay: 0, options: options) { [weak self] in guard let self else { return } - self.transform = CGAffineTransform.identity - self.alpha = 1 + self.contentView.transform = CGAffineTransform.identity + self.contentView.alpha = 1 } } } -public extension BBComponentClosable where Self: UIView { +public extension BBComponentClosable where Self: BBToolTip { /// hidePopover 메서드 호출 시 Popover 애니메이션 효과를 제거합니다. func hidePopover(duration: TimeInterval = 0.3, options: UIView.AnimationOptions = [.curveEaseInOut], transform: CGAffineTransform = CGAffineTransform(scaleX: 0.1, y: 0.1), alpha: CGFloat = 0) { UIView.animate(withDuration: duration, delay: 0, options: options) { [weak self] in guard let self else { return } - self.transform = transform - self.alpha = alpha + self.contentView.transform = transform + self.contentView.alpha = alpha } completion: { _ in - self.transform = CGAffineTransform.identity + self.contentView.transform = CGAffineTransform.identity } } } diff --git a/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBDrawable.swift b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBDrawable.swift index 348387470..399320bf4 100644 --- a/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBDrawable.swift +++ b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBDrawable.swift @@ -46,7 +46,7 @@ extension BBDrawable { /// **BBToolTipType** 에 따라 Arrow의 위치가 배치됩니다. func drawToolTipArrowShape(_ frame: CGRect, type: BBToolTipType, path: CGMutablePath) { let margin: CGFloat = 16 - let arrowTipXPosition = type.xPosition.rawValue * frame.width + let arrowTipXPosition = type.configure.xPosition.rawValue * frame.width let adjustedArrowTipXPosition = min(max(arrowTipXPosition, margin + type.configure.arrowWidth / 2), frame.width - margin - type.configure.arrowWidth / 2) let arrowLeft = adjustedArrowTipXPosition - type.configure.arrowWidth / 2 let arrowRight = adjustedArrowTipXPosition + type.configure.arrowWidth / 2 diff --git a/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTipConfiguration.swift b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTipConfiguration.swift index f46711b80..c788a78db 100644 --- a/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTipConfiguration.swift +++ b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTipConfiguration.swift @@ -17,8 +17,10 @@ public struct BBToolTipConfiguration { public var foregroundColor: UIColor /// TooTip Background Color public var backgroundColor: UIColor - /// ToolTip Arrow Position - public var position: BBToolTipVerticalPosition + /// ToolTip Arrow YPosition + public var yPosition: BBToolTipVerticalPosition + /// ToolTip Arrow XPosition + public var xPosition: BBToolTipHorizontalPosition /// ToolTip Text Font public var font: BBFontStyle /// ToolTip Content Text @@ -32,7 +34,8 @@ public struct BBToolTipConfiguration { cornerRadius: CGFloat = 12, foregroundColor: UIColor = .bibbiBlack, backgroundColor: UIColor = .mainYellow, - position: BBToolTipVerticalPosition = .top, + yPosition: BBToolTipVerticalPosition = .bottom, + xPosition: BBToolTipHorizontalPosition = .center, font: BBFontStyle = .body2Regular, contentText: String = "", arrowWidth: CGFloat = 15, @@ -41,7 +44,8 @@ public struct BBToolTipConfiguration { self.cornerRadius = cornerRadius self.foregroundColor = foregroundColor self.backgroundColor = backgroundColor - self.position = position + self.xPosition = xPosition + self.yPosition = yPosition self.font = font self.contentText = contentText self.arrowWidth = arrowWidth diff --git a/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTipType.swift b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTipType.swift index 21b428435..b628cd0a0 100644 --- a/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTipType.swift +++ b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTipType.swift @@ -9,6 +9,12 @@ import UIKit import DesignSystem + +public enum BBToolTipAction: String { + case show + case hide +} + /// BBToolTip의 Style을 설정하기 위한 Nested types입니다. /// 해당 **BBToolTipType** 을 통해 BBToolTip의 Layout을 구성합니다. public enum BBToolTipType { @@ -52,70 +58,80 @@ public enum BBToolTipType { return .init( foregroundColor: .bibbiWhite, backgroundColor: .gray700, - position: .bottom, + yPosition: .bottom, + xPosition: .center, contentText: "오늘의 생존신고는 완료되었어요" ) case .activeCameraTime: return .init( foregroundColor: .bibbiWhite, backgroundColor: .gray700, - position: .bottom, + yPosition: .bottom, + xPosition: .center, contentText: "하루에 한 번 사진을 올릴 수 있어요" ) case .familyNameEdit: return .init( foregroundColor: .bibbiBlack, backgroundColor: .mainYellow, - position: .bottom, + yPosition: .bottom, + xPosition: .right, contentText: "가족 방 이름을 변경해보세요!" ) case .inactiveSurvivalCameraNoUpload: return .init( foregroundColor: .bibbiWhite, backgroundColor: .gray700, - position: .bottom, + yPosition: .bottom, + xPosition: .center, contentText: "생존신고 후 미션 사진을 올릴 수 있어요" ) case .inactiveMissionCameraPostUpload: return .init( foregroundColor: .bibbiWhite, backgroundColor: .gray700, - position: .bottom, + yPosition: .bottom, + xPosition: .center, contentText: "오늘의 미션은 완료되었어요" ) case .inactiveMissionCamera: return .init( foregroundColor: .bibbiWhite, backgroundColor: .gray700, - position: .bottom, + yPosition: .bottom, + xPosition: .center, contentText: "아직 미션 사진을 찍을 수 없어요" ) case .activeMissionCamera: return .init( foregroundColor: .bibbiWhite, backgroundColor: .gray700, - position: .bottom, + yPosition: .bottom, + xPosition: .center, contentText: "미션 사진을 찍으러 가볼까요?" ) case .contributor: return .init( foregroundColor: .bibbiWhite, backgroundColor: .gray700, - position: .top, + yPosition: .top, + xPosition: .midLeft, contentText: "생존신고 횟수가 동일한 경우\n이모지, 댓글 수를 합산해서 등수를 정해요" ) case .monthlyCalendar: return .init( foregroundColor: .bibbiWhite, backgroundColor: .gray700, - position: .top, + yPosition: .top, + xPosition: .midLeft, contentText: "모두가 참여한 날과 업로드한 사진 수로\n이 달의 친밀도를 측정합니다" ) case let .waitingSurvivalImage(contentText, profile): return .init( foregroundColor: .bibbiBlack, backgroundColor: .mainYellow, - position: .bottom, + yPosition: .bottom, + xPosition: .center, contentText: "\(contentText)님 외 \(profile.count - 1)명이 기다리고 있어요" ) } diff --git a/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTipView.swift b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTipView.swift index 22612f967..949a48bb0 100644 --- a/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTipView.swift +++ b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTipView.swift @@ -13,22 +13,92 @@ import SnapKit import Then -public final class BBToolTipView: UIView, BBDrawable, BBComponentPresentable { +public class BBThumbnailToolTipView: BBBaseToolTipView { + private let stackView: UIStackView = UIStackView() - //MARK: Properties - private let contentLabel: BBLabel = BBLabel() - private let profileStackView: UIStackView = UIStackView() - public var toolTipType: BBToolTipType = .activeCameraTime { + public override init(toolTipType: BBToolTipType) { + super.init(toolTipType: toolTipType) + guard case let .waitingSurvivalImage(_, imageURLs) = toolTipType else { + return + } + setupThumbnailImageView(imageURL: imageURLs) + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + + public override func setupToolTipUI() { + super.setupToolTipUI() + addSubview(stackView) + } + + + public override func setupAutoLayount() { + super.setupAutoLayount() + let arrowHeight: CGFloat = toolTipType.configure.arrowHeight + let textPadding: CGFloat = 10 + guard case let .waitingSurvivalImage(contentText, imageURLs) = toolTipType else { + return + } + + stackView.snp.makeConstraints { + $0.width.equalTo(24 * imageURLs.count) + $0.height.equalTo(24) + $0.left.equalToSuperview().inset(16) + $0.centerY.equalTo(contentLabel) + } + + + contentLabel.snp.makeConstraints { + $0.left.equalTo(stackView.snp.right).offset(22) + $0.right.equalToSuperview().inset(16) + $0.bottom.equalToSuperview().inset(arrowHeight + textPadding) + $0.top.equalToSuperview().inset(textPadding) + } + + + } + + public override func setupToolTipContent() { + super.setupToolTipContent() + stackView.do { + $0.spacing = -4 + $0.distribution = .fillEqually + } + } + + + private func setupThumbnailImageView(imageURL: [URL]) { + imageURL.forEach { + let imageView: UIImageView = UIImageView(frame: .init(x: 0, y: 0, width: 20, height: 20)) + imageView.contentMode = .scaleAspectFill + imageView.layer.borderColor = UIColor.mainYellow.cgColor + imageView.layer.borderWidth = 2 + imageView.layer.cornerRadius = 10 + imageView.clipsToBounds = true + imageView.kf.setImage(with: $0) + stackView.addArrangedSubview(imageView) + } + } + +} + + +public class BBBaseToolTipView: UIView, BBDrawable { + + public private(set) var toolTipType: BBToolTipType { didSet { setupToolTipContent() - setupAutoLayout(toolTipType) - setNeedsDisplay() + setupAutoLayount() } } + public private(set) var contentLabel: BBLabel = BBLabel() - public init() { + public init(toolTipType: BBToolTipType) { + self.toolTipType = toolTipType super.init(frame: .zero) - setupToolTipUI() } required init?(coder: NSCoder) { @@ -43,14 +113,11 @@ public final class BBToolTipView: UIView, BBDrawable, BBComponentPresentable { context.restoreGState() } - //MARK: Configure - private func setupToolTipContent() { - - profileStackView.do { - $0.spacing = -4 - $0.distribution = .fillEqually - } - + public func setupToolTipUI() { + addSubview(contentLabel) + } + + public func setupToolTipContent() { contentLabel.do { $0.text = toolTipType.configure.contentText $0.fontStyle = toolTipType.configure.font @@ -65,63 +132,71 @@ public final class BBToolTipView: UIView, BBDrawable, BBComponentPresentable { } } - private func setupToolTipUI() { - addSubviews(contentLabel, profileStackView) + public func setupAutoLayount() { + let arrowHeight: CGFloat = toolTipType.configure.arrowHeight + let textPadding: CGFloat = 10 + contentLabel.snp.makeConstraints { + $0.horizontalEdges.equalToSuperview().inset(16) + $0.top.equalToSuperview().inset(arrowHeight + textPadding) + $0.bottom.equalToSuperview().inset(textPadding) + } } +} + + +public final class BBToolTip: AnyObject, BBComponentPresentable { + - private func setupWaitingToolTipUI(imageURL: [URL]) { - imageURL.forEach { - createProfileImageView(imageURL: $0) + public var contentView: UIView? + private let superview: UIView? + public var configure: BBToolTipType { + didSet { + switch configure { + case .waitingSurvivalImage: + contentView = createThumbnailToolTipView() + default: + contentView = createTextToolTipView() + } } } - private func createProfileImageView(imageURL: URL) { - let imageView = UIImageView(frame: .init(x: 0, y: 0, width: 20, height: 20)) - imageView.contentMode = .scaleAspectFill - imageView.layer.borderColor = UIColor.mainYellow.cgColor - imageView.layer.borderWidth = 2 - imageView.clipsToBounds = true - imageView.layer.cornerRadius = 10 - imageView.kf.setImage(with: imageURL) - profileStackView.addArrangedSubview(imageView) + + public init(configure: BBToolTipType, superView: UIView) { + self.configure = configure + self.superview = superView } - private func setupAutoLayout(_ type: BBToolTipType) { - let arrowHeight = toolTipType.configure.arrowHeight - let textPadding: CGFloat = 10 + private func updateConstraints() { + guard let superview else { + fatalError("SuperView not Created") + } - switch type { - case .monthlyCalendar, .contributor: - contentLabel.snp.remakeConstraints { - $0.left.equalToSuperview().inset(16) - $0.right.equalToSuperview().inset(16) - $0.top.equalToSuperview().inset((arrowHeight + textPadding)) - $0.bottom.equalToSuperview().inset(textPadding) - } - case let .waitingSurvivalImage(_ ,imageURL): - setupWaitingToolTipUI(imageURL: imageURL) - - profileStackView.snp.remakeConstraints { - $0.width.equalTo(24 * imageURL.count) - $0.left.equalToSuperview().offset(16) - $0.height.equalTo(24) - $0.centerY.equalTo(contentLabel) + switch configure { + case .contributor, .monthlyCalendar: + contentView?.snp.makeConstraints { + $0.top.equalTo(superview.snp.bottom) + $0.left.equalToSuperview().offset(20) } - - contentLabel.snp.remakeConstraints { - $0.left.equalTo(profileStackView.snp.right).offset(2) - $0.right.equalToSuperview().inset(16) - $0.bottom.equalToSuperview().inset((arrowHeight + textPadding)) - $0.top.equalToSuperview().inset(textPadding) + case .familyNameEdit: + contentView?.snp.makeConstraints { + $0.bottom.equalTo(superview.snp.top) + $0.left.equalToSuperview() } default: - contentLabel.snp.remakeConstraints { - $0.left.equalToSuperview().inset(16) - $0.right.equalToSuperview().inset(16) - $0.bottom.equalToSuperview().inset((arrowHeight + textPadding)) - $0.top.equalToSuperview().inset(textPadding) + contentView?.snp.makeConstraints { + $0.bottom.equalTo(superview.snp.top) + $0.centerX.equalToSuperview() } } } + + private func createTextToolTipView() -> BBBaseToolTipView { + return BBBaseToolTipView(toolTipType: configure) + } + + private func createThumbnailToolTipView() -> BBThumbnailToolTipView { + return BBThumbnailToolTipView(toolTipType: configure) + } + } From 5d324e30b4faa9f75993af35a5db7485498d87e6 Mon Sep 17 00:00:00 2001 From: Do-hyun-Kim Date: Sun, 27 Oct 2024 22:13:39 +0900 Subject: [PATCH 2/9] =?UTF-8?q?feat:=20BBTextToolTipView,=20BBThumbnailToo?= =?UTF-8?q?lTipView=20=EB=AA=A8=EB=93=88=20=EB=B6=84=EB=A6=AC=20-=20BBBase?= =?UTF-8?q?ToolTIpView=20=EB=82=B4=EB=B6=80=20drawable=20Method=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20-=20BBToolTip=20Class=20=EC=B6=94=EA=B0=80?= =?UTF-8?q?=20-=20BBDrawable=20protocol,=20extension=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BBCommons/BBToolTip/BBAnimatable.swift | 42 ++-- .../BBToolTip/BBBaseToolTipView.swift | 85 ++++++++ .../BBCommons/BBToolTip/BBDrawable.swift | 69 ------ .../BBToolTip/BBTextToolTipView.swift | 106 +++++++++ .../BBToolTip/BBThumbnailToolTipView.swift | 91 ++++++++ .../Bibbi/BBCommons/BBToolTip/BBToolTip.swift | 77 +++++++ .../BBCommons/BBToolTip/BBToolTipType.swift | 2 +- .../BBCommons/BBToolTip/BBToolTipView.swift | 202 ------------------ 8 files changed, 387 insertions(+), 287 deletions(-) create mode 100644 14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBBaseToolTipView.swift create mode 100644 14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBTextToolTipView.swift create mode 100644 14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBThumbnailToolTipView.swift create mode 100644 14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTip.swift delete mode 100644 14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTipView.swift diff --git a/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBAnimatable.swift b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBAnimatable.swift index b04379956..be55a44b0 100644 --- a/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBAnimatable.swift +++ b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBAnimatable.swift @@ -22,36 +22,48 @@ public protocol BBComponentShowable { /// **Animate**, **CGAffineTransform**, **CABasicAnimation** 을 활용한 Animation 메서드를 정의하는 Protocol 입니다. /// 해당 **BBComponentClosable** 프로토콜은 Component 객체를 숨기는 애니메이션을 정의하는 프로토콜입니다. public protocol BBComponentClosable { - func hidePopover(duration: TimeInterval, options: UIView.AnimationOptions, transform: CGAffineTransform, alpha: CGFloat) + func hide(duration: TimeInterval, options: UIView.AnimationOptions, transform: CGAffineTransform, alpha: CGFloat) } //MARK: - Extensions public extension BBComponentShowable where Self: BBToolTip { - /// showPopover 메서드 호출 시 Popover 애니메이션 효과를 실행합니다. func showPopover(duration: TimeInterval = 0.3, options: UIView.AnimationOptions = [.curveEaseInOut], transform: CGAffineTransform = CGAffineTransform(scaleX: 0.1, y: 0.1), alpha: CGFloat = 1) { - self.contentView.transform = transform - self.contentView.alpha = alpha + + guard let contentView else { + fatalError("contentView is Not Created") + } + + superview?.addSubview(contentView) + updateLayout() UIView.animate(withDuration: duration, delay: 0, options: options) { [weak self] in guard let self else { return } - self.contentView.transform = CGAffineTransform.identity - self.contentView.alpha = 1 + self.contentView?.transform = CGAffineTransform.identity + self.contentView?.alpha = 1 } } } public extension BBComponentClosable where Self: BBToolTip { - /// hidePopover 메서드 호출 시 Popover 애니메이션 효과를 제거합니다. - func hidePopover(duration: TimeInterval = 0.3, options: UIView.AnimationOptions = [.curveEaseInOut], transform: CGAffineTransform = CGAffineTransform(scaleX: 0.1, y: 0.1), alpha: CGFloat = 0) { + func hide( + duration: TimeInterval = 0.3, + options: UIView.AnimationOptions = [.curveEaseInOut], + transform: CGAffineTransform = CGAffineTransform(scaleX: 0.1, y: 0.1), + alpha: CGFloat = 0 + ) { - UIView.animate(withDuration: duration, delay: 0, options: options) { [weak self] in - guard let self else { return } - self.contentView.transform = transform - self.contentView.alpha = alpha - } completion: { _ in - self.contentView.transform = CGAffineTransform.identity - } + UIView.animate(withDuration: duration, delay: 0, options: options, animations: { [weak self] in + guard let self = self else { return } + self.contentView?.transform = transform + self.contentView?.alpha = 0 + }, completion: { [weak self] _ in + self?.contentView?.removeFromSuperview() + self?.contentView?.transform = .identity + }) + + print("hide popover: \(self.contentView)") + self.contentView?.layoutIfNeeded() } } diff --git a/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBBaseToolTipView.swift b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBBaseToolTipView.swift new file mode 100644 index 000000000..c384ba534 --- /dev/null +++ b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBBaseToolTipView.swift @@ -0,0 +1,85 @@ +// +// BBBaseToolTipView.swift +// Core +// +// Created by 김도현 on 10/27/24. +// + +import UIKit + +import SnapKit +import Then + +public class BBBaseToolTipView: UIView { + public var toolTipType: BBToolTipType + + public init(toolTipType: BBToolTipType) { + self.toolTipType = toolTipType + super.init(frame: .zero) + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + public override func draw(_ rect: CGRect) { + super.draw(rect) + guard let context = UIGraphicsGetCurrentContext() else { return } + context.saveGState() + drawToolTip(rect, type: toolTipType, context: context) + context.restoreGState() + } + + func drawToolTip(_ frame: CGRect, type: BBToolTipType, context: CGContext) { + let toolTipPath = CGMutablePath() + + switch type { + case .contributor, .monthlyCalendar: + drawToolTipArrowShape(frame, type: type, path: toolTipPath) + drawToolTipTopShape(frame, toolTipType: type, cornerRadius: type.configure.cornerRadius, path: toolTipPath) + default: + drawToolTipArrowShape(frame, type: type, path: toolTipPath) + drawToolTipBottomShape(frame, toolTipType: type, cornerRadius: type.configure.cornerRadius, path: toolTipPath) + } + + toolTipPath.closeSubpath() + context.addPath(toolTipPath) + context.setFillColor(type.configure.backgroundColor.cgColor) + context.fillPath() + } + + func drawToolTipArrowShape(_ frame: CGRect, type: BBToolTipType, path: CGMutablePath) { + let margin: CGFloat = 16 + let arrowTipXPosition = type.configure.xPosition.rawValue * frame.width + let adjustedArrowTipXPosition = min(max(arrowTipXPosition, margin + type.configure.arrowWidth / 2), frame.width - margin - type.configure.arrowWidth / 2) + let arrowLeft = adjustedArrowTipXPosition - type.configure.arrowWidth / 2 + let arrowRight = adjustedArrowTipXPosition + type.configure.arrowWidth / 2 + + switch type { + case .contributor, .monthlyCalendar: + path.move(to: CGPoint(x: arrowLeft, y: type.configure.arrowHeight)) + path.addLine(to: CGPoint(x: adjustedArrowTipXPosition, y: 0)) + path.addLine(to: CGPoint(x: arrowRight, y: type.configure.arrowHeight)) + default: + path.move(to: CGPoint(x: arrowLeft, y: frame.height - type.configure.arrowHeight)) + path.addLine(to: CGPoint(x: adjustedArrowTipXPosition, y: frame.height)) + path.addLine(to: CGPoint(x: arrowRight, y: frame.height - type.configure.arrowHeight)) + } + } + + func drawToolTipTopShape(_ frame: CGRect, toolTipType: BBToolTipType, cornerRadius: CGFloat, path: CGMutablePath) { + path.addArc(tangent1End: CGPoint(x: frame.maxX, y: toolTipType.configure.arrowHeight), tangent2End: CGPoint(x: frame.maxX, y: frame.maxY + frame.height), radius: cornerRadius) + path.addArc(tangent1End: CGPoint(x: frame.maxX, y: frame.maxY), tangent2End: CGPoint(x: frame.minX, y: frame.maxY), radius: cornerRadius) + + path.addArc(tangent1End: CGPoint(x: frame.minX, y: frame.maxY), tangent2End: CGPoint(x: frame.minX, y: toolTipType.configure.arrowHeight), radius: cornerRadius) + path.addArc(tangent1End: CGPoint(x: frame.minX, y: toolTipType.configure.arrowHeight), tangent2End: CGPoint(x: frame.maxX, y: toolTipType.configure.arrowHeight), radius: cornerRadius) + } + + func drawToolTipBottomShape(_ frame: CGRect, toolTipType: BBToolTipType, cornerRadius: CGFloat, path: CGMutablePath) { + path.addArc(tangent1End: CGPoint(x: frame.maxX, y: frame.height - toolTipType.configure.arrowHeight), tangent2End: CGPoint(x: frame.maxX, y: 0), radius: cornerRadius) + path.addArc(tangent1End: CGPoint(x: frame.maxX, y: 0), tangent2End: CGPoint(x: frame.minX, y: 0), radius: cornerRadius) + path.addArc(tangent1End: CGPoint(x: frame.minX, y: 0), tangent2End: CGPoint(x: frame.minX, y: frame.height - toolTipType.configure.arrowHeight), radius: cornerRadius) + path.addArc(tangent1End: CGPoint(x: frame.minX, y: frame.height - toolTipType.configure.arrowHeight), tangent2End: CGPoint(x: frame.maxX, y: frame.height - toolTipType.configure.arrowHeight), radius: cornerRadius) + } + +} diff --git a/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBDrawable.swift b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBDrawable.swift index 399320bf4..b6c9a4a61 100644 --- a/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBDrawable.swift +++ b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBDrawable.swift @@ -15,72 +15,3 @@ protocol BBDrawable { func drawToolTipTopShape(_ frame: CGRect, toolTipType: BBToolTipType, cornerRadius: CGFloat, path: CGMutablePath) } - -extension BBDrawable { - - - /// drawToolTip 메서드 호출 시 **BBToolTipType** 에 해당하는 ToolTip Layout을 **CGContext** 내에서 드로잉 하는 메서드입니다. - /// - /// drawToolTip에 frame은 UIView의 **draw(_: )** 메서드에서 호출되고 있습니다. - /// ToolTip Layout을 변경할 경우 **setNeedsDisplay** 메서드를 호출하시면 됩니다. - func drawToolTip(_ frame: CGRect, type: BBToolTipType, context: CGContext) { - let toolTipPath = CGMutablePath() - - switch type { - case .contributor, .monthlyCalendar: - drawToolTipArrowShape(frame, type: type, path: toolTipPath) - drawToolTipTopShape(frame, toolTipType: type, cornerRadius: type.configure.cornerRadius, path: toolTipPath) - default: - drawToolTipArrowShape(frame, type: type, path: toolTipPath) - drawToolTipBottomShape(frame, toolTipType: type, cornerRadius: type.configure.cornerRadius, path: toolTipPath) - } - - toolTipPath.closeSubpath() - context.addPath(toolTipPath) - context.setFillColor(type.configure.backgroundColor.cgColor) - context.fillPath() - } - - /// drawToolTipArrowShape 메서드 호출 시 ToolTip에 Arrow 모양을 드로잉 하도록 실행합니다. - /// - /// **BBToolTipType** 에 따라 Arrow의 위치가 배치됩니다. - func drawToolTipArrowShape(_ frame: CGRect, type: BBToolTipType, path: CGMutablePath) { - let margin: CGFloat = 16 - let arrowTipXPosition = type.configure.xPosition.rawValue * frame.width - let adjustedArrowTipXPosition = min(max(arrowTipXPosition, margin + type.configure.arrowWidth / 2), frame.width - margin - type.configure.arrowWidth / 2) - let arrowLeft = adjustedArrowTipXPosition - type.configure.arrowWidth / 2 - let arrowRight = adjustedArrowTipXPosition + type.configure.arrowWidth / 2 - - switch type { - case .contributor, .monthlyCalendar: - path.move(to: CGPoint(x: arrowLeft, y: type.configure.arrowHeight)) - path.addLine(to: CGPoint(x: adjustedArrowTipXPosition, y: 0)) - path.addLine(to: CGPoint(x: arrowRight, y: type.configure.arrowHeight)) - default: - path.move(to: CGPoint(x: arrowLeft, y: frame.height - type.configure.arrowHeight)) - path.addLine(to: CGPoint(x: adjustedArrowTipXPosition, y: frame.height)) - path.addLine(to: CGPoint(x: arrowRight, y: frame.height - type.configure.arrowHeight)) - } - } - - /// drawToolTipTopShape 메서드 실행 시 ToolTip의 **ContentShape** 영역들을 드로잉 하도록 실행합니다. - /// - /// Note: - 해당 메서드는 **BBToolTipVerticalPosition** 이 Top일 경우 실행합니다. - func drawToolTipTopShape(_ frame: CGRect, toolTipType: BBToolTipType, cornerRadius: CGFloat, path: CGMutablePath) { - path.addArc(tangent1End: CGPoint(x: frame.maxX, y: toolTipType.configure.arrowHeight), tangent2End: CGPoint(x: frame.maxX, y: frame.maxY + frame.height), radius: cornerRadius) - path.addArc(tangent1End: CGPoint(x: frame.maxX, y: frame.maxY), tangent2End: CGPoint(x: frame.minX, y: frame.maxY), radius: cornerRadius) - - path.addArc(tangent1End: CGPoint(x: frame.minX, y: frame.maxY), tangent2End: CGPoint(x: frame.minX, y: toolTipType.configure.arrowHeight), radius: cornerRadius) - path.addArc(tangent1End: CGPoint(x: frame.minX, y: toolTipType.configure.arrowHeight), tangent2End: CGPoint(x: frame.maxX, y: toolTipType.configure.arrowHeight), radius: cornerRadius) - } - - /// drawToolTipBottomShape 메서드 실행 시 ToolTip의 **ContentShape** 영역들을 드로잉 하도록 실행합니다. - /// - /// Note: - 해당 메서드는 **BBToolTipVerticalPosition** 이 Bottom일 경우 실행합니다. - func drawToolTipBottomShape(_ frame: CGRect, toolTipType: BBToolTipType, cornerRadius: CGFloat, path: CGMutablePath) { - path.addArc(tangent1End: CGPoint(x: frame.maxX, y: frame.height - toolTipType.configure.arrowHeight), tangent2End: CGPoint(x: frame.maxX, y: 0), radius: cornerRadius) - path.addArc(tangent1End: CGPoint(x: frame.maxX, y: 0), tangent2End: CGPoint(x: frame.minX, y: 0), radius: cornerRadius) - path.addArc(tangent1End: CGPoint(x: frame.minX, y: 0), tangent2End: CGPoint(x: frame.minX, y: frame.height - toolTipType.configure.arrowHeight), radius: cornerRadius) - path.addArc(tangent1End: CGPoint(x: frame.minX, y: frame.height - toolTipType.configure.arrowHeight), tangent2End: CGPoint(x: frame.maxX, y: frame.height - toolTipType.configure.arrowHeight), radius: cornerRadius) - } -} diff --git a/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBTextToolTipView.swift b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBTextToolTipView.swift new file mode 100644 index 000000000..84249a2cd --- /dev/null +++ b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBTextToolTipView.swift @@ -0,0 +1,106 @@ +// +// BBTextToolTipView.swift +// Core +// +// Created by 김도현 on 10/27/24. +// + +import UIKit + +import SnapKit +import Then + + +public class BBTextToolTipView: BBBaseToolTipView { + + private var contentLabel: BBLabel = BBLabel() + private let touchControl: UIControl = UIControl() + + public override init(toolTipType: BBToolTipType) { + super.init(toolTipType: toolTipType) + setupToolTipUI() + setupToolTipContent() + setupAutoLayount() + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + private func setupToolTipUI() { + addSubview(contentLabel) + if toolTipType == .contributor || toolTipType == .monthlyCalendar { + addTouchControl() + } + } + + private func setupToolTipContent() { + contentLabel.do { + $0.text = toolTipType.configure.contentText + $0.fontStyle = toolTipType.configure.font + $0.textAlignment = .center + $0.numberOfLines = 0 + $0.textColor = toolTipType.configure.foregroundColor + $0.sizeToFit() + } + + touchControl.do { + $0.frame = UIScreen.main.bounds + } + + self.do { + $0.backgroundColor = .clear + } + } + + private func setupAutoLayount() { + let position = toolTipType.configure.yPosition + let arrowHeight: CGFloat = toolTipType.configure.arrowHeight + let textPadding: CGFloat = 10 + + switch position { + case .bottom: + contentLabel.snp.makeConstraints { + $0.horizontalEdges.equalToSuperview().inset(16) + $0.bottom.equalToSuperview().inset((arrowHeight + textPadding)) + $0.top.equalToSuperview().inset(textPadding) + } + case .top: + contentLabel.snp.makeConstraints { + $0.horizontalEdges.equalToSuperview().inset(16) + $0.top.equalToSuperview().inset((arrowHeight + textPadding)) + $0.bottom.equalToSuperview().inset(textPadding) + } + } + } + + private func addTouchControl() { + + BBHelper.topMostController()?.view.addSubview(self.touchControl) + self.touchControl.addTarget(self, action: #selector(didTappedContainerView), for: .touchDown) + } + + @objc private func didTappedContainerView() { + self.touchesBeganHide() + } + + private func touchesBeganHide( + duration: TimeInterval = 0.3, + options: UIView.AnimationOptions = [.curveEaseInOut], + transform: CGAffineTransform = CGAffineTransform(scaleX: 0.1, y: 0.1), + alpha: CGFloat = 0 + ) { + UIView.animate(withDuration: duration, delay: 0, options: options, animations: { [weak self] in + guard let self = self else { return } + self.transform = transform + self.alpha = 0 + }, completion: { _ in + self.removeFromSuperview() + self.touchControl.removeFromSuperview() + self.transform = .identity + }) + + self.layoutIfNeeded() + } + +} diff --git a/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBThumbnailToolTipView.swift b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBThumbnailToolTipView.swift new file mode 100644 index 000000000..34b8ff82b --- /dev/null +++ b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBThumbnailToolTipView.swift @@ -0,0 +1,91 @@ +// +// BBThumbnailToolTipView.swift +// Core +// +// Created by 김도현 on 10/27/24. +// + +import UIKit + +import SnapKit +import Then + +public class BBThumbnailToolTipView: BBBaseToolTipView { + private let stackView: UIStackView = UIStackView() + private let contentLabel: BBLabel = BBLabel() + + public override init(toolTipType: BBToolTipType) { + super.init(toolTipType: toolTipType) + guard case let .waitingSurvivalImage(_, imageURLs) = toolTipType else { + return + } + setupToolTipUI() + setupToolTipContent() + setupAutoLayount() + setupThumbnailImageView(imageURL: imageURLs) + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + + public func setupToolTipUI() { + addSubviews(stackView, contentLabel) + } + + + public func setupAutoLayount() { + let arrowHeight: CGFloat = toolTipType.configure.arrowHeight + let textPadding: CGFloat = 10 + guard case let .waitingSurvivalImage(_, imageURLs) = toolTipType else { + return + } + + stackView.snp.makeConstraints { + $0.width.equalTo(24 * imageURLs.count) + $0.height.equalTo(24) + $0.left.equalToSuperview().inset(16) + $0.centerY.equalTo(contentLabel) + } + + + contentLabel.snp.makeConstraints { + $0.left.equalTo(stackView.snp.right).offset(6) + $0.right.equalToSuperview().inset(16) + $0.bottom.equalToSuperview().inset(arrowHeight + textPadding) + $0.top.equalToSuperview().inset(textPadding) + } + } + + public func setupToolTipContent() { + stackView.do { + $0.spacing = -4 + $0.distribution = .fillEqually + } + + contentLabel.do { + $0.text = toolTipType.configure.contentText + $0.fontStyle = toolTipType.configure.font + $0.textAlignment = .center + $0.numberOfLines = 0 + $0.textColor = toolTipType.configure.foregroundColor + $0.sizeToFit() + } + } + + + private func setupThumbnailImageView(imageURL: [URL]) { + imageURL.forEach { + let imageView: UIImageView = UIImageView(frame: .init(x: 0, y: 0, width: 20, height: 20)) + imageView.contentMode = .scaleAspectFill + imageView.layer.borderColor = UIColor.mainYellow.cgColor + imageView.layer.borderWidth = 2 + imageView.layer.cornerRadius = 10 + imageView.clipsToBounds = true + imageView.kf.setImage(with: $0) + stackView.addArrangedSubview(imageView) + } + } + +} diff --git a/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTip.swift b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTip.swift new file mode 100644 index 000000000..fe6b00aae --- /dev/null +++ b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTip.swift @@ -0,0 +1,77 @@ +// +// BBToolTip.swift +// Core +// +// Created by 김도현 on 10/27/24. +// + +import UIKit + +import SnapKit + +public final class BBToolTip: NSObject, BBComponentPresentable { + typealias Content = BBBaseToolTipView + + //MARK: Properties + public var contentView: BBBaseToolTipView? + public let superview: UIView? + public var toolTipStyle: BBToolTipType { + didSet { + contentView?.removeFromSuperview() + createToolTipContent(toolTipStyle) + + guard let superview else { return } + if let contentView = contentView { + superview.addSubview(contentView) + updateLayout() + contentView.layoutIfNeeded() + } + } + } + + + public init( + _ toolTipStyle: BBToolTipType = .activeCameraTime, + superView: UIView + ) { + self.toolTipStyle = toolTipStyle + self.superview = superView + super.init() + createToolTipContent(toolTipStyle) + } + + public func updateLayout() { + guard let superview else { + fatalError("SuperView not Created") + } + + switch toolTipStyle { + case .contributor, .monthlyCalendar: + + contentView?.snp.makeConstraints { + $0.top.equalTo(superview.snp.bottom) + $0.left.equalToSuperview().offset(20) + } + case .familyNameEdit: + contentView?.snp.makeConstraints { + $0.bottom.equalTo(superview.snp.top) + $0.left.equalToSuperview() + } + default: + contentView?.snp.makeConstraints { + $0.bottom.equalTo(superview.snp.top) + $0.centerX.equalToSuperview() + } + } + } + + + private func createToolTipContent(_ style: BBToolTipType) { + switch style { + case .waitingSurvivalImage: + self.contentView = BBThumbnailToolTipView(toolTipType: style) + default: + self.contentView = BBTextToolTipView(toolTipType: style) + } + } +} diff --git a/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTipType.swift b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTipType.swift index b628cd0a0..694a5e8ff 100644 --- a/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTipType.swift +++ b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTipType.swift @@ -17,7 +17,7 @@ public enum BBToolTipAction: String { /// BBToolTip의 Style을 설정하기 위한 Nested types입니다. /// 해당 **BBToolTipType** 을 통해 BBToolTip의 Layout을 구성합니다. -public enum BBToolTipType { +public enum BBToolTipType: Equatable { /// 홈 화면 inactive Camera Button State ToolTip Type case inactiveCameraTime /// 홈 화면 active Camera Button State ToolTip Type diff --git a/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTipView.swift b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTipView.swift deleted file mode 100644 index 949a48bb0..000000000 --- a/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTipView.swift +++ /dev/null @@ -1,202 +0,0 @@ -// -// BBToolTipView.swift -// Core -// -// Created by Kim dohyun on 9/13/24. -// - -import UIKit - -import DesignSystem -import Kingfisher -import SnapKit -import Then - - -public class BBThumbnailToolTipView: BBBaseToolTipView { - private let stackView: UIStackView = UIStackView() - - public override init(toolTipType: BBToolTipType) { - super.init(toolTipType: toolTipType) - guard case let .waitingSurvivalImage(_, imageURLs) = toolTipType else { - return - } - setupThumbnailImageView(imageURL: imageURLs) - } - - required init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - - - public override func setupToolTipUI() { - super.setupToolTipUI() - addSubview(stackView) - } - - - public override func setupAutoLayount() { - super.setupAutoLayount() - let arrowHeight: CGFloat = toolTipType.configure.arrowHeight - let textPadding: CGFloat = 10 - guard case let .waitingSurvivalImage(contentText, imageURLs) = toolTipType else { - return - } - - stackView.snp.makeConstraints { - $0.width.equalTo(24 * imageURLs.count) - $0.height.equalTo(24) - $0.left.equalToSuperview().inset(16) - $0.centerY.equalTo(contentLabel) - } - - - contentLabel.snp.makeConstraints { - $0.left.equalTo(stackView.snp.right).offset(22) - $0.right.equalToSuperview().inset(16) - $0.bottom.equalToSuperview().inset(arrowHeight + textPadding) - $0.top.equalToSuperview().inset(textPadding) - } - - - } - - public override func setupToolTipContent() { - super.setupToolTipContent() - stackView.do { - $0.spacing = -4 - $0.distribution = .fillEqually - } - } - - - private func setupThumbnailImageView(imageURL: [URL]) { - imageURL.forEach { - let imageView: UIImageView = UIImageView(frame: .init(x: 0, y: 0, width: 20, height: 20)) - imageView.contentMode = .scaleAspectFill - imageView.layer.borderColor = UIColor.mainYellow.cgColor - imageView.layer.borderWidth = 2 - imageView.layer.cornerRadius = 10 - imageView.clipsToBounds = true - imageView.kf.setImage(with: $0) - stackView.addArrangedSubview(imageView) - } - } - -} - - -public class BBBaseToolTipView: UIView, BBDrawable { - - public private(set) var toolTipType: BBToolTipType { - didSet { - setupToolTipContent() - setupAutoLayount() - } - } - public private(set) var contentLabel: BBLabel = BBLabel() - - public init(toolTipType: BBToolTipType) { - self.toolTipType = toolTipType - super.init(frame: .zero) - } - - required init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - - public override func draw(_ rect: CGRect) { - super.draw(rect) - guard let context = UIGraphicsGetCurrentContext() else { return } - context.saveGState() - drawToolTip(rect, type: toolTipType, context: context) - context.restoreGState() - } - - public func setupToolTipUI() { - addSubview(contentLabel) - } - - public func setupToolTipContent() { - contentLabel.do { - $0.text = toolTipType.configure.contentText - $0.fontStyle = toolTipType.configure.font - $0.textAlignment = .center - $0.numberOfLines = 0 - $0.textColor = toolTipType.configure.foregroundColor - $0.sizeToFit() - } - - self.do { - $0.backgroundColor = .clear - } - } - - public func setupAutoLayount() { - let arrowHeight: CGFloat = toolTipType.configure.arrowHeight - let textPadding: CGFloat = 10 - contentLabel.snp.makeConstraints { - $0.horizontalEdges.equalToSuperview().inset(16) - $0.top.equalToSuperview().inset(arrowHeight + textPadding) - $0.bottom.equalToSuperview().inset(textPadding) - } - } -} - - -public final class BBToolTip: AnyObject, BBComponentPresentable { - - - - public var contentView: UIView? - private let superview: UIView? - public var configure: BBToolTipType { - didSet { - switch configure { - case .waitingSurvivalImage: - contentView = createThumbnailToolTipView() - default: - contentView = createTextToolTipView() - } - } - } - - - public init(configure: BBToolTipType, superView: UIView) { - self.configure = configure - self.superview = superView - } - - private func updateConstraints() { - guard let superview else { - fatalError("SuperView not Created") - } - - switch configure { - case .contributor, .monthlyCalendar: - contentView?.snp.makeConstraints { - $0.top.equalTo(superview.snp.bottom) - $0.left.equalToSuperview().offset(20) - } - case .familyNameEdit: - contentView?.snp.makeConstraints { - $0.bottom.equalTo(superview.snp.top) - $0.left.equalToSuperview() - } - default: - contentView?.snp.makeConstraints { - $0.bottom.equalTo(superview.snp.top) - $0.centerX.equalToSuperview() - } - } - } - - private func createTextToolTipView() -> BBBaseToolTipView { - return BBBaseToolTipView(toolTipType: configure) - } - - private func createThumbnailToolTipView() -> BBThumbnailToolTipView { - return BBThumbnailToolTipView(toolTipType: configure) - } - -} From b3ca702b664bb19f67d42cc8c5a3b1c4b009fbbe Mon Sep 17 00:00:00 2001 From: Do-hyun-Kim Date: Sun, 27 Oct 2024 22:33:25 +0900 Subject: [PATCH 3/9] =?UTF-8?q?fix:=20BBToolTip=20createToolTip=20Method?= =?UTF-8?q?=20parameter=20completionHandler=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Bibbi/BBCommons/BBToolTip/BBToolTip.swift | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTip.swift b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTip.swift index fe6b00aae..2b0776755 100644 --- a/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTip.swift +++ b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTip.swift @@ -18,13 +18,14 @@ public final class BBToolTip: NSObject, BBComponentPresentable { public var toolTipStyle: BBToolTipType { didSet { contentView?.removeFromSuperview() - createToolTipContent(toolTipStyle) - guard let superview else { return } - if let contentView = contentView { + createToolTipContent(toolTipStyle) { [weak self] in + guard let superview = self?.superview, + let contentView = self?.contentView + else { return } superview.addSubview(contentView) - updateLayout() - contentView.layoutIfNeeded() + self?.updateLayout() + self?.contentView?.layoutIfNeeded() } } } @@ -65,13 +66,14 @@ public final class BBToolTip: NSObject, BBComponentPresentable { } } - - private func createToolTipContent(_ style: BBToolTipType) { + private func createToolTipContent(_ style: BBToolTipType, completion: (() -> Void)? = nil) { switch style { case .waitingSurvivalImage: self.contentView = BBThumbnailToolTipView(toolTipType: style) default: self.contentView = BBTextToolTipView(toolTipType: style) } + + completion?() } } From 39b45a9f90e9d0d643a1bca2a39c99a23c421681 Mon Sep 17 00:00:00 2001 From: Do-hyun-Kim Date: Sun, 27 Oct 2024 23:51:29 +0900 Subject: [PATCH 4/9] =?UTF-8?q?feat:=20BBToolTip=20=EA=B4=80=EB=A0=A8=20?= =?UTF-8?q?=EC=97=90=EB=9F=AC=EC=B2=98=EB=A6=AC=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20-=20ToolTip=20=EA=B4=80=EB=A0=A8=20?= =?UTF-8?q?=EC=A3=BC=EC=84=9D=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Bibbi/BBCommons/BBToolTip/BBAnimatable.swift | 8 ++++---- .../Bibbi/BBCommons/BBToolTip/BBBaseToolTipView.swift | 11 +++++++---- .../Bibbi/BBCommons/BBToolTip/BBTextToolTipView.swift | 4 +++- .../BBCommons/BBToolTip/BBThumbnailToolTipView.swift | 4 ++++ .../Sources/Bibbi/BBCommons/BBToolTip/BBToolTip.swift | 9 +++++---- .../Bibbi/BBCommons/BBToolTip/BBToolTipType.swift | 6 ------ 6 files changed, 23 insertions(+), 19 deletions(-) diff --git a/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBAnimatable.swift b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBAnimatable.swift index be55a44b0..2fa2e7078 100644 --- a/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBAnimatable.swift +++ b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBAnimatable.swift @@ -16,7 +16,7 @@ public typealias BBComponentPresentable = BBComponentShowable & BBComponentClosa /// **Animate**, **CGAffineTransform**, **CABasicAnimation** 을 활용한 Animation 메서드를 정의하는 Protocol 입니다. /// 해당 **BBComponentShowable** 프로토콜은 Component 객체를 보여주는 애니메이션을 정의하는 프로토콜입니다. public protocol BBComponentShowable { - func showPopover(duration: TimeInterval, options: UIView.AnimationOptions, transform: CGAffineTransform, alpha: CGFloat) + func show(duration: TimeInterval, options: UIView.AnimationOptions, transform: CGAffineTransform, alpha: CGFloat) } /// **Animate**, **CGAffineTransform**, **CABasicAnimation** 을 활용한 Animation 메서드를 정의하는 Protocol 입니다. @@ -29,10 +29,11 @@ public protocol BBComponentClosable { //MARK: - Extensions public extension BBComponentShowable where Self: BBToolTip { - func showPopover(duration: TimeInterval = 0.3, options: UIView.AnimationOptions = [.curveEaseInOut], transform: CGAffineTransform = CGAffineTransform(scaleX: 0.1, y: 0.1), alpha: CGFloat = 1) { + func show(duration: TimeInterval = 0.3, options: UIView.AnimationOptions = [.curveEaseInOut], transform: CGAffineTransform = CGAffineTransform(scaleX: 0.1, y: 0.1), alpha: CGFloat = 1) { guard let contentView else { - fatalError("contentView is Not Created") + assertionFailure("No contentView assigned to BBToolTip") + return } superview?.addSubview(contentView) @@ -63,7 +64,6 @@ public extension BBComponentClosable where Self: BBToolTip { self?.contentView?.transform = .identity }) - print("hide popover: \(self.contentView)") self.contentView?.layoutIfNeeded() } } diff --git a/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBBaseToolTipView.swift b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBBaseToolTipView.swift index c384ba534..66979570e 100644 --- a/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBBaseToolTipView.swift +++ b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBBaseToolTipView.swift @@ -11,8 +11,10 @@ import SnapKit import Then public class BBBaseToolTipView: UIView { + // MARK: - Properties public var toolTipType: BBToolTipType + // MARK: - Intializer public init(toolTipType: BBToolTipType) { self.toolTipType = toolTipType super.init(frame: .zero) @@ -30,7 +32,8 @@ public class BBBaseToolTipView: UIView { context.restoreGState() } - func drawToolTip(_ frame: CGRect, type: BBToolTipType, context: CGContext) { + // MARK: - Configure + private func drawToolTip(_ frame: CGRect, type: BBToolTipType, context: CGContext) { let toolTipPath = CGMutablePath() switch type { @@ -48,7 +51,7 @@ public class BBBaseToolTipView: UIView { context.fillPath() } - func drawToolTipArrowShape(_ frame: CGRect, type: BBToolTipType, path: CGMutablePath) { + private func drawToolTipArrowShape(_ frame: CGRect, type: BBToolTipType, path: CGMutablePath) { let margin: CGFloat = 16 let arrowTipXPosition = type.configure.xPosition.rawValue * frame.width let adjustedArrowTipXPosition = min(max(arrowTipXPosition, margin + type.configure.arrowWidth / 2), frame.width - margin - type.configure.arrowWidth / 2) @@ -67,7 +70,7 @@ public class BBBaseToolTipView: UIView { } } - func drawToolTipTopShape(_ frame: CGRect, toolTipType: BBToolTipType, cornerRadius: CGFloat, path: CGMutablePath) { + private func drawToolTipTopShape(_ frame: CGRect, toolTipType: BBToolTipType, cornerRadius: CGFloat, path: CGMutablePath) { path.addArc(tangent1End: CGPoint(x: frame.maxX, y: toolTipType.configure.arrowHeight), tangent2End: CGPoint(x: frame.maxX, y: frame.maxY + frame.height), radius: cornerRadius) path.addArc(tangent1End: CGPoint(x: frame.maxX, y: frame.maxY), tangent2End: CGPoint(x: frame.minX, y: frame.maxY), radius: cornerRadius) @@ -75,7 +78,7 @@ public class BBBaseToolTipView: UIView { path.addArc(tangent1End: CGPoint(x: frame.minX, y: toolTipType.configure.arrowHeight), tangent2End: CGPoint(x: frame.maxX, y: toolTipType.configure.arrowHeight), radius: cornerRadius) } - func drawToolTipBottomShape(_ frame: CGRect, toolTipType: BBToolTipType, cornerRadius: CGFloat, path: CGMutablePath) { + private func drawToolTipBottomShape(_ frame: CGRect, toolTipType: BBToolTipType, cornerRadius: CGFloat, path: CGMutablePath) { path.addArc(tangent1End: CGPoint(x: frame.maxX, y: frame.height - toolTipType.configure.arrowHeight), tangent2End: CGPoint(x: frame.maxX, y: 0), radius: cornerRadius) path.addArc(tangent1End: CGPoint(x: frame.maxX, y: 0), tangent2End: CGPoint(x: frame.minX, y: 0), radius: cornerRadius) path.addArc(tangent1End: CGPoint(x: frame.minX, y: 0), tangent2End: CGPoint(x: frame.minX, y: frame.height - toolTipType.configure.arrowHeight), radius: cornerRadius) diff --git a/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBTextToolTipView.swift b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBTextToolTipView.swift index 84249a2cd..d701aa34c 100644 --- a/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBTextToolTipView.swift +++ b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBTextToolTipView.swift @@ -12,10 +12,11 @@ import Then public class BBTextToolTipView: BBBaseToolTipView { - + // MARK: - Properties private var contentLabel: BBLabel = BBLabel() private let touchControl: UIControl = UIControl() + // MARK: - Intializer public override init(toolTipType: BBToolTipType) { super.init(toolTipType: toolTipType) setupToolTipUI() @@ -27,6 +28,7 @@ public class BBTextToolTipView: BBBaseToolTipView { fatalError("init(coder:) has not been implemented") } + // MARK: - Configure private func setupToolTipUI() { addSubview(contentLabel) if toolTipType == .contributor || toolTipType == .monthlyCalendar { diff --git a/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBThumbnailToolTipView.swift b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBThumbnailToolTipView.swift index 34b8ff82b..d36b92b3d 100644 --- a/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBThumbnailToolTipView.swift +++ b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBThumbnailToolTipView.swift @@ -11,9 +11,12 @@ import SnapKit import Then public class BBThumbnailToolTipView: BBBaseToolTipView { + // MARK: - Properties private let stackView: UIStackView = UIStackView() private let contentLabel: BBLabel = BBLabel() + + // MARK: - Intializer public override init(toolTipType: BBToolTipType) { super.init(toolTipType: toolTipType) guard case let .waitingSurvivalImage(_, imageURLs) = toolTipType else { @@ -30,6 +33,7 @@ public class BBThumbnailToolTipView: BBBaseToolTipView { } + // MARK: - Configure public func setupToolTipUI() { addSubviews(stackView, contentLabel) } diff --git a/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTip.swift b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTip.swift index 2b0776755..48f5be000 100644 --- a/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTip.swift +++ b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTip.swift @@ -10,9 +10,8 @@ import UIKit import SnapKit public final class BBToolTip: NSObject, BBComponentPresentable { - typealias Content = BBBaseToolTipView - //MARK: Properties + // MARK: - Properties public var contentView: BBBaseToolTipView? public let superview: UIView? public var toolTipStyle: BBToolTipType { @@ -30,7 +29,7 @@ public final class BBToolTip: NSObject, BBComponentPresentable { } } - + // MARK: - Intializer public init( _ toolTipStyle: BBToolTipType = .activeCameraTime, superView: UIView @@ -41,9 +40,11 @@ public final class BBToolTip: NSObject, BBComponentPresentable { createToolTipContent(toolTipStyle) } + // MARK: - Configure public func updateLayout() { guard let superview else { - fatalError("SuperView not Created") + assertionFailure("No superview assigned to BBToolTip") + return } switch toolTipStyle { diff --git a/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTipType.swift b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTipType.swift index 694a5e8ff..4cabc0c7d 100644 --- a/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTipType.swift +++ b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTipType.swift @@ -9,12 +9,6 @@ import UIKit import DesignSystem - -public enum BBToolTipAction: String { - case show - case hide -} - /// BBToolTip의 Style을 설정하기 위한 Nested types입니다. /// 해당 **BBToolTipType** 을 통해 BBToolTip의 Layout을 구성합니다. public enum BBToolTipType: Equatable { From 5b38376768ad7b2681e6fc7e3a004fc0ee66b5c5 Mon Sep 17 00:00:00 2001 From: Do-hyun-Kim Date: Mon, 28 Oct 2024 20:51:30 +0900 Subject: [PATCH 5/9] =?UTF-8?q?feat:=20BBToolTipConfiguration=20maxWidth,?= =?UTF-8?q?=20maxHeight=20Properties=20=EC=B6=94=EA=B0=80=20-=20BBToolTip?= =?UTF-8?q?=20Layout=EC=9D=84=20frame=20=EA=B8=B0=EB=B0=98=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Bibbi/BBCommons/BBToolTip/BBToolTip.swift | 47 ++++++++++++------- .../BBToolTip/BBToolTipConfiguration.swift | 28 +++++++---- 2 files changed, 48 insertions(+), 27 deletions(-) diff --git a/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTip.swift b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTip.swift index 48f5be000..ca958c5e3 100644 --- a/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTip.swift +++ b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTip.swift @@ -17,14 +17,12 @@ public final class BBToolTip: NSObject, BBComponentPresentable { public var toolTipStyle: BBToolTipType { didSet { contentView?.removeFromSuperview() - createToolTipContent(toolTipStyle) { [weak self] in guard let superview = self?.superview, let contentView = self?.contentView else { return } superview.addSubview(contentView) self?.updateLayout() - self?.contentView?.layoutIfNeeded() } } } @@ -42,30 +40,45 @@ public final class BBToolTip: NSObject, BBComponentPresentable { // MARK: - Configure public func updateLayout() { - guard let superview else { - assertionFailure("No superview assigned to BBToolTip") + guard let superview = superview, let contentView = contentView else { + assertionFailure("No superview or contentView assigned to BBToolTip") return } + superview.layoutIfNeeded() + + contentView.frame.size = CGSize(width: toolTipStyle.configure.maxWidth, height: toolTipStyle.configure.maxHeight) + + + let superviewCenterX = superview.bounds.midX + let contentViewWidth = contentView.frame.width + let arrowTipXPosition = toolTipStyle.configure.xPosition.rawValue * contentViewWidth + + let horizontalOffset = superviewCenterX - arrowTipXPosition + + var contentViewFrame = contentView.frame switch toolTipStyle { case .contributor, .monthlyCalendar: - - contentView?.snp.makeConstraints { - $0.top.equalTo(superview.snp.bottom) - $0.left.equalToSuperview().offset(20) - } + contentViewFrame.origin = CGPoint( + x: horizontalOffset, + y: superview.bounds.origin.y + superview.frame.height + ) case .familyNameEdit: - contentView?.snp.makeConstraints { - $0.bottom.equalTo(superview.snp.top) - $0.left.equalToSuperview() - } + contentViewFrame.origin = CGPoint( + x: horizontalOffset + superview.bounds.midX, + y: superview.bounds.minY - contentView.frame.height + ) default: - contentView?.snp.makeConstraints { - $0.bottom.equalTo(superview.snp.top) - $0.centerX.equalToSuperview() - } + contentViewFrame.origin = CGPoint( + x: horizontalOffset, + y: superview.bounds.minY - contentView.frame.height + ) } + + contentView.frame = contentViewFrame + print("contentView frame: \(contentView.frame)") } + private func createToolTipContent(_ style: BBToolTipType, completion: (() -> Void)? = nil) { switch style { diff --git a/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTipConfiguration.swift b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTipConfiguration.swift index c788a78db..5f9a84282 100644 --- a/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTipConfiguration.swift +++ b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTipConfiguration.swift @@ -12,23 +12,27 @@ import DesignSystem /// BBToolTip에 (UI, Width, Height) Properties를 설정하기 위한 구조체입니다. public struct BBToolTipConfiguration { /// ToolTip Corner Radius - public var cornerRadius: CGFloat + public let cornerRadius: CGFloat /// TooTip TextFont Foreground Color - public var foregroundColor: UIColor + public let foregroundColor: UIColor /// TooTip Background Color - public var backgroundColor: UIColor + public let backgroundColor: UIColor /// ToolTip Arrow YPosition - public var yPosition: BBToolTipVerticalPosition + public let yPosition: BBToolTipVerticalPosition /// ToolTip Arrow XPosition - public var xPosition: BBToolTipHorizontalPosition + public let xPosition: BBToolTipHorizontalPosition /// ToolTip Text Font - public var font: BBFontStyle + public let font: BBFontStyle /// ToolTip Content Text - public var contentText: String + public let contentText: String /// ToolTip Arrow Width - public var arrowWidth: CGFloat + public let arrowWidth: CGFloat /// ToolTip Arrow Height - public var arrowHeight: CGFloat + public let arrowHeight: CGFloat + + public let maxWidth: CGFloat + + public let maxHeight: CGFloat public init( cornerRadius: CGFloat = 12, @@ -39,7 +43,9 @@ public struct BBToolTipConfiguration { font: BBFontStyle = .body2Regular, contentText: String = "", arrowWidth: CGFloat = 15, - arrowHeight: CGFloat = 12 + arrowHeight: CGFloat = 12, + maxWidth: CGFloat = 222, + maxHeight: CGFloat = 40 ) { self.cornerRadius = cornerRadius self.foregroundColor = foregroundColor @@ -50,5 +56,7 @@ public struct BBToolTipConfiguration { self.contentText = contentText self.arrowWidth = arrowWidth self.arrowHeight = arrowHeight + self.maxWidth = maxWidth + self.maxHeight = maxHeight } } From 1ab3d359429be0fda045618a9f024044bbfb0bb0 Mon Sep 17 00:00:00 2001 From: Do-hyun-Kim Date: Mon, 28 Oct 2024 21:37:27 +0900 Subject: [PATCH 6/9] =?UTF-8?q?feat:=20BBTextToolTipView,=20BBThumbnailToo?= =?UTF-8?q?lTipView=20Width,=20height=20=EB=8F=99=EC=A0=81=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EC=A0=95=EC=9D=98=ED=95=98=EA=B8=B0=20=EC=9C=84?= =?UTF-8?q?=ED=95=B4=20intrinsicContentSize=20=EC=9E=AC=EC=A0=95=EC=9D=98?= =?UTF-8?q?=20-=20BBTooltip=20contentView=20ContentView=20intrinsicContent?= =?UTF-8?q?Size=20=EA=B8=B0=EB=B0=98=EC=9C=BC=EB=A1=9C=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=88=98=EC=A0=95=20-=20BBToolTipConfiguration=20m?= =?UTF-8?q?axWidth,=20maxHeight=20Properties=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BBCommons/BBToolTip/BBTextToolTipView.swift | 7 +++++++ .../BBToolTip/BBThumbnailToolTipView.swift | 16 ++++++++++++++++ .../Bibbi/BBCommons/BBToolTip/BBToolTip.swift | 5 ++--- .../BBToolTip/BBToolTipConfiguration.swift | 10 +--------- 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBTextToolTipView.swift b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBTextToolTipView.swift index d701aa34c..7e4ffa0d5 100644 --- a/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBTextToolTipView.swift +++ b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBTextToolTipView.swift @@ -17,6 +17,13 @@ public class BBTextToolTipView: BBBaseToolTipView { private let touchControl: UIControl = UIControl() // MARK: - Intializer + public override var intrinsicContentSize: CGSize { + let contentWidth = contentLabel.intrinsicContentSize.width + 32 + let contentHeight = contentLabel.intrinsicContentSize.height + toolTipType.configure.arrowHeight + 20 + return CGSize(width: contentWidth, height: contentHeight) + } + + public override init(toolTipType: BBToolTipType) { super.init(toolTipType: toolTipType) setupToolTipUI() diff --git a/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBThumbnailToolTipView.swift b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBThumbnailToolTipView.swift index d36b92b3d..d58e4f203 100644 --- a/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBThumbnailToolTipView.swift +++ b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBThumbnailToolTipView.swift @@ -17,6 +17,18 @@ public class BBThumbnailToolTipView: BBBaseToolTipView { // MARK: - Intializer + public override var intrinsicContentSize: CGSize { + guard case let .waitingSurvivalImage(_, imageURLs) = toolTipType else { + return .zero + } + let thumbnailWidth = CGFloat(24 * imageURLs.count) + let labelWidth = contentLabel.intrinsicContentSize.width + let contentWidth = thumbnailWidth + labelWidth + 38 + let contentHeight = max(stackView.intrinsicContentSize.height, contentLabel.intrinsicContentSize.height) + toolTipType.configure.arrowHeight + 20 + + return CGSize(width: contentWidth, height: contentHeight) + } + public override init(toolTipType: BBToolTipType) { super.init(toolTipType: toolTipType) guard case let .waitingSurvivalImage(_, imageURLs) = toolTipType else { @@ -76,6 +88,10 @@ public class BBThumbnailToolTipView: BBBaseToolTipView { $0.textColor = toolTipType.configure.foregroundColor $0.sizeToFit() } + + self.do { + $0.backgroundColor = .clear + } } diff --git a/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTip.swift b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTip.swift index ca958c5e3..817ab4b26 100644 --- a/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTip.swift +++ b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTip.swift @@ -46,9 +46,9 @@ public final class BBToolTip: NSObject, BBComponentPresentable { } superview.layoutIfNeeded() - - contentView.frame.size = CGSize(width: toolTipStyle.configure.maxWidth, height: toolTipStyle.configure.maxHeight) + contentView.layoutIfNeeded() + contentView.frame.size = contentView.intrinsicContentSize let superviewCenterX = superview.bounds.midX let contentViewWidth = contentView.frame.width @@ -76,7 +76,6 @@ public final class BBToolTip: NSObject, BBComponentPresentable { } contentView.frame = contentViewFrame - print("contentView frame: \(contentView.frame)") } diff --git a/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTipConfiguration.swift b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTipConfiguration.swift index 5f9a84282..6f4cfd0f2 100644 --- a/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTipConfiguration.swift +++ b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTipConfiguration.swift @@ -30,10 +30,6 @@ public struct BBToolTipConfiguration { /// ToolTip Arrow Height public let arrowHeight: CGFloat - public let maxWidth: CGFloat - - public let maxHeight: CGFloat - public init( cornerRadius: CGFloat = 12, foregroundColor: UIColor = .bibbiBlack, @@ -43,9 +39,7 @@ public struct BBToolTipConfiguration { font: BBFontStyle = .body2Regular, contentText: String = "", arrowWidth: CGFloat = 15, - arrowHeight: CGFloat = 12, - maxWidth: CGFloat = 222, - maxHeight: CGFloat = 40 + arrowHeight: CGFloat = 12 ) { self.cornerRadius = cornerRadius self.foregroundColor = foregroundColor @@ -56,7 +50,5 @@ public struct BBToolTipConfiguration { self.contentText = contentText self.arrowWidth = arrowWidth self.arrowHeight = arrowHeight - self.maxWidth = maxWidth - self.maxHeight = maxHeight } } From ff128b6535366b498b020a9c9e74a140a36ffe14 Mon Sep 17 00:00:00 2001 From: Do-hyun-Kim Date: Tue, 29 Oct 2024 23:56:34 +0900 Subject: [PATCH 7/9] =?UTF-8?q?fix:=20BBDrawable=20Protocol=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0=20-=20BBToolTip=20property,=20Intializer=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Bibbi/BBCommons/BBToolTip/BBDrawable.swift | 17 ----------------- .../Bibbi/BBCommons/BBToolTip/BBToolTip.swift | 6 ++---- 2 files changed, 2 insertions(+), 21 deletions(-) delete mode 100644 14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBDrawable.swift diff --git a/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBDrawable.swift b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBDrawable.swift deleted file mode 100644 index b6c9a4a61..000000000 --- a/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBDrawable.swift +++ /dev/null @@ -1,17 +0,0 @@ -// -// BBDrawable.swift -// Core -// -// Created by Kim dohyun on 9/19/24. -// - -import UIKit - -/// **UIBezierPath**, ** CALayer**, **CGMutablePath**을 활용한 draw 메서드를 정의하는 Protocol입니다. -protocol BBDrawable { - func drawToolTip(_ frame: CGRect, type: BBToolTipType, context: CGContext) - func drawToolTipArrowShape(_ frame: CGRect, type: BBToolTipType, path: CGMutablePath) - func drawToolTipBottomShape(_ frame: CGRect, toolTipType: BBToolTipType, cornerRadius: CGFloat, path: CGMutablePath) - func drawToolTipTopShape(_ frame: CGRect, toolTipType: BBToolTipType, cornerRadius: CGFloat, path: CGMutablePath) -} - diff --git a/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTip.swift b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTip.swift index 817ab4b26..4ff293f02 100644 --- a/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTip.swift +++ b/14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBToolTip.swift @@ -13,7 +13,7 @@ public final class BBToolTip: NSObject, BBComponentPresentable { // MARK: - Properties public var contentView: BBBaseToolTipView? - public let superview: UIView? + public var superview: UIView? public var toolTipStyle: BBToolTipType { didSet { contentView?.removeFromSuperview() @@ -29,11 +29,9 @@ public final class BBToolTip: NSObject, BBComponentPresentable { // MARK: - Intializer public init( - _ toolTipStyle: BBToolTipType = .activeCameraTime, - superView: UIView + _ toolTipStyle: BBToolTipType = .activeCameraTime ) { self.toolTipStyle = toolTipStyle - self.superview = superView super.init() createToolTipContent(toolTipStyle) } From 46021702ddcba97b51ed64fc47cf1a0ee5caa2f3 Mon Sep 17 00:00:00 2001 From: Do-hyun-Kim Date: Wed, 30 Oct 2024 14:59:38 +0900 Subject: [PATCH 8/9] =?UTF-8?q?fix:=20MemoriesCalendarPageTitleView=20?= =?UTF-8?q?=EA=B8=B0=EC=A1=B4=20TooltipView=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20-=20BBTextToolTipView=20TouchControl=20?= =?UTF-8?q?=ED=81=B4=EB=A6=AD=EC=8B=9C=20Tooltip=20=EC=82=AC=EB=9D=BC?= =?UTF-8?q?=EC=A7=80=EB=8A=94=20=EC=95=A0=EB=8B=88=EB=A9=94=EC=9D=B4?= =?UTF-8?q?=EC=85=98=20=EB=A1=9C=EC=A7=81=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../View/MemoriesCalendarPageTitleView.swift | 19 ++++------ .../BBToolTip/BBTextToolTipView.swift | 38 ------------------- 2 files changed, 8 insertions(+), 49 deletions(-) diff --git a/14th-team5-iOS/App/Sources/Presentation/Calendar/View/MemoriesCalendarPageTitleView.swift b/14th-team5-iOS/App/Sources/Presentation/Calendar/View/MemoriesCalendarPageTitleView.swift index 4c550a018..2f920c5ac 100644 --- a/14th-team5-iOS/App/Sources/Presentation/Calendar/View/MemoriesCalendarPageTitleView.swift +++ b/14th-team5-iOS/App/Sources/Presentation/Calendar/View/MemoriesCalendarPageTitleView.swift @@ -21,7 +21,7 @@ final public class MemoriesCalendarPageTitleView: BaseView Date: Fri, 20 Dec 2024 00:36:52 +0900 Subject: [PATCH 9/9] =?UTF-8?q?fix:=20BBAnimatable,=20BBTextToolTipView,?= =?UTF-8?q?=20BBThumbnailToolTipView,=20BBToolTIpView=20=EC=BD=94=EB=93=9C?= =?UTF-8?q?=EB=A6=AC=EB=B7=B0=20=EB=B0=98=EC=98=81=20-=20ManagementTableHe?= =?UTF-8?q?aderView=20ToolTipView=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../View/MemoriesCalendarPageTitleView.swift | 6 +---- .../ManagementTableHeaderReactor.swift | 27 ++++++++++++++++--- .../View/ManagementTableHeaderView.swift | 17 +++++++++++- .../BBCommons/BBToolTip/BBAnimatable.swift | 12 ++++----- .../BBToolTip/BBTextToolTipView.swift | 4 +-- .../BBToolTip/BBThumbnailToolTipView.swift | 4 +-- .../Bibbi/BBCommons/BBToolTip/BBToolTip.swift | 4 +++ 7 files changed, 54 insertions(+), 20 deletions(-) diff --git a/14th-team5-iOS/App/Sources/Presentation/Calendar/View/MemoriesCalendarPageTitleView.swift b/14th-team5-iOS/App/Sources/Presentation/Calendar/View/MemoriesCalendarPageTitleView.swift index 2f920c5ac..f13c3200a 100644 --- a/14th-team5-iOS/App/Sources/Presentation/Calendar/View/MemoriesCalendarPageTitleView.swift +++ b/14th-team5-iOS/App/Sources/Presentation/Calendar/View/MemoriesCalendarPageTitleView.swift @@ -47,10 +47,7 @@ final public class MemoriesCalendarPageTitleView: BaseView Observable { + switch action { + case .didTappedToolTipButton: + return .just(.setToolTipHidden(!currentState.isHidden)) + } + } + + public func reduce(state: State, mutation: Mutation) -> State { + var newState = state + switch mutation { + case let .setToolTipHidden(isHidden): + newState.isHidden = isHidden + } + return newState + } } diff --git a/14th-team5-iOS/App/Sources/Presentation/Management/View/ManagementTableHeaderView.swift b/14th-team5-iOS/App/Sources/Presentation/Management/View/ManagementTableHeaderView.swift index e1c9fd2d9..680d5662f 100644 --- a/14th-team5-iOS/App/Sources/Presentation/Management/View/ManagementTableHeaderView.swift +++ b/14th-team5-iOS/App/Sources/Presentation/Management/View/ManagementTableHeaderView.swift @@ -20,7 +20,7 @@ public final class ManagementTableHeaderView: BaseView