Commit 48144a13 authored by Aral Balkan's avatar Aral Balkan

Modernise API, clean up project

* Enum properties now start with lowercase letters
* Cleaned up readme
* Cleaned up, commented code
parent af79d3b2
......@@ -11,7 +11,7 @@
// GlobalTouchNotifications.sharedInstance
//
// // Register for global touch notification
// handle(GlobalTouchNotification.named(.TouchesBegan)
// handle(GlobalTouchNotification.named(.touchesBegan))
// {
// /* with */ notification in
//
......@@ -28,10 +28,10 @@ import Handle
public enum GlobalTouchNotification:String
{
case TouchesBegan
case TouchesEnded
case TouchesCancelled
case TouchesEstimatedPropertiesUpdated
case touchesBegan
case touchesEnded
case touchesCancelled
case touchesEstimatedPropertiesUpdated
public static func named(_ notification:GlobalTouchNotification) -> String
{
......@@ -43,16 +43,9 @@ public enum GlobalTouchNotification:String
open class GlobalTouchNotifications
{
/// Singleton
open class var sharedInstance:GlobalTouchNotifications
{
struct Static
{
static let instance:GlobalTouchNotifications = GlobalTouchNotifications()
}
return Static.instance
}
open static let shared = GlobalTouchNotifications()
init()
private init()
{
let mainWindow = UIApplication.shared.windows[0]
let globalTapGestureRecognizer = GlobalTapGestureRecognizer()
......@@ -66,24 +59,24 @@ class GlobalTapGestureRecognizer: UITapGestureRecognizer
{
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent)
{
post(GlobalTouchNotification.named(.TouchesBegan), from: self, with: ["touches" as NSObject: touches as AnyObject, "event" as NSObject: event])
post(GlobalTouchNotification.named(.touchesBegan), from: self, with: ["touches": touches, "event": event])
super.touchesBegan(touches, with: event)
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent)
{
post(GlobalTouchNotification.named(.TouchesEnded), from: self, with: ["touches" as NSObject: touches as AnyObject, "event" as NSObject: event])
post(GlobalTouchNotification.named(.touchesEnded), from: self, with: ["touches": touches, "event": event])
super.touchesEnded(touches, with: event)
}
override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent)
{
post(GlobalTouchNotification.named(.TouchesCancelled), from: self, with: ["touches" as NSObject: touches as AnyObject, "event" as NSObject: event])
post(GlobalTouchNotification.named(.touchesCancelled), from: self, with: ["touches": touches, "event": event])
super.touchesCancelled(touches, with: event)
}
override func touchesEstimatedPropertiesUpdated(_ touches: Set<UITouch>) {
post(GlobalTouchNotification.named(.TouchesEstimatedPropertiesUpdated), from: self, with: ["touches" as NSObject: touches as AnyObject])
post(GlobalTouchNotification.named(.touchesEstimatedPropertiesUpdated), from: self, with: ["touches": touches])
super.touchesEstimatedPropertiesUpdated(touches)
}
}
......@@ -26,9 +26,9 @@ class ViewController: UIViewController, WKNavigationDelegate, UIPopoverPresentat
{
super.viewDidLoad()
_ = GlobalTouchNotifications.sharedInstance
_ = GlobalTouchNotifications.shared
globalTouchesBeganHandler = globalTouchesBeganHandler ?? handle(GlobalTouchNotification.named(.TouchesBegan))
globalTouchesBeganHandler = globalTouchesBeganHandler ?? handle(GlobalTouchNotification.named(.touchesBegan))
{
/* with */ notification in
......@@ -51,9 +51,11 @@ class ViewController: UIViewController, WKNavigationDelegate, UIPopoverPresentat
webView.loadHTMLString("<head><meta name='viewport' content='width=device-width; initial-scale=1.0'><style>body {margin-top: 40px; background-color: #eee;}</style></head><h1>Hello</h1><p>This is <a href='#'>a link</a></p><p>This is <a href='#'>a link</a></p><p>This is <a href='#'>a link</a></p><p>This is <a href='#'>a link</a></p><p>This is <a href='#'>a link</a></p><p>This is <a href='#'>a link</a></p><p>This is <a href='#'>a link</a></p>.", baseURL: nil)
popoverViewController = PopoverTableViewController()
}
// MARK: - WKNavigationDelegate
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void)
{
if let lastTouch = lastTouch
......@@ -73,12 +75,12 @@ class ViewController: UIViewController, WKNavigationDelegate, UIPopoverPresentat
decisionHandler(.allow)
}
// UIPopoverPresentationControllerDelegate
func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
// MARK: - UIPopoverPresentationControllerDelegate
func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle
{
return .none
}
}
......@@ -2,27 +2,35 @@
A singleton that broadcasts touch events from the main window as notifications. See the demo app for a use case (to find out the location of a link that was clicked in a WKWebView).
**This is the Swift 3 branch.** Also available: [Master (Swift 2.2.1)](https://source.ind.ie/project/global-touch-notifications/tree/master) and [Swift 2.3](https://source.ind.ie/project/global-touch-notifications/tree/swift-2.3) branches.
**Supported on:** Xcode 8 Beta 6
## Installation
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
Run the `./install` script to install the dependencies for the demo apps.
### 1. Update your Cartfile
**Swift 3 (latest version)**
```
git "git@source.ind.ie:project/global-touch-notifications.git" ~> 6.0.0
```
For Swift 2.3, use the swift-2.3 branch:
See the [detailed installation instructions](#detailed-installation-instructions), below, for instructions on how to add Delay to your own apps.
```
git "git@source.ind.ie:project/global-touch-notifications.git" "swift-2.3"
```
To include the Swift 3 version in your own projects, please make sure you specify the swift-3 branch in your Cartfile:
To stay on Swift 2.2, use the 5.0.0 tag:
```
git "git@source.ind.ie:project/global-touch-notifications.git" "swift-3"
git "git@source.ind.ie:project/global-touch-notifications.git" ~> 5.0.0
```
## Getting started
## Demo
1. Run the `./install` script to install the dependencies for the demo apps.
Run the `./dev` script and play with the iOS demo app.
2. Run the `./dev` script and play with the iOS demo app.
## Usage
......@@ -38,7 +46,7 @@ GlobalTouchNotifications.sharedInstance
// Register for global touch notification
handle(GlobalTouchNotification.named(.TouchesBegan)
{
/* with */ notification in
/* with */ notification in
guard let
userInfo = notification.userInfo,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment