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

Support AppKit #351

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
30 changes: 30 additions & 0 deletions Example-macOS/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// AppDelegate.swift
// Example-macOS
//
// Created by JH on 2024/5/26.
//

import Cocoa

@main
class AppDelegate: NSObject, NSApplicationDelegate {


Copy link

Choose a reason for hiding this comment

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

Lines should not have trailing whitespace.



func applicationDidFinishLaunching(_ aNotification: Notification) {
// Insert code here to initialize your application
}

func applicationWillTerminate(_ aNotification: Notification) {
// Insert code here to tear down your application
}

func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool {
return true
}


}

11 changes: 11 additions & 0 deletions Example-macOS/Assets.xcassets/AccentColor.colorset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
58 changes: 58 additions & 0 deletions Example-macOS/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"images" : [
{
"idiom" : "mac",
"scale" : "1x",
"size" : "16x16"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "16x16"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "32x32"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "32x32"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "128x128"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "128x128"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "256x256"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "256x256"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "512x512"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "512x512"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 6 additions & 0 deletions Example-macOS/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
757 changes: 757 additions & 0 deletions Example-macOS/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions Example-macOS/Example_macOS.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.files.user-selected.read-only</key>
<true/>
</dict>
</plist>
93 changes: 93 additions & 0 deletions Example-macOS/ViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
//
// ViewController.swift
// Example-macOS
//
// Created by JH on 2024/5/26.
//

import Cocoa
import NVActivityIndicatorView

class ViewController: NSViewController {
@ViewLoading
@IBOutlet var collectionView: NSCollectionView

override func viewDidLoad() {
super.viewDidLoad()

collectionView.dataSource = self
collectionView.delegate = self
collectionView.register(CollectionViewItem.self, forItemWithIdentifier: .init(String(describing: CollectionViewItem.self)))
collectionView.enclosingScrollView?.scrollerStyle = .overlay
}

override var representedObject: Any? {
didSet {
// Update the view, if already loaded.
}
}

let allTypes = NVActivityIndicatorType.allCases.filter { $0 != .blank }
}

extension ViewController: NSCollectionViewDataSource, NSCollectionViewDelegate {
func collectionView(_ collectionView: NSCollectionView, numberOfItemsInSection section: Int) -> Int {
allTypes.count
}

func collectionView(_ collectionView: NSCollectionView, itemForRepresentedObjectAt indexPath: IndexPath) -> NSCollectionViewItem {
let viewItem = collectionView.makeItem(withIdentifier: .init(String(describing: CollectionViewItem.self)), for: indexPath) as! CollectionViewItem
Copy link

Choose a reason for hiding this comment

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

Force casts should be avoided.

viewItem.type = allTypes[indexPath.item]
return viewItem
}
}

class CollectionViewItem: NSCollectionViewItem {
lazy var indicatorView: NVActivityIndicatorView = {
let indicatorView = NVActivityIndicatorView(frame: .zero, type: type)
view.addSubview(indicatorView)
indicatorView.translatesAutoresizingMaskIntoConstraints = false

NSLayoutConstraint.activate([
indicatorView.topAnchor.constraint(equalTo: view.topAnchor),
indicatorView.leftAnchor.constraint(equalTo: view.leftAnchor),
indicatorView.rightAnchor.constraint(equalTo: view.rightAnchor),
indicatorView.heightAnchor.constraint(equalTo: indicatorView.widthAnchor),
])
indicatorView.layoutSubtreeIfNeeded()
indicatorView.startAnimating()
return indicatorView
}()

lazy var titleLabel: NSTextField = {
let titleLabel = NSTextField(labelWithString: "")
titleLabel.textColor = .labelColor
titleLabel.font = .systemFont(ofSize: 10)
view.addSubview(titleLabel)
titleLabel.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
titleLabel.topAnchor.constraint(equalTo: indicatorView.bottomAnchor, constant: 10),
titleLabel.centerXAnchor.constraint(equalTo: view.centerXAnchor),
])
return titleLabel
}()

var type: NVActivityIndicatorType = .blank {
didSet {
indicatorView.type = type
indicatorView.stopAnimating()
indicatorView.startAnimating()
titleLabel.stringValue = type.animationName
}
}

override init(nibName nibNameOrNil: NSNib.Name?, bundle nibBundleOrNil: Bundle?) {
super.init(nibName: nil, bundle: nil)

}

@available(*, unavailable)
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
10 changes: 10 additions & 0 deletions Example/Example.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
</dict>
</plist>
8 changes: 5 additions & 3 deletions Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,15 @@ class ViewController: UIViewController, NVActivityIndicatorViewable {
type: indicatorType)
let animationTypeLabel = UILabel(frame: frame)

animationTypeLabel.text = String(index)
animationTypeLabel.text = indicatorType.animationClassName.replacingOccurrences(of: "NVActivityIndicatorView.NVActivityIndicatorAnimation", with: "")
animationTypeLabel.font = .systemFont(ofSize: 10)
animationTypeLabel.sizeToFit()
animationTypeLabel.allowsDefaultTighteningForTruncation = true
animationTypeLabel.textColor = UIColor.white
animationTypeLabel.frame.origin.x += 5
animationTypeLabel.frame.origin.x += 0
animationTypeLabel.frame.origin.y += CGFloat(cellHeight) - animationTypeLabel.frame.size.height

animationTypeLabel.frame.size.width = frame.width
animationTypeLabel.textAlignment = .center
activityIndicatorView.padding = 20
if indicatorType == NVActivityIndicatorType.orbit {
activityIndicatorView.padding = 0
Expand Down
5 changes: 4 additions & 1 deletion NVActivityIndicatorView.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Pod::Spec.new do |s|
s.social_media_url = 'http://twitter.com/ninjaprox'
s.documentation_url = 'https://nvactivityindicatorview.vinhis.me'

s.osx.deployment_target = '10.13'
s.ios.deployment_target = '9.0'
s.tvos.deployment_target = '9.0'
s.swift_version = '5.0'
Expand All @@ -25,5 +26,7 @@ Pod::Spec.new do |s|
end
s.default_subspec = 'Base'

s.frameworks = 'UIKit', 'QuartzCore'
s.ios.frameworks = 'UIKit', 'QuartzCore'
s.tvos.frameworks = 'UIKit', 'QuartzCore'
s.osx.frameworks = 'AppKit', 'QuartzCore'
end
Loading