Skip to content

Commit

Permalink
Merge branch 'main' into feat-uikit-toast
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinneko committed Jul 23, 2024
2 parents 0e0a738 + 5cfd721 commit 85d43b6
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 133 deletions.
4 changes: 2 additions & 2 deletions BuildTools/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@
"repositoryURL": "https://github.com/nicklockwood/SwiftFormat",
"state": {
"branch": null,
"revision": "dd989a46d0c6f15c016484bab8afe5e7a67a4022",
"version": "0.54.0"
"revision": "e4965d9e8acebb8341a6ebd20b910c882157482d",
"version": "0.54.1"
}
},
{
Expand Down
4 changes: 4 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ let package = Package(
.target(
name: "CharcoalUIKit",
dependencies: ["CharcoalShared"]
),
.testTarget(
name: "charcoal-iosUIKitTests",
dependencies: ["CharcoalUIKit"]
)
]
)
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ public extension CharcoalTooltip {
static func dismiss(id: CharcoalIdentifiableOverlayView.IDValue) {
ChacoalOverlayManager.shared.dismiss(id: id)
}
}

private static func tooltipX(anchorFrame: CGRect, tooltipSize: CGSize, canvasGeometrySize: CGSize, spacingToScreen: CGFloat) -> CGFloat {
extension CharcoalTooltip {
static func tooltipX(anchorFrame: CGRect, tooltipSize: CGSize, canvasGeometrySize: CGSize, spacingToScreen: CGFloat) -> CGFloat {
let minX = anchorFrame.midX - (tooltipSize.width / 2.0)

var edgeLeft = minX
Expand All @@ -85,7 +87,7 @@ public extension CharcoalTooltip {
return edgeLeft
}

private static func tooltipY(anchorFrame: CGRect, arrowHeight: CGFloat, tooltipSize: CGSize, canvasGeometrySize: CGSize, spacingToTarget: CGFloat) -> CGFloat {
static func tooltipY(anchorFrame: CGRect, arrowHeight: CGFloat, tooltipSize: CGSize, canvasGeometrySize: CGSize, spacingToTarget: CGFloat) -> CGFloat {
let minX = anchorFrame.maxY + spacingToTarget + arrowHeight
var edgeBottom = anchorFrame.maxY + spacingToTarget + anchorFrame.height
if edgeBottom + tooltipSize.height >= canvasGeometrySize.height {
Expand Down
95 changes: 0 additions & 95 deletions Tests/charcoal-iosTests/UIKit/CharcoalTextFieldViewTests.swift

This file was deleted.

52 changes: 52 additions & 0 deletions Tests/charcoal-iosUIKitTests/CharcoalTooltipTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
@testable import CharcoalUIKit
import XCTest

final class CharcoalTooltipTests: XCTestCase {
// The canvas is a rectangle where the tooltip can be placed
let canvasGeometryRect = CGRect(x: 0, y: 0, width: 320, height: 640)
// The size of the tooltip
let tooltipSize = CGSize(width: 100, height: 100)
// The spacing of the tooltip to the screen
let spacingToScreen: CGFloat = 16
// The height of the arrow
let arrowHeight: CGFloat = 4
// The spacing of the tooltip to the target
let spacingToTarget: CGFloat = 2
// The size of the anchor view
let anchorViewSize = CGSize(width: 100, height: 100)

func testLayoutTopLeft() throws {
// Here we put the anchor frame at top left corner
let anchorFrame = CGRect(x: 0, y: 0, width: anchorViewSize.width, height: anchorViewSize.height)
let x = CharcoalTooltip.tooltipX(anchorFrame: anchorFrame, tooltipSize: tooltipSize, canvasGeometrySize: canvasGeometryRect.size, spacingToScreen: spacingToScreen)
let y = CharcoalTooltip.tooltipY(anchorFrame: anchorFrame, arrowHeight: arrowHeight, tooltipSize: tooltipSize, canvasGeometrySize: canvasGeometryRect.size, spacingToTarget: spacingToTarget)

// The tooltip should be at the top left corner and respect the spacing
XCTAssertEqual(x, spacingToScreen)
XCTAssertEqual(y, anchorFrame.maxY + spacingToTarget + arrowHeight)
}

func testLayoutCenter() throws {
// Here we put the anchor frame at the center of the canvas
let canvasCenter = CGPoint(x: canvasGeometryRect.midX, y: canvasGeometryRect.midY)
let anchorFrame = CGRect(x: canvasCenter.x - anchorViewSize.width / 2.0, y: canvasCenter.y - anchorViewSize.height / 2.0, width: anchorViewSize.width, height: anchorViewSize.height)

let x = CharcoalTooltip.tooltipX(anchorFrame: anchorFrame, tooltipSize: tooltipSize, canvasGeometrySize: canvasGeometryRect.size, spacingToScreen: spacingToScreen)
let y = CharcoalTooltip.tooltipY(anchorFrame: anchorFrame, arrowHeight: arrowHeight, tooltipSize: tooltipSize, canvasGeometrySize: canvasGeometryRect.size, spacingToTarget: spacingToTarget)

// The tooltip should be at the center of the canvas
XCTAssertEqual(x, canvasCenter.x - tooltipSize.width / 2.0)
XCTAssertEqual(y, anchorFrame.maxY + spacingToTarget + arrowHeight)
}

func testLayoutBottomRight() throws {
// Here we put the anchor frame at the bottom right corner
let anchorFrame = CGRect(x: canvasGeometryRect.maxX - anchorViewSize.width, y: canvasGeometryRect.maxY - anchorViewSize.height, width: anchorViewSize.width, height: anchorViewSize.height)
let x = CharcoalTooltip.tooltipX(anchorFrame: anchorFrame, tooltipSize: tooltipSize, canvasGeometrySize: canvasGeometryRect.size, spacingToScreen: spacingToScreen)
let y = CharcoalTooltip.tooltipY(anchorFrame: anchorFrame, arrowHeight: arrowHeight, tooltipSize: tooltipSize, canvasGeometrySize: canvasGeometryRect.size, spacingToTarget: spacingToTarget)

// The tooltip should be at the bottom right corner and respect the spacing
XCTAssertEqual(x, canvasGeometryRect.maxX - tooltipSize.width - spacingToScreen)
XCTAssertEqual(y, anchorFrame.minY - spacingToTarget - arrowHeight - tooltipSize.height)
}
}
52 changes: 26 additions & 26 deletions scripts/create-pull-request/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions scripts/xcasset-gen/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion scripts/xcasset-gen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"type": "module",
"dependencies": {
"@babel/runtime": "^7.24.7",
"@babel/runtime": "^7.24.8",
"fs-extra": "^11.2.0",
"globby": "^14.0.2",
"yargs": "^17.7.2"
Expand Down

0 comments on commit 85d43b6

Please sign in to comment.