Skip to content
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

An assortment of changes and additions to help with accessibility, alerts, tables, etc #2

Open
wants to merge 36 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
381a8a0
Added NSTextAlignment and NSMutableParagraphStyle
pkclsoft Aug 4, 2021
2302bbe
Added NSStringDrawingContext
pkclsoft Aug 5, 2021
7a8440c
* Lots of changes to broaden the compatibility between UIKit and AppKit.
pkclsoft Aug 15, 2021
c1df5a6
Prevent bezier path always being closed.
pkclsoft Aug 15, 2021
ae2cc28
Working on getting UXTableView working properly.
pkclsoft Aug 22, 2021
a1e4c35
Got the table view cells centered properly on macOS.
pkclsoft Aug 23, 2021
bf01731
Added UXCustomRowView class to allow control over the background draw…
pkclsoft Aug 24, 2021
593fce1
Getting cell/row editing working within a table.
pkclsoft Aug 27, 2021
b1c3f1f
Added a UIKit style set of methods to the TextFieldDelegate protocol …
pkclsoft Aug 30, 2021
f81047e
Fleshed out the UXAlertAction, and UXAlert and got it working.
pkclsoft Sep 1, 2021
c4da749
Added initialiser for UXTableView that does some initialisation that …
pkclsoft Sep 2, 2021
b02fd22
Merge branch 'develop' of https://github.com/pkclsoft/UXKit into develop
pkclsoft Nov 13, 2021
d913e5b
Added valueChanged notification to UIKit.
pkclsoft Nov 21, 2021
4421948
Set the minimum OS versions.
pkclsoft Mar 7, 2022
0c2b5d9
Added a tvOS target.
pkclsoft Mar 7, 2022
30c1ab5
Made the deployment targets more consistent.
pkclsoft Mar 7, 2022
6d87c87
Made the deployment targets more consistent.
pkclsoft Mar 7, 2022
2fbb22c
Made the tvOS target have the same module name as the others.
pkclsoft Mar 7, 2022
3f7d56f
More tvOS specificity.
pkclsoft Mar 7, 2022
b5a1ba4
iOS needs 13.0 for several of the classes.
pkclsoft Mar 7, 2022
2909593
Don't try to use tvOS 13 stuff when it's not available.
pkclsoft Mar 7, 2022
1f59f5d
Don't try to use iOS 13 stuff when it's not available.
pkclsoft Mar 7, 2022
0602b78
Moving back to iOS and tvOS 12.4
pkclsoft Mar 8, 2022
f5e1969
Move to iOS/tvOS v13
pkclsoft May 30, 2023
14caee4
Added a little more to UXViewController in support of GameKit
pkclsoft Sep 12, 2023
a5c279c
New functions need to be public.
pkclsoft Sep 12, 2023
de8e342
Merge branch 'ZeeZide:develop' into develop
pkclsoft Dec 15, 2023
501d50c
Merge branch 'develop' of https://github.com/pkclsoft/UXKit into develop
pkclsoft Dec 15, 2023
29078de
Added UXBezierPath.addCurve so that macOS can use the same API as iOS…
pkclsoft Feb 5, 2024
95d8a43
Accessibility notifications need sometimes to provide a userInfo dict…
pkclsoft Apr 1, 2024
a885abb
Attempt to improve the notifications sent for accessibility.
pkclsoft Apr 2, 2024
24127b9
Another attempt to get macOS accessibility notifications to actually …
pkclsoft Apr 2, 2024
2bd004b
Provide a UIKit equivalent for the AppKit announcementRequested.
pkclsoft Apr 4, 2024
f4bc84a
Added accessibilitySpeechLanguage to appkit so that there is alignmen…
pkclsoft Apr 9, 2024
fe29d16
Moved the accessibilitySpeechLanguage to the right place.
pkclsoft Apr 9, 2024
77e0db4
On macOS, force notifications to be posted on the main thread because…
pkclsoft Jul 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import PackageDescription

let package = Package(
name: "UXKit",

exclude: [
"UXKit.xcodeproj",
"GNUmakefile",
"LICENSE",
"README.md",
"xcconfig"
]
name: "UXKit",

platforms: [
.macOS(.v10_15), .iOS(.v13), .tvOS(.v13)
],

exclude: [
"UXKit.xcodeproj",
"GNUmakefile",
"LICENSE",
"README.md",
"xcconfig"
]
)
2 changes: 1 addition & 1 deletion [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import PackageDescription
let package = Package(
name: "UXKit",
platforms: [
.macOS(.v10_12), .iOS(.v10)
.macOS(.v10_13), .iOS(.v13), .tvOS(.v13)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is quite a bump :-) But I think I'm fine w/ that. I think I've actually bumped Xcode even further.

],
products: [
.library(name: "UXKit", targets: ["UXKit"]),
Expand Down
19 changes: 11 additions & 8 deletions [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
import PackageDescription

let package = Package(
name: "UXKit",
products: [
.library(name: "UXKit", targets: ["UXKit"]),
],
dependencies: [],
targets: [
.target(name:"UXKit")
]
name: "UXKit",
platforms: [
.macOS(.v10_13), .iOS(.v12), .tvOS(.v12)
],
products: [
.library(name: "UXKit", targets: ["UXKit"]),
],
dependencies: [],
targets: [
.target(name:"UXKit")
]
)
164 changes: 145 additions & 19 deletions Sources/UXKit/AppKit/NSTableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*
* NOTE: This one doesn't actually support an image :-/
*/
open class NSTableViewCell : NSTableCellView {
open class NSTableViewCell : NSTableCellView, NSTextFieldDelegate {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what to make of that (and the related changes below, including the 1st responder changes). The behaviour added seems specific to a certain use-case, not required for UIKit/AppKit compatibility?
Can you elaborate why we need that in UXKit?

// Note: UITableViewCell has many more views to show selection state,
// regular background, etc.

Expand Down Expand Up @@ -56,14 +56,62 @@
}
private let style = Style()

// provided for compatibility, though not really used.
public enum SelectionStyle : Int {
case none = 0
case blue = 1
case gray = 2
@available(iOS 7.0, *)
case `default` = 3
}

public var selectionStyle : SelectionStyle = .default

// provided for compatibility, though not really used.
public enum AccessoryType : Int {
case none = 0 // don't show any accessory view
case disclosureIndicator = 1 // regular chevron. doesn't track
case detailDisclosureButton = 2 // info button w/ chevron. tracks
case checkmark = 3 // checkmark. doesn't track

@available(iOS 7.0, *)
case detailButton = 4 // info button. tracks
}

public var accessoryType : AccessoryType = .none


// provided for compatibility, though not really used.
public enum EditingStyle : Int {
case none = 0
case delete = 1
case insert = 2
}

// These are provided for UIKit compatibility. Not actively used (yet).
public var backgroundColor : UXColor {
get {
if let col = self.layer?.backgroundColor {
return UXColor(cgColor: col)!
}

return UXColor.textBackgroundColor
}

set {
self.layer?.backgroundColor = newValue.cgColor
}
}

public init(style: UXTableViewCellStyle, reuseIdentifier id: String?) {
/* TODO: SETUP:
default: just label, no detail
value1: label on the left, gray detail on the right (same row)
value1: blue lable on the left 1/4, black detail on the right (same row)
subtitle: label, below gray detail (two rows)
*/

editing = false

super.init(frame: UXRect())

if let id = id {
Expand All @@ -80,7 +128,7 @@
}

private var installedConstraintSetup = ViewSetup.none
private var requiredContraintSetup : ViewSetup {
private var requiredConstraintSetup : ViewSetup {
switch ( _textLabel, _detailTextLabel ) {
case ( .none, .none ): return .none
case ( .some, .none ): return .label
Expand All @@ -93,7 +141,7 @@
override open func updateConstraints() {
super.updateConstraints()

let required = requiredContraintSetup
let required = requiredConstraintSetup
guard installedConstraintSetup != required else { return }
// Swift.print("from \(installedConstraintSetup) to \(required)")

Expand Down Expand Up @@ -156,7 +204,7 @@
let label = makeLabel()
label.font = UXFont.systemFont(ofSize: style.labelSize)
label.cell?.lineBreakMode = .byTruncatingTail

#if false
label.verticalAlignment = .middleAlignment // TBD: do we want this?
// I'm still not quite sure why we even need this. The height of the
Expand All @@ -179,6 +227,84 @@
return label
}
}

public override var acceptsFirstResponder: Bool {
get {
return true
}
}

public override func becomeFirstResponder() -> Bool {
if !self.editing {
self.editing = true

if let label = _textLabel {
if #available(macOS 10.14, *) {
label.backgroundColor = .selectedContentBackgroundColor
} else {
// Fallback on earlier versions
label.backgroundColor = .selectedMenuItemColor
}

label.drawsBackground = true
label.isEditable = true
label.target = self
label.action = #selector(didEditTableRow(_ :))
label.becomeFirstResponder()

if label.delegate == nil {
label.delegate = self
}

if let del = label.delegate as? UXTextFieldDelegate {
del.textFieldDidBeginEditing(label)
}
}

return true
}

return false
}

public override func resignFirstResponder() -> Bool {
if self.editing {
self.editing = false

if let label = _textLabel {
label.drawsBackground = false
label.abortEditing()
label.isEditable = false

if let del = label.delegate as? UXTextFieldDelegate {
del.textFieldDidEndEditing(label)
}
}
}

return true
}

var editing : Bool

@objc func didEditTableRow(_ editor: Any) {
NSLog("row was edited")
if let label = _textLabel {
if let del = label.delegate as? UXTextFieldDelegate {
if del.textFieldShouldReturn(label) {
// Only actually end the editing if the delegate says to.
_ = self.resignFirstResponder()
}
} else {
// if the delegate is not an instance of UXTextFieldDelegate, meaning it
// doesn't support the UIKit enhancements, then just treat this as an end
// to editing.
//
_ = self.resignFirstResponder()
}
}
}


var _detailTextLabel : UXLabel? = nil
open var detailTextLabel : UXLabel? {
Expand Down Expand Up @@ -224,7 +350,6 @@
}
}


// MARK: - Separator line (TBD: should we draw this?)

open var dividerColor : UXColor { return UXColor.lightGray }
Expand All @@ -249,19 +374,20 @@
// MARK: - Label Factory

open func makeLabel() -> UXLabel {
let v = NSTextField(frame: UXRect())
v.translatesAutoresizingMaskIntoConstraints = false

/* configure as label */
v.isEditable = false
v.isBezeled = false
v.drawsBackground = false
v.isSelectable = false // not for raw labels

/* common */
v.alignment = .left

return v
let v = UXLabel(frame: UXRect())
v.cell = VerticallyCenteredTextFieldCell()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the centering of all axis really what UITableView does?
I'd also move the Cell implementation into this function and not make it public API.

v.translatesAutoresizingMaskIntoConstraints = false

/* configure as label */
v.isEditable = false
v.isBezeled = false
v.drawsBackground = false
v.isSelectable = false // not for raw labels

/* common */
v.alignment = .center

return v
}
}

Expand Down
28 changes: 28 additions & 0 deletions Sources/UXKit/AppKit/UXGestures-AppKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import Cocoa

public typealias UXGestureRecognizer = NSGestureRecognizer
public typealias UXGestureRecognizerDelegate = NSGestureRecognizerDelegate
public typealias UXRotationGestureRecognizer = NSRotationGestureRecognizer
public typealias UXPanGestureRecognizer = NSPanGestureRecognizer
public typealias UXTapGestureRecognizer = NSClickGestureRecognizer
Expand All @@ -16,6 +17,14 @@

public extension NSView {

enum SwipeDirection {
case none
case left
case right
case up
case down
}

@discardableResult
func on(gesture gr: UXGestureRecognizer,
target: AnyObject, action: Selector) -> Self
Expand All @@ -26,6 +35,25 @@
return self
}

// This is how macOS handles Swipe gestures.
override func swipe(with event: NSEvent) {
let x : CGFloat = event.deltaX
let y : CGFloat = event.deltaY
var direction : SwipeDirection = .none

if (x != 0) {
direction = (x > 0) ? .left : .right
} else if (y != 0) {
direction = (y > 0) ? .up : .down
}

self.swipeGestureRecognized(inDirection: direction)
}

// Override this if you want to receive swipe gestures on your NSView.
func swipeGestureRecognized(inDirection direction: SwipeDirection) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't that func have to be open or @objc or sth to be actually subclassed?

The whole swipe thing doesn't seem to have any peer in UIKit? It is more like a convenience addition to just AppKit?

}

}

public extension UXTapGestureRecognizer {
Expand Down
Loading