Skip to content

Commit

Permalink
Vertically center PillView subviews according to font line height and…
Browse files Browse the repository at this point in the history
… pillView heights

Ensure font size does not exceed PillView height
Rename files to start with Pill*
  • Loading branch information
martindufort committed Jan 10, 2024
1 parent a358b8d commit bba448a
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 130 deletions.
23 changes: 0 additions & 23 deletions Sources/PillboxView/PillAnimation.swift

This file was deleted.

23 changes: 23 additions & 0 deletions Sources/PillboxView/PillPosition.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// PillPosition.swift
// ---

/// Defines the position of the ``PillboxView/PillView`` respective to it's view container as an offset
/// Also provide the ability to show the ``PillboxView/PillView`` appearing from the top ``fromTop`` or from the bottom
/// ``fromBottom`` of the container's edge
/// Default position is `.fromTop` with and offset of 25
import CoreGraphics

public struct PillPosition {
enum AnimationDirection {
case fromTop
case fromBottom
}
var direction: AnimationDirection
var offsetFromEdge: CGFloat

init() {
self.direction = .fromTop
self.offsetFromEdge = CGFloat(25.0)
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//
// File.swift
//
// PillTransitions.swift
//
//
// Created by Jacob Trentini on 2/3/22.

#if canImport(AppKit)
import AppKit
#elseif canImport(UIKit)
#if canImport(UIKit)
import UIKit
#elseif canImport(AppKit)
import AppKit
#endif

import Foundation
Expand Down Expand Up @@ -40,17 +40,17 @@ extension PillView {
self.frame.origin = CGPoint(x: originX, y: originY)
},
completionHandler: {
if let completionHandler = completionHandler { completionHandler() }
completionHandler?()
})
#else
UIView.animate(withDuration: 1, delay: 0.25) {
self.frame = CGRect(x: self.frame.minX,
y: -300,
width: self.frame.width,
height: self.frame.height)

if let completionHandler = completionHandler { completionHandler() }
}
UIView.animate(withDuration: 1.0,
animations: {
// Only change the position of the origin Y axis to be above the container
self.frame.origin = CGPoint(x: self.frame.origin.x, y: 0 - self.frame.height)
},
completion: { completed in
if completed { completionHandler?() }
})
#endif
}
}
Expand All @@ -75,14 +75,17 @@ extension PillView {
self.frame.origin = CGPoint(x: originX, y: originY)
}
#else
UIView.animate(withDuration: 1, delay: 0.25) {
self.frame = CGRect(x: self.frame.minX,
y: UIDevice.current.hasNotch ? 45: 25 + (self.isNavigationControllerPresent ? 40 : 0),
width: self.frame.width,
height: self.frame.height)

if let completionHandler = completionHandler { completionHandler() }
}
UIView.animate(withDuration: 1,
delay: 0.25,
animations: {
self.frame = CGRect(x: self.frame.minX,
y: UIDevice.current.hasNotch ? 45: 25 + (self.isNavigationControllerPresent ? 40 : 0),
width: self.frame.width,
height: self.frame.height)
},
completion: { completed in
if completed { completionHandler?() }
})
#endif
}
}
Expand Down
Loading

0 comments on commit bba448a

Please sign in to comment.