-
Notifications
You must be signed in to change notification settings - Fork 5
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
feat: BBToolTip Action 처리 및 마이그레이션 작업 해요 #693
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a75fc9f
feat: BBBaseToolTipView, BBThumbnailToolTipView 추가
Do-hyun-Kim 5d324e3
feat: BBTextToolTipView, BBThumbnailToolTipView 모듈 분리
Do-hyun-Kim b3ca702
fix: BBToolTip createToolTip Method parameter completionHandler 추가
Do-hyun-Kim 39b45a9
feat: BBToolTip 관련 에러처리 로직 수정
Do-hyun-Kim 5b38376
feat: BBToolTipConfiguration maxWidth, maxHeight Properties 추가
Do-hyun-Kim 1ab3d35
feat: BBTextToolTipView, BBThumbnailToolTipView Width, height 동적으로 정의…
Do-hyun-Kim ff128b6
fix: BBDrawable Protocol 제거
Do-hyun-Kim fe22a7d
Merge branch 'develop' of https://github.com/depromeet/14th-team5-iOS…
Do-hyun-Kim 4602170
fix: MemoriesCalendarPageTitleView 기존 TooltipView 로직 수정
Do-hyun-Kim d873e2a
Merge branch 'develop' of https://github.com/depromeet/14th-team5-iOS…
Do-hyun-Kim 2ce2660
fix: BBAnimatable, BBTextToolTipView, BBThumbnailToolTipView, BBToolT…
Do-hyun-Kim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,39 @@ | ||
// | ||
// BBDrawable.swift | ||
// BBBaseToolTipView.swift | ||
// Core | ||
// | ||
// Created by Kim dohyun on 9/19/24. | ||
// Created by 김도현 on 10/27/24. | ||
// | ||
|
||
import UIKit | ||
|
||
/// **UIBezierPath**, ** CALayer**, **CGMutablePath**을 활용한 draw 메서드를 정의하는 Protocol입니다. | ||
protocol BBDrawable { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 요거 없앤 이유가 있나영? 결국 메서드들은 쓰는 . 것같은뎅..?! |
||
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) | ||
} | ||
|
||
import SnapKit | ||
import Then | ||
|
||
extension BBDrawable { | ||
public class BBBaseToolTipView: UIView { | ||
// MARK: - Properties | ||
public var toolTipType: BBToolTipType | ||
|
||
// MARK: - Intializer | ||
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() | ||
} | ||
|
||
/// drawToolTip 메서드 호출 시 **BBToolTipType** 에 해당하는 ToolTip Layout을 **CGContext** 내에서 드로잉 하는 메서드입니다. | ||
/// | ||
/// drawToolTip에 frame은 UIView의 **draw(_: )** 메서드에서 호출되고 있습니다. | ||
/// ToolTip Layout을 변경할 경우 **setNeedsDisplay** 메서드를 호출하시면 됩니다. | ||
func drawToolTip(_ frame: CGRect, type: BBToolTipType, context: CGContext) { | ||
// MARK: - Configure | ||
private func drawToolTip(_ frame: CGRect, type: BBToolTipType, context: CGContext) { | ||
let toolTipPath = CGMutablePath() | ||
|
||
switch type { | ||
|
@@ -40,13 +50,10 @@ extension BBDrawable { | |
context.setFillColor(type.configure.backgroundColor.cgColor) | ||
context.fillPath() | ||
} | ||
|
||
/// drawToolTipArrowShape 메서드 호출 시 ToolTip에 Arrow 모양을 드로잉 하도록 실행합니다. | ||
/// | ||
/// **BBToolTipType** 에 따라 Arrow의 위치가 배치됩니다. | ||
func drawToolTipArrowShape(_ frame: CGRect, type: BBToolTipType, path: CGMutablePath) { | ||
|
||
private 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 | ||
|
@@ -62,25 +69,20 @@ extension BBDrawable { | |
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) { | ||
|
||
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) | ||
|
||
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) { | ||
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) | ||
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) | ||
} | ||
|
||
} |
77 changes: 77 additions & 0 deletions
77
14th-team5-iOS/Core/Sources/Bibbi/BBCommons/BBToolTip/BBTextToolTipView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// | ||
// BBTextToolTipView.swift | ||
// Core | ||
// | ||
// Created by 김도현 on 10/27/24. | ||
// | ||
|
||
import UIKit | ||
|
||
import SnapKit | ||
import Then | ||
|
||
|
||
public class BBTextToolTipView: BBBaseToolTipView { | ||
// MARK: - Properties | ||
private var contentLabel: BBLabel = BBLabel() | ||
|
||
// 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() | ||
setupToolTipContent() | ||
setupAutoLayout() | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
// MARK: - Configure | ||
private func setupToolTipUI() { | ||
addSubview(contentLabel) | ||
} | ||
|
||
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() | ||
} | ||
|
||
self.do { | ||
$0.backgroundColor = .clear | ||
} | ||
} | ||
|
||
private func setupAutoLayout() { | ||
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) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
..UIView.animate는 weak self를 쓸 필요가 없다고 합니당...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아하 UIView.animate에는 쓸필요가 없네요 감사합니다 :)
weak self
코드도 따로 이슈 파서 수정해 놓을 게요There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
고거는 왜 쓸 필요 없나여?! 저도 알려주세영
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
제가 이해한 바로는 GCD 같은 경우
타입 프로퍼티
,타입 메서드
로 구성이 되어 있기때문에weak self
를 사용하지 않아도 되요