Skip to content

Commit

Permalink
Swift Package support (#20)
Browse files Browse the repository at this point in the history
* Add Package manifest
* move Xcode files into `Xcode/` subfolder
* migrate Cocoapods URLs to Timing-GmbH/DateRangePicker
* document workaround to get NSColor from asset catalog or code
  • Loading branch information
DivineDominion committed Jun 9, 2023
1 parent 27b74ba commit 6b87a66
Show file tree
Hide file tree
Showing 31 changed files with 168 additions and 204 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Expand Up @@ -5,4 +5,6 @@
*.xcuserstate
*.xcbkptlist
*.xcodeproj/xcuserdata
tmp/
tmp/
.swiftpm/
.build/
10 changes: 5 additions & 5 deletions DateRangePicker.podspec
Expand Up @@ -2,19 +2,19 @@ Pod::Spec.new do |s|
s.name = 'DateRangePicker'
s.version = '5.0'

s.homepage = 'https://github.com/MrMage/DateRangePicker'
s.homepage = 'https://github.com/Timing-GmbH/DateRangePicker'
s.summary = 'The best (?) date range picker control for OS X.'
s.screenshots = 'https://raw.githubusercontent.com/MrMage/DateRangePicker/master/Screenshots/Popover.png', 'https://raw.githubusercontent.com/MrMage/DateRangePicker/master/Screenshots/ControlVariants.png', 'https://raw.githubusercontent.com/MrMage/DateRangePicker/master/Screenshots/Menu.png'
s.screenshots = 'https://raw.githubusercontent.com/Timing-GmbH/DateRangePicker/master/Screenshots/Popover.png', 'https://raw.githubusercontent.com/Timing-GmbH/DateRangePicker/master/Screenshots/ControlVariants.png', 'https://raw.githubusercontent.com/Timing-GmbH/DateRangePicker/master/Screenshots/Menu.png'

s.author = { 'Daniel Alm' => 'CocoaPods@danielalm.de' }
s.license = { :type => 'ISC (simplified BSD)', :file => 'LICENSE' }
s.social_media_url = 'https://twitter.com/daniel_a_a'
s.platforms = { :osx => '10.13' }

s.source_files = 'DateRangePicker/*.{h,swift}'
s.resources = ['DateRangePicker/*.lproj/*', 'DateRangePicker/*.xcassets']
s.source_files = 'Sources/DateRangePicker/*.{h,swift}'
s.resources = ['Sources/DateRangePicker/Resources/*.lproj/*', 'Sources/DateRangePicker/Resources/*.xcassets']
s.module_name = 'DateRangePicker'
s.source = { :git => 'https://github.com/MrMage/DateRangePicker.git', :tag => 'v5.0' }
s.source = { :git => 'https://github.com/Timing-GmbH/DateRangePicker.git', :tag => 'v5.0' }
s.requires_arc = true
s.frameworks = 'AppKit', 'Foundation'
s.swift_versions = ['4.2', '5']
Expand Down
199 changes: 71 additions & 128 deletions DateRangePicker.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

36 changes: 0 additions & 36 deletions DateRangePickerDemoUITests/DateRangePickerDemoUITests.swift

This file was deleted.

24 changes: 0 additions & 24 deletions DateRangePickerTests/Info.plist

This file was deleted.

23 changes: 23 additions & 0 deletions Package.swift
@@ -0,0 +1,23 @@
// swift-tools-version: 5.6

import PackageDescription

let package = Package(
name: "DateRangePicker",
defaultLocalization: "en",
platforms: [
.macOS(.v10_13),
],
products: [
.library(
name: "DateRangePicker",
targets: ["DateRangePicker"]),
],
targets: [
.target(
name: "DateRangePicker"),
.testTarget(
name: "DateRangePickerTests",
dependencies: ["DateRangePicker"]),
]
)
File renamed without changes.
File renamed without changes.
Expand Up @@ -6,7 +6,7 @@
// Copyright © 2021 Daniel Alm. All rights reserved.
//

import Foundation
import AppKit

class DateRangeButtonCell: NSButtonCell {
static let horizontalInset: CGFloat = 7
Expand Down
File renamed without changes.
Expand Up @@ -6,7 +6,7 @@
// Copyright © 2021 Daniel Alm. All rights reserved.
//

import Foundation
import AppKit

open class DoubleClickDateRangePicker: NSDatePicker {
open var doubleAction: Selector?
Expand Down
Expand Up @@ -58,8 +58,44 @@ fileprivate class SolidBackgroundView: NSView {
}
}

extension NSAppearance {
fileprivate var isDarkMode: Bool {
if #available(macOS 10.14, *) {
if self.bestMatch(from: [.darkAqua, .aqua]) == .darkAqua {
return true
} else {
return false
}
} else {
return false
}
}
}

open class ExpandedDateRangePickerController: NSViewController {
/// - Note: Testing seam to verify the color is loadable from all build products.
@available(macOS 10.14, *)
static var separatorColor: NSColor? {
if #available(macOS 10.15, *) {
// Programmatic initialization works on all devices and in all contexts and should be favored in the long run.
return NSColor(name: "DateRangePicker_separator") { appearance in
if appearance.isDarkMode {
return NSColor(genericGamma22White: 1, alpha: 0.098)
} else {
return NSColor(genericGamma22White: 0, alpha: 0.098)
}
}
} else {
// This code path is for macOS 10.14 and Xcode.
// Swift Packages won't compile asset catalogs from the command line. Xcode is required to compile an
// asset catalog. This is fine in practice because Xcode is required to build AppKit apps anyway, so this
// code path is never exercised from the command line. (It's a bummer nevertheless.)
return NSColor(
named: "DateRangePicker_separator",
bundle: getBundle())
}
}

@IBOutlet var presetColumnStackView: NSStackView?
@IBOutlet var rhsStackView: NSStackView?
@IBOutlet var startDateCalendarPicker: DoubleClickDateRangePicker?
Expand Down Expand Up @@ -162,11 +198,11 @@ open class ExpandedDateRangePickerController: NSViewController {
_dateRange = dateRange
self.hourShift = hourShift
super.init(nibName: "ExpandedDateRangePickerController",
bundle: Bundle(for: ExpandedDateRangePickerController.self))
bundle: getBundle())
}

public required init?(coder: NSCoder) {
return nil
return nil
}

private func updateButtonStates(selectedRange: DateRange) {
Expand Down Expand Up @@ -217,10 +253,10 @@ open class ExpandedDateRangePickerController: NSViewController {

presetColumnStackView.addArrangedSubview(column)
var separatorColor: NSColor?
if #available(OSX 10.14, *) {
if #available(macOS 10.14, *) {
// In other contexts, `.gridColor` seems to work fine for uses like this, but in this particular case it
// appears too weak (possibly because of the popover's vibrancy).
separatorColor = NSColor(named: "DateRangePicker_separator")
separatorColor = ExpandedDateRangePickerController.separatorColor
}
let separator = SolidBackgroundView.verticalSeparator(
backgroundColor: separatorColor ?? NSColor(calibratedWhite: 0, alpha: 0.2))
Expand Down
Expand Up @@ -9,5 +9,9 @@
import Foundation

func getBundle() -> Bundle {
#if SWIFT_PACKAGE
return Bundle.module
#else
return Bundle(for: DateRangePickerView.self)
#endif
}
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="21179.7" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="21701" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="21179.7"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="21701"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
Expand Down Expand Up @@ -50,7 +50,7 @@
<binding destination="-2" name="maxValue" keyPath="maxDate" id="z8H-Ip-gnA"/>
</connections>
</datePicker>
<datePicker verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="HSY-I2-CQn" customClass="DoubleClickDateRangePicker" customModule="DateRangePicker" customModuleProvider="target">
<datePicker verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="HSY-I2-CQn" customClass="DoubleClickDateRangePicker" customModule="DateRangePicker">
<rect key="frame" x="0.0" y="0.0" width="139" height="148"/>
<datePickerCell key="cell" borderStyle="bezel" alignment="left" datePickerStyle="clockAndCalendar" id="YkB-C8-NUg">
<font key="font" metaFont="system"/>
Expand All @@ -66,7 +66,7 @@
<binding destination="-2" name="value" keyPath="startDate" id="m8C-aT-mc7"/>
</connections>
</datePicker>
<datePicker verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="UeG-Rz-FlU" customClass="DoubleClickDateRangePicker" customModule="DateRangePicker" customModuleProvider="target">
<datePicker verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="UeG-Rz-FlU" customClass="DoubleClickDateRangePicker" customModule="DateRangePicker">
<rect key="frame" x="147" y="0.0" width="139" height="148"/>
<datePickerCell key="cell" borderStyle="bezel" alignment="left" datePickerStyle="clockAndCalendar" id="IA0-nd-0dU">
<font key="font" metaFont="system"/>
Expand Down
16 changes: 16 additions & 0 deletions Tests/DateRangePickerTests/AssetTests.swift
@@ -0,0 +1,16 @@
//
// DateRangeTest.swift
// DateRangePicker
//
// Created by Christian Tietze on 08.06.23.
// Copyright © 2015 Daniel Alm. All rights reserved.
//

import XCTest
@testable import DateRangePicker

final class AssetTests: XCTestCase {
func testSeparatorColor() {
XCTAssertNotNil(ExpandedDateRangePickerController.separatorColor)
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 6b87a66

Please sign in to comment.