generated from Awesomeplayer165/Template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for macOS (AppKit) using the NSUI package (#29)
* Add macOS (AppKit) compatibility using the UXKit package Directly derive PillView from UXView Add ability to specify a custom font to display the pill message Ensure pillView is centered within the container view Add ability to specify a different message when `completeTask` is called Comment out Hashable conformance because this is coming for free by dericing from UXView Rework initializer structure to use convenience init Fix issue where pillView was not removed from the view hierarchy when dismissed WIP: Add PillAnimation structure to allow pill to be animated from the bottom or from the top * Ensure UXImage with symbol name works for both macOS (11.x +) and iOS * Update .gitignore Add extensions to NSUI * Update PillBox to use NSUI for macOS compatibility Derive PillBox directly from NSUIView instead of using containment Comment out Conformance as no longer needed Support AppKit for PillView transition Allow specification to sticky timeout for showError() Allow specification of a default Font for PillView Allow capability to update the showTask() message while in process Properly center the pillView into the container view using simple autoresizing masks Extend NSUIColor to get light and dark color scheme * Add ci.yml to build on supported platforms... * Update ci to support Mac Catalyst * Update ci to support Mac Catalyst * Update ci.yml * Trying to fix ci again. * Update ci.yml * Update ci.yml * Update ci.yml * Update all NS* reference to use the common CoreGraphics CG* functions to help with AppKit / UIKit compatibility * Vertically center PillView subviews according to font line height and pillView heights Ensure font size does not exceed PillView height Rename files to start with Pill*
- Loading branch information
1 parent
d5f7cbf
commit 971e784
Showing
12 changed files
with
600 additions
and
223 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
paths-ignore: | ||
- 'README.md' | ||
- 'CODE_OF_CONDUCT.md' | ||
- 'CONTRIBUTING.md' | ||
- 'LICENSE' | ||
- 'SECURITY.md' | ||
- 'ios.yml' | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
test: | ||
name: Test | ||
runs-on: macOS-latest | ||
strategy: | ||
matrix: | ||
destination: | ||
- "platform=macOS" | ||
# - "platform=macOS,variant=Mac Catalyst" | ||
- "platform=iOS Simulator,name=iPhone 11" | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Install XCBeautify | ||
run: brew install xcbeautify | ||
- name: Show buildable schemes | ||
run: xcodebuild -list | ||
- name: Test Each Platform | ||
run: set -o pipefail && xcodebuild -scheme PillboxView -destination "${{ matrix.destination }}" test | xcbeautify --renderer github-actions |
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,3 +1,5 @@ | ||
|
||
*.xcuserstate | ||
## User settings | ||
xcuserdata/ | ||
**/.swiftpm | ||
**/.DS_Store | ||
*.xcuserstate |
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
Binary file not shown.
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// | ||
// NSUI+Extensions.swift | ||
// | ||
// | ||
|
||
import CoreGraphics | ||
import Foundation | ||
|
||
// --- | ||
import NSUI | ||
|
||
internal extension NSUIView { | ||
|
||
/// Return the origin `UXPoint` for a view which needs to be centered horizontally within its superview | ||
/// This is performed with frame math only and it is set at init type. | ||
/// Changing the window size will not recalculate the origin. | ||
func originForCenter(inRelationTo parentView: NSUIView) -> CGPoint { | ||
guard | ||
parentView.frame != CGRect.zero | ||
else { | ||
fatalError("Your parentView must have a non-zero size") | ||
} | ||
|
||
let midPoint = CGRectGetMidX(parentView.frame) | ||
|
||
// Now get the half the width of our view and substract than from the midPoint | ||
let selfMidPoint = self.frame.width / 2 | ||
|
||
let newOriginX = (midPoint - selfMidPoint).rounded() | ||
let newOriginY = self.frame.origin.y | ||
return CGPoint(x: newOriginX, y: newOriginY) | ||
} | ||
} | ||
|
||
#if canImport(AppKit) | ||
import AppKit | ||
#endif | ||
|
||
internal extension NSUIColor { | ||
#if os(macOS) | ||
@available(OSX 10.14, *) | ||
static var isLight: Bool { NSApp.effectiveAppearance.name == NSAppearance.Name.aqua } | ||
|
||
@available(OSX 10.14, *) | ||
static var isDark: Bool { NSApp.effectiveAppearance.name == NSAppearance.Name.darkAqua } | ||
#endif | ||
} | ||
|
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 |
---|---|---|
@@ -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) | ||
} | ||
} |
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,92 @@ | ||
// | ||
// PillTransitions.swift | ||
// | ||
// | ||
// Created by Jacob Trentini on 2/3/22. | ||
|
||
#if canImport(UIKit) | ||
import UIKit | ||
#elseif canImport(AppKit) | ||
import AppKit | ||
#endif | ||
|
||
import Foundation | ||
|
||
extension PillView { | ||
|
||
/// Hides the ``PillboxView/PillView/pillView`` to the top of the screen. | ||
/// | ||
/// The ``PillboxView/PillView/pillView`` moves up to the top of the screen until it is out of sight. | ||
/// This is used within the ``PillboxView/PillView/completedTask(state:completionHandler:)`` and ``PillboxView/PillView/showError(message:vcView:)``. | ||
/// | ||
/// The animation, in total, takes 3 seconds to complete. | ||
/// | ||
/// This does not reset or de-initialize any values of the ``PillboxView/PillView``. | ||
/// | ||
/// - Parameters: | ||
/// - animated: A Boolean indicating whether the ``PillboxView/PillView/pillView`` should be dismissed with an animation. | ||
/// - timeBeforeMoveOut: Amount of time (in secs) before the ``PillboxView/PillView/pillView`` is moved outside the viewing frame | ||
/// - completionHandler: A completion handler indicating when the animation has finished. | ||
public func dismiss(animated: Bool = true, timeBeforeMoveOut: TimeInterval = 1.5, completionHandler: (() -> Void)? = nil) { | ||
DispatchQueue.main.asyncAfter(deadline: .now() + timeBeforeMoveOut) { | ||
#if os(macOS) | ||
let originX = self.frame.origin.x | ||
let originY = self.vcView.frame.height /* Distance above top (plus value) */ + 50 | ||
NSAnimationContext.runAnimationGroup({ context in | ||
context.duration = 1 | ||
context.allowsImplicitAnimation = true | ||
context.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeIn) | ||
|
||
self.frame.origin = CGPoint(x: originX, y: originY) | ||
}, | ||
completionHandler: { | ||
completionHandler?() | ||
}) | ||
#else | ||
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 | ||
} | ||
} | ||
|
||
/// Reveal the ``PillboxView/PillView/pillView`` to the top of the screen. | ||
/// | ||
/// The ``PillboxView/PillView/pillView`` moves to the top of the screen until it is in sight (it usually comes from being dismissed). | ||
/// | ||
/// - Parameters: | ||
/// - animated: A Boolean indicating whether the ``PillboxView/PillView/pillView`` should be revealed with an animation. | ||
/// - completionHandler: A completion handler indicating when the animation has finished. | ||
public func reveal(animated: Bool = true, completionHandler: (() -> Void)? = nil) { | ||
DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) { | ||
#if os(macOS) | ||
NSAnimationContext.runAnimationGroup{ context in | ||
context.duration = 0.25 | ||
context.allowsImplicitAnimation = true | ||
context.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeIn) | ||
|
||
let originX = self.frame.origin.x | ||
let originY = 25.0 | ||
self.frame.origin = CGPoint(x: originX, y: originY) | ||
} | ||
#else | ||
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 | ||
} | ||
} | ||
} |
Oops, something went wrong.