trifork / triforkswiftextensions Goto Github PK
View Code? Open in Web Editor NEWGeneric Trifork Swift Extensions
License: MIT License
Generic Trifork Swift Extensions
License: MIT License
Combined property for contentInset and scrollIndicatorInsets
. I always forget to set the scrollIndicatorInsets
when using contentInset
๐ฌ
isToday
extensions such as
presentOkAlert
should always return the created dialog, in case the user / consumer wants to say dismiss it afterwards.
Something like:
UIEdgeInsets(allSides: 10.0)
Requested (and implemented) by @ktvtrifork :
//
// GlobalDialog.swift
// Created by Kasper Tvede on 18/02/2019.
// Copyright ยฉ 2019 Trifork a/s. All rights reserved.
//
// inspiration drawn from https://github.com/agilityvision/FFGlobalAlertController
// && https://github.com/lostatseajoshua/Alerts/blob/master/Alerts/AlertCoordinator.swift
// and further see https://stackoverflow.com/a/25428409
import Foundation
import UIKit
// Declare a global var to produce a unique address as the assoc object handle for the alert window variable
private var alertWindowObjectHandle: UInt8 = 0
// Declare a global var to produce a unique address as the assoc object handle for the dialog id variable
private var dialogIdObjectHandle: UInt8 = 1
//static variables for functionality; kept private as this is quite edgy already.
private var numOfGlobalDialogsShowing: Int = 0
private var dialogIdSet: Set<Int> = Set()
// MARK: -
extension UIAlertController {
/// This creates a property on a ui alert controller via objective C.
private var alertWindow: UIWindow? {
get {
return objc_getAssociatedObject(self, &alertWindowObjectHandle) as? UIWindow
}
set {
objc_setAssociatedObject(self, &alertWindowObjectHandle, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
}
}
/// This creates a property on a ui alert controller via objective C.
private var dialogId: Int? {
get {
return objc_getAssociatedObject(self, &dialogIdObjectHandle) as? Int
}
set {
objc_setAssociatedObject(self, &dialogIdObjectHandle, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
}
}
//can safely be called from any thread, and anywhere. multiple calls will just stack up.
func showGlobally(animated: Bool = true) {
DispatchQueue.main.async {
numOfGlobalDialogsShowing += 1
let window = UIWindow(frame: UIScreen.main.bounds)
let rootController = UIViewController()
window.rootViewController = rootController
//above all else
window.windowLevel = UIWindow.Level.alert + 1
self.alertWindow = window
window.makeKeyAndVisible()
rootController.present(self, animated: animated)
}
}
/// Only shows the igen dialog iff there are no global dialogs there already.
///
/// - Parameter animated: true if the dialog should be animated in place
func showGloballyIfNoGlobalIsPresented(animated: Bool = true) {
if numOfGlobalDialogsShowing > 0 {
return
}
showGlobally(animated: animated)
}
/// a more advanced editon; where we simply map each dialog to a given id, and iff that id is presented then skips displaying it (akk preventing dual
/// displaing these dialogs).
///
/// - Parameters:
/// - id: the unique id, (so if mulitple dialogs contain this, then only the first one will be shown, prevents displaying multiple dialogs)
/// - animated: whenever the appearence should be animated
func showGloballyWithId(id: Int, animated: Bool = true) {
//force it though the main thread, thus ensuring no data raceing, since 1 thing can at max execute at the mainthread.
DispatchQueue.main.async {
if dialogIdSet.contains(id) {
return
}
dialogIdSet.insert(id)
self.dialogId = id
self.showGlobally(animated: animated)
}
}
//clean up when the dialog gets closed.
override open func viewDidDisappear(_ animated: Bool) {
super.viewDidAppear(animated)
//cleanup
numOfGlobalDialogsShowing -= 1
if let id = dialogId {
dialogIdSet.remove(id)
}
//dismiss all visible things.
alertWindow?.isHidden = true
//and make it possible to garbage collect
alertWindow = nil
}
}
public var midPoint: CGPoint {
return CGPoint(x: self.midX, y: self.midY)
}
There should be a textAlignment(NSTextAlignment)
type in the StringFormatOption
enum.
A simple potentially very permissive, set of swiftlint rules to for example disallow force trys and to make some of the styling more cohesive.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.