diff --git a/Display.xcodeproj/project.pbxproj b/Display.xcodeproj/project.pbxproj index 2305a05007..780cab3d93 100644 --- a/Display.xcodeproj/project.pbxproj +++ b/Display.xcodeproj/project.pbxproj @@ -64,7 +64,6 @@ D05CC3271B69725400E235A3 /* NavigationBackArrowLight@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = D05CC3261B69725400E235A3 /* NavigationBackArrowLight@2x.png */; }; D05CC3291B69750D00E235A3 /* InteractiveTransitionGestureRecognizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = D05CC3281B69750D00E235A3 /* InteractiveTransitionGestureRecognizer.swift */; }; D06EE8451B7140FF00837186 /* Font.swift in Sources */ = {isa = PBXBuildFile; fileRef = D06EE8441B7140FF00837186 /* Font.swift */; }; - D07921A91B6FC0C0005C23D9 /* KeyboardHostWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = D07921A81B6FC0C0005C23D9 /* KeyboardHostWindow.swift */; }; D081229D1D19AA1C005F7395 /* ContainerViewLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = D081229C1D19AA1C005F7395 /* ContainerViewLayout.swift */; }; D08E903A1D24159200533158 /* ActionSheetItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = D08E90391D24159200533158 /* ActionSheetItem.swift */; }; D08E903C1D2417E000533158 /* ActionSheetButtonItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = D08E903B1D2417E000533158 /* ActionSheetButtonItem.swift */; }; @@ -170,7 +169,6 @@ D05CC3261B69725400E235A3 /* NavigationBackArrowLight@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "NavigationBackArrowLight@2x.png"; sourceTree = ""; }; D05CC3281B69750D00E235A3 /* InteractiveTransitionGestureRecognizer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InteractiveTransitionGestureRecognizer.swift; sourceTree = ""; }; D06EE8441B7140FF00837186 /* Font.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Font.swift; sourceTree = ""; }; - D07921A81B6FC0C0005C23D9 /* KeyboardHostWindow.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeyboardHostWindow.swift; sourceTree = ""; }; D081229C1D19AA1C005F7395 /* ContainerViewLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContainerViewLayout.swift; sourceTree = ""; }; D08E90391D24159200533158 /* ActionSheetItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActionSheetItem.swift; sourceTree = ""; }; D08E903B1D2417E000533158 /* ActionSheetButtonItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActionSheetButtonItem.swift; sourceTree = ""; }; @@ -324,7 +322,6 @@ D03BCCE91C72AE4B0097A291 /* Theme */, D05CC3001B6955D500E235A3 /* Utils */, D07921AA1B6FC911005C23D9 /* Status Bar */, - D07921A71B6FC0AE005C23D9 /* Keyboard */, D05CC3211B695AA600E235A3 /* Navigation */, D0DC48521BF93D7C00F672FD /* Tabs */, D02BDAEC1B6A7053008AFAD2 /* Nodes */, @@ -418,14 +415,6 @@ name = Navigation; sourceTree = ""; }; - D07921A71B6FC0AE005C23D9 /* Keyboard */ = { - isa = PBXGroup; - children = ( - D07921A81B6FC0C0005C23D9 /* KeyboardHostWindow.swift */, - ); - name = Keyboard; - sourceTree = ""; - }; D07921AA1B6FC911005C23D9 /* Status Bar */ = { isa = PBXGroup; children = ( @@ -639,7 +628,6 @@ D0C2DFCA1CC4431D0044FF83 /* ListViewItem.swift in Sources */, D05CC2A01B69326400E235A3 /* NavigationController.swift in Sources */, D06EE8451B7140FF00837186 /* Font.swift in Sources */, - D07921A91B6FC0C0005C23D9 /* KeyboardHostWindow.swift in Sources */, D0C2DFCB1CC4431D0044FF83 /* ListViewAnimation.swift in Sources */, D05CC3251B695B0700E235A3 /* NavigationBarProxy.m in Sources */, D03E7DE61C96B96E00C07816 /* NavigationBarTransitionContainer.swift in Sources */, diff --git a/Display.xcodeproj/xcuserdata/peter.xcuserdatad/xcschemes/xcschememanagement.plist b/Display.xcodeproj/xcuserdata/peter.xcuserdatad/xcschemes/xcschememanagement.plist index 3dc3380d40..aa5ae0473f 100644 --- a/Display.xcodeproj/xcuserdata/peter.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/Display.xcodeproj/xcuserdata/peter.xcuserdatad/xcschemes/xcschememanagement.plist @@ -12,7 +12,7 @@ DisplayTests.xcscheme orderHint - 15 + 14 SuppressBuildableAutocreation diff --git a/Display/ASTransformLayerNode.swift b/Display/ASTransformLayerNode.swift index 72c5ef9729..0e204e8074 100644 --- a/Display/ASTransformLayerNode.swift +++ b/Display/ASTransformLayerNode.swift @@ -2,7 +2,7 @@ import Foundation import AsyncDisplayKit class ASTransformLayer: CATransformLayer { - override var contents: AnyObject? { + override var contents: Any? { get { return nil } set(value) { @@ -31,7 +31,7 @@ class ASTransformView: UIView { } } -public class ASTransformLayerNode: ASDisplayNode { +open class ASTransformLayerNode: ASDisplayNode { public override init() { super.init(layerBlock: { return ASTransformLayer() @@ -39,7 +39,7 @@ public class ASTransformLayerNode: ASDisplayNode { } } -public class ASTransformViewNode: ASDisplayNode { +open class ASTransformViewNode: ASDisplayNode { public override init() { super.init(viewBlock: { return ASTransformView() @@ -47,7 +47,7 @@ public class ASTransformViewNode: ASDisplayNode { } } -public class ASTransformNode: ASDisplayNode { +open class ASTransformNode: ASDisplayNode { public init(layerBacked: Bool = true) { if layerBacked { super.init(layerBlock: { diff --git a/Display/ActionSheetButtonItem.swift b/Display/ActionSheetButtonItem.swift index b0435d21f6..ccd5ebfd43 100644 --- a/Display/ActionSheetButtonItem.swift +++ b/Display/ActionSheetButtonItem.swift @@ -10,7 +10,7 @@ public class ActionSheetButtonItem: ActionSheetItem { public let color: ActionSheetButtonColor public let action: () -> Void - public init(title: String, color: ActionSheetButtonColor = .accent, action: () -> Void) { + public init(title: String, color: ActionSheetButtonColor = .accent, action: @escaping () -> Void) { self.title = title self.color = color self.action = action diff --git a/Display/ActionSheetButtonNode.swift b/Display/ActionSheetButtonNode.swift index e740f94b43..396d6623bf 100644 --- a/Display/ActionSheetButtonNode.swift +++ b/Display/ActionSheetButtonNode.swift @@ -10,7 +10,7 @@ public class ActionSheetButtonNode: ActionSheetItemNode { private let label: UILabel private var calculatedLabelSize: CGSize? - public init(title: NSAttributedString, action: () -> Void) { + public init(title: NSAttributedString, action: @escaping () -> Void) { self.action = action self.button = HighlightTrackingButton() diff --git a/Display/ActionSheetController.swift b/Display/ActionSheetController.swift index afb7038bb6..0b6191f424 100644 --- a/Display/ActionSheetController.swift +++ b/Display/ActionSheetController.swift @@ -1,6 +1,6 @@ import Foundation -public class ActionSheetController: ViewController { +open class ActionSheetController: ViewController { private var actionSheetNode: ActionSheetControllerNode { return self.displayNode as! ActionSheetControllerNode } @@ -11,7 +11,7 @@ public class ActionSheetController: ViewController { self.actionSheetNode.animateOut() } - public override func loadDisplayNode() { + open override func loadDisplayNode() { self.displayNode = ActionSheetControllerNode() self.displayNodeDidLoad() self.navigationBar.isHidden = true @@ -23,13 +23,13 @@ public class ActionSheetController: ViewController { self.actionSheetNode.setGroups(self.groups) } - override public func containerLayoutUpdated(_ layout: ContainerViewLayout, transition: ContainedViewLayoutTransition) { + override open func containerLayoutUpdated(_ layout: ContainerViewLayout, transition: ContainedViewLayoutTransition) { super.containerLayoutUpdated(layout, transition: transition) self.actionSheetNode.containerLayoutUpdated(layout, transition: transition) } - public override func viewWillAppear(_ animated: Bool) { + open override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) self.actionSheetNode.animateIn() diff --git a/Display/ActionSheetItemNode.swift b/Display/ActionSheetItemNode.swift index a41f3d71d7..22214130a3 100644 --- a/Display/ActionSheetItemNode.swift +++ b/Display/ActionSheetItemNode.swift @@ -1,7 +1,7 @@ import UIKit import AsyncDisplayKit -public class ActionSheetItemNode: ASDisplayNode { +open class ActionSheetItemNode: ASDisplayNode { public static let defaultBackgroundColor: UIColor = UIColor(white: 1.0, alpha: 0.8) public static let highlightedBackgroundColor: UIColor = UIColor(white: 0.9, alpha: 0.7) @@ -21,11 +21,11 @@ public class ActionSheetItemNode: ASDisplayNode { self.addSubnode(self.overflowSeparatorNode) } - public override func calculateSizeThatFits(_ constrainedSize: CGSize) -> CGSize { + open override func calculateSizeThatFits(_ constrainedSize: CGSize) -> CGSize { return CGSize(width: constrainedSize.width, height: 57.0) } - public override func layout() { + open override func layout() { self.backgroundNode.frame = CGRect(origin: CGPoint(), size: self.calculatedSize) self.overflowSeparatorNode.frame = CGRect(origin: CGPoint(x: 0.0, y: self.calculatedSize.height), size: CGSize(width: self.calculatedSize.width, height: UIScreenPixel)) } diff --git a/Display/BarButtonItemWrapper.swift b/Display/BarButtonItemWrapper.swift index 02b62f6aa3..3e6f1b5695 100644 --- a/Display/BarButtonItemWrapper.swift +++ b/Display/BarButtonItemWrapper.swift @@ -11,7 +11,7 @@ internal class BarButtonItemWrapper { private var setEnabledListenerKey: Int! private var setTitleListenerKey: Int! - init(parentNode: ASDisplayNode, barButtonItem: UIBarButtonItem, layoutNeeded: () -> ()) { + init(parentNode: ASDisplayNode, barButtonItem: UIBarButtonItem, layoutNeeded: @escaping () -> ()) { self.parentNode = parentNode self.barButtonItem = barButtonItem self.layoutNeeded = layoutNeeded diff --git a/Display/ContainerViewLayout.swift b/Display/ContainerViewLayout.swift index a1f66c887c..f2df5b9655 100644 --- a/Display/ContainerViewLayout.swift +++ b/Display/ContainerViewLayout.swift @@ -36,10 +36,10 @@ public struct ContainerViewLayout: Equatable { public func insets(options: ContainerViewLayoutInsetOptions) -> UIEdgeInsets { var insets = self.intrinsicInsets - if let statusBarHeight = self.statusBarHeight where options.contains(.statusBar) { + if let statusBarHeight = self.statusBarHeight , options.contains(.statusBar) { insets.top += statusBarHeight } - if let inputHeight = self.inputHeight where options.contains(.input) { + if let inputHeight = self.inputHeight , options.contains(.input) { insets.bottom = max(inputHeight, insets.bottom) } return insets diff --git a/Display/DisplayLinkDispatcher.swift b/Display/DisplayLinkDispatcher.swift index 16d054c4da..7e14daed58 100644 --- a/Display/DisplayLinkDispatcher.swift +++ b/Display/DisplayLinkDispatcher.swift @@ -18,7 +18,7 @@ public class DisplayLinkDispatcher: NSObject { self.displayLink.add(to: RunLoop.main, forMode: RunLoopMode.commonModes) } - public func dispatch(f: (Void) -> Void) { + public func dispatch(f: @escaping (Void) -> Void) { self.blocksToDispatch.append(f) self.displayLink.isPaused = false } diff --git a/Display/GenerateImage.swift b/Display/GenerateImage.swift index 031843fd81..ecd6729ba5 100644 --- a/Display/GenerateImage.swift +++ b/Display/GenerateImage.swift @@ -9,7 +9,7 @@ public func generateImage(_ size: CGSize, pixelGenerator: (CGSize, UnsafeMutable let scaledSize = CGSize(width: size.width * scale, height: size.height * scale) let bytesPerRow = (4 * Int(scaledSize.width) + 15) & (~15) let length = bytesPerRow * Int(scaledSize.height) - let bytes = UnsafeMutablePointer(malloc(length)!) + let bytes = malloc(length)!.assumingMemoryBound(to: Int8.self) guard let provider = CGDataProvider(dataInfo: bytes, data: bytes, size: length, releaseData: { bytes, _, _ in free(bytes) }) @@ -34,7 +34,7 @@ public func generateImage(_ size: CGSize, contextGenerator: (CGSize, CGContext) let scaledSize = CGSize(width: size.width * scale, height: size.height * scale) let bytesPerRow = (4 * Int(scaledSize.width) + 15) & (~15) let length = bytesPerRow * Int(scaledSize.height) - let bytes = UnsafeMutablePointer(malloc(length)!) + let bytes = malloc(length)!.assumingMemoryBound(to: Int8.self) guard let provider = CGDataProvider(dataInfo: bytes, data: bytes, size: length, releaseData: { bytes, _, _ in free(bytes) @@ -102,7 +102,7 @@ public class DrawingContext { public let bytesPerRow: Int private let bitmapInfo: CGBitmapInfo public let length: Int - public let bytes: UnsafeMutablePointer + public let bytes: UnsafeMutableRawPointer let provider: CGDataProvider? private var _context: CGContext? @@ -151,7 +151,7 @@ public class DrawingContext { self.bitmapInfo = CGBitmapInfo(rawValue: CGBitmapInfo.byteOrder32Little.rawValue | CGImageAlphaInfo.premultipliedFirst.rawValue) - self.bytes = UnsafeMutablePointer(malloc(length)) + self.bytes = malloc(length)! if clear { memset(self.bytes, 0, self.length) } @@ -172,7 +172,7 @@ public class DrawingContext { let x = Int(point.x * self.scale) let y = Int(point.y * self.scale) if x >= 0 && x < Int(self.scaledSize.width) && y >= 0 && y < Int(self.scaledSize.height) { - let srcLine = UnsafeMutablePointer(self.bytes + y * self.bytesPerRow) + let srcLine = self.bytes.advanced(by: y * self.bytesPerRow).assumingMemoryBound(to: UInt32.self) let pixel = srcLine + x let colorValue = pixel.pointee return UIColor(UInt32(colorValue)) @@ -197,8 +197,8 @@ public class DrawingContext { switch mode { case .Alpha: while dstY < maxDstY { - let srcLine = UnsafeMutablePointer(other.bytes + srcY * other.bytesPerRow) - let dstLine = UnsafeMutablePointer(self.bytes + dstY * self.bytesPerRow) + let srcLine = other.bytes.advanced(by: srcY * other.bytesPerRow).assumingMemoryBound(to: UInt32.self) + let dstLine = self.bytes.advanced(by: dstY * self.bytesPerRow).assumingMemoryBound(to: UInt32.self) var dx = dstX var sx = srcX @@ -278,13 +278,13 @@ public func drawSvgPath(_ context: CGContext, path: StaticString) throws { let y = try readCGFloat(&index, end: end, separator: 32) //print("Move to \(x), \(y)") - context.moveTo(x: x, y: y) + context.move(to: CGPoint(x: x, y: y)) } else if c == 76 { // L let x = try readCGFloat(&index, end: end, separator: 44) let y = try readCGFloat(&index, end: end, separator: 32) //print("Line to \(x), \(y)") - context.addLineTo(x: x, y: y) + context.addLine(to: CGPoint(x: x, y: y)) } else if c == 67 { // C let x1 = try readCGFloat(&index, end: end, separator: 44) let y1 = try readCGFloat(&index, end: end, separator: 32) @@ -292,7 +292,7 @@ public func drawSvgPath(_ context: CGContext, path: StaticString) throws { let y2 = try readCGFloat(&index, end: end, separator: 32) let x = try readCGFloat(&index, end: end, separator: 44) let y = try readCGFloat(&index, end: end, separator: 32) - context.addCurveTo(cp1x: x1, cp1y: y1, cp2x: x2, cp2y: y2, endingAtX: x, y: y) + context.addCurve(to: CGPoint(x: x1, y: y1), control1: CGPoint(x: x2, y: y2), control2: CGPoint(x: x, y: y)) //print("Line to \(x), \(y)") diff --git a/Display/InteractiveTransitionGestureRecognizer.swift b/Display/InteractiveTransitionGestureRecognizer.swift index 79c07faaae..e6fde67334 100644 --- a/Display/InteractiveTransitionGestureRecognizer.swift +++ b/Display/InteractiveTransitionGestureRecognizer.swift @@ -5,7 +5,7 @@ class InteractiveTransitionGestureRecognizer: UIPanGestureRecognizer { var validatedGesture = false var firstLocation: CGPoint = CGPoint() - override init(target: AnyObject?, action: Selector?) { + override init(target: Any?, action: Selector?) { super.init(target: target, action: action) self.maximumNumberOfTouches = 1 diff --git a/Display/KeyboardHostWindow.swift b/Display/KeyboardHostWindow.swift deleted file mode 100644 index 114a07f70c..0000000000 --- a/Display/KeyboardHostWindow.swift +++ /dev/null @@ -1,28 +0,0 @@ -import Foundation -import UIKit - -public class KeyboardHostWindow: UIWindow { - public let textField: UITextField - - convenience public init() { - self.init(frame: CGRect()) - } - - override init(frame: CGRect) { - self.textField = UITextField(frame: CGRect(x: -110.0, y: 0.0, width: 100.0, height: 50.0)) - - super.init(frame: frame) - - self.windowLevel = -1.0 - self.rootViewController = UIViewController() - self.addSubview(self.textField) - } - - required public init?(coder aDecoder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - - public func acquireFirstResponder() { - textField.becomeFirstResponder() - } -} diff --git a/Display/ListView.swift b/Display/ListView.swift index 33bed43bcd..970e34e9f8 100644 --- a/Display/ListView.swift +++ b/Display/ListView.swift @@ -298,7 +298,7 @@ private struct ListViewState { mutating func fixScrollPostition(_ itemCount: Int) { if let (fixedIndex, fixedPosition) = self.scrollPosition { for node in self.nodes { - if let index = node.index where index == fixedIndex { + if let index = node.index , index == fixedIndex { let offset: CGFloat switch fixedPosition { case .Bottom: @@ -372,7 +372,7 @@ private struct ListViewState { mutating func setupStationaryOffset(_ index: Int, boundary: Int, frames: [Int: CGRect]) { if index < boundary { for node in self.nodes { - if let nodeIndex = node.index where nodeIndex >= index { + if let nodeIndex = node.index , nodeIndex >= index { if let frame = frames[nodeIndex] { self.stationaryOffset = (nodeIndex, frame.minY) break @@ -381,7 +381,7 @@ private struct ListViewState { } } else { for node in self.nodes.reversed() { - if let nodeIndex = node.index where nodeIndex <= index { + if let nodeIndex = node.index , nodeIndex <= index { if let frame = frames[nodeIndex] { self.stationaryOffset = (nodeIndex, frame.minY) break @@ -459,7 +459,7 @@ private struct ListViewState { if let (fixedIndex, _) = self.scrollPosition { for i in 0 ..< self.nodes.count { let node = self.nodes[i] - if let index = node.index where index == fixedIndex { + if let index = node.index , index == fixedIndex { fixedNode = (i, index, node.frame) break } @@ -474,7 +474,7 @@ private struct ListViewState { if let (fixedIndex, _) = self.stationaryOffset { for i in 0 ..< self.nodes.count { let node = self.nodes[i] - if let index = node.index where index == fixedIndex { + if let index = node.index , index == fixedIndex { fixedNode = (i, index, node.frame) break } @@ -485,7 +485,7 @@ private struct ListViewState { if fixedNode == nil { for i in 0 ..< self.nodes.count { let node = self.nodes[i] - if let index = node.index where node.frame.maxY >= self.insets.top { + if let index = node.index , node.frame.maxY >= self.insets.top { fixedNode = (i, index, node.frame) break } @@ -510,7 +510,7 @@ private struct ListViewState { if index != currentUpperNode.index - 1 { if currentUpperNode.frame.minY > -self.invisibleInset - CGFloat(FLT_EPSILON) { var directionHint: ListViewInsertionOffsetDirection? - if let hint = insertDirectionHints[currentUpperNode.index - 1] where currentUpperNode.frame.minY > self.insets.top - CGFloat(FLT_EPSILON) { + if let hint = insertDirectionHints[currentUpperNode.index - 1] , currentUpperNode.frame.minY > self.insets.top - CGFloat(FLT_EPSILON) { directionHint = ListViewInsertionOffsetDirection(hint) } return ListViewInsertionPoint(index: currentUpperNode.index - 1, point: CGPoint(x: 0.0, y: currentUpperNode.frame.minY), direction: directionHint ?? .Up) @@ -524,7 +524,7 @@ private struct ListViewState { if currentUpperNode.index != 0 && currentUpperNode.frame.minY > -self.invisibleInset - CGFloat(FLT_EPSILON) { var directionHint: ListViewInsertionOffsetDirection? - if let hint = insertDirectionHints[currentUpperNode.index - 1] where currentUpperNode.frame.minY > self.insets.top - CGFloat(FLT_EPSILON) { + if let hint = insertDirectionHints[currentUpperNode.index - 1] , currentUpperNode.frame.minY > self.insets.top - CGFloat(FLT_EPSILON) { directionHint = ListViewInsertionOffsetDirection(hint) } @@ -539,7 +539,7 @@ private struct ListViewState { if index != currentLowerNode.index + 1 { if currentLowerNode.frame.maxY < self.visibleSize.height + self.invisibleInset - CGFloat(FLT_EPSILON) { var directionHint: ListViewInsertionOffsetDirection? - if let hint = insertDirectionHints[currentLowerNode.index + 1] where currentLowerNode.frame.maxY < self.visibleSize.height - self.insets.bottom + CGFloat(FLT_EPSILON) { + if let hint = insertDirectionHints[currentLowerNode.index + 1] , currentLowerNode.frame.maxY < self.visibleSize.height - self.insets.bottom + CGFloat(FLT_EPSILON) { directionHint = ListViewInsertionOffsetDirection(hint) } return ListViewInsertionPoint(index: currentLowerNode.index + 1, point: CGPoint(x: 0.0, y: currentLowerNode.frame.maxY), direction: directionHint ?? .Down) @@ -554,7 +554,7 @@ private struct ListViewState { if currentLowerNode.index != itemCount - 1 && currentLowerNode.frame.maxY < self.visibleSize.height + self.invisibleInset - CGFloat(FLT_EPSILON) { var directionHint: ListViewInsertionOffsetDirection? - if let hint = insertDirectionHints[currentLowerNode.index + 1] where currentLowerNode.frame.maxY < self.visibleSize.height - self.insets.bottom + CGFloat(FLT_EPSILON) { + if let hint = insertDirectionHints[currentLowerNode.index + 1] , currentLowerNode.frame.maxY < self.visibleSize.height - self.insets.bottom + CGFloat(FLT_EPSILON) { directionHint = ListViewInsertionOffsetDirection(hint) } return ListViewInsertionPoint(index: currentLowerNode.index + 1, point: CGPoint(x: 0.0, y: currentLowerNode.frame.maxY), direction: directionHint ?? .Down) @@ -592,7 +592,7 @@ private struct ListViewState { let upperBound = -self.invisibleInset + CGFloat(FLT_EPSILON) for i in 0 ..< self.nodes.count { let node = self.nodes[i] - if let index = node.index where node.frame.maxY > upperBound { + if let index = node.index , node.frame.maxY > upperBound { if i != 0 { var previousIndex = index for j in (0 ..< i).reversed() { @@ -616,7 +616,7 @@ private struct ListViewState { let lowerBound = self.visibleSize.height + self.invisibleInset - CGFloat(FLT_EPSILON) for i in (0 ..< self.nodes.count).reversed() { let node = self.nodes[i] - if let index = node.index where node.frame.minY < lowerBound { + if let index = node.index , node.frame.minY < lowerBound { if i != self.nodes.count - 1 { var previousIndex = index var removeIndices: [Int] = [] @@ -700,7 +700,7 @@ private struct ListViewState { return height } - mutating func insertNode(_ itemIndex: Int, node: ListViewItemNode, layout: ListViewItemNodeLayout, apply: () -> (), offsetDirection: ListViewInsertionOffsetDirection, animated: Bool, operations: inout [ListViewStateOperation], itemCount: Int) { + mutating func insertNode(_ itemIndex: Int, node: ListViewItemNode, layout: ListViewItemNodeLayout, apply: @escaping () -> (), offsetDirection: ListViewInsertionOffsetDirection, animated: Bool, operations: inout [ListViewStateOperation], itemCount: Int) { let (insertionOrigin, insertionIndex) = self.nodeInsertionPointAndIndex(itemIndex) let nodeOrigin: CGPoint @@ -774,12 +774,12 @@ private struct ListViewState { } operations.append(.Remove(index: index, offsetDirection: offsetDirection)) - if let referenceNode = referenceNode where animated { + if let referenceNode = referenceNode , animated { self.nodes.insert(.Placeholder(frame: nodeFrame), at: index) operations.append(.InsertPlaceholder(index: index, referenceNode: referenceNode, offsetDirection: offsetDirection.inverted())) } else { if nodeFrame.maxY > self.insets.top - CGFloat(FLT_EPSILON) { - if let direction = direction where direction == .Down && node.frame.minY < self.visibleSize.height - self.insets.bottom + CGFloat(FLT_EPSILON) { + if let direction = direction , direction == .Down && node.frame.minY < self.visibleSize.height - self.insets.bottom + CGFloat(FLT_EPSILON) { for i in (0 ..< index).reversed() { var frame = self.nodes[i].frame frame.origin.y += nodeFrame.size.height @@ -805,7 +805,7 @@ private struct ListViewState { } } - mutating func updateNodeAtItemIndex(_ itemIndex: Int, layout: ListViewItemNodeLayout, direction: ListViewItemOperationDirectionHint?, animation: ListViewItemUpdateAnimation, apply: () -> Void, operations: inout [ListViewStateOperation]) { + mutating func updateNodeAtItemIndex(_ itemIndex: Int, layout: ListViewItemNodeLayout, direction: ListViewItemOperationDirectionHint?, animation: ListViewItemUpdateAnimation, apply: @escaping () -> Void, operations: inout [ListViewStateOperation]) { var i = -1 for node in self.nodes { i += 1 @@ -912,7 +912,7 @@ private final class ListViewBackingView: UIView { private final class ListViewTimerProxy: NSObject { private let action: () -> () - init(_ action: () -> ()) { + init(_ action: @escaping () -> ()) { self.action = action super.init() } @@ -1111,7 +1111,7 @@ public final class ListView: ASDisplayNode, UIScrollViewDelegate { } } - private func dispatchOnVSync(forceNext: Bool = false, action: () -> ()) { + private func dispatchOnVSync(forceNext: Bool = false, action: @escaping () -> ()) { Queue.mainQueue().async { if !forceNext && self.inVSync { action() @@ -1280,7 +1280,7 @@ public final class ListView: ASDisplayNode, UIScrollViewDelegate { private func updateVisibleContentOffset() { var offset: CGFloat? - if let itemNode = self.itemNodes.first, index = itemNode.index where index == 0 { + if let itemNode = self.itemNodes.first, let index = itemNode.index , index == 0 { offset = -(itemNode.apparentFrame.minY - self.insets.top) } @@ -1348,11 +1348,11 @@ public final class ListView: ASDisplayNode, UIScrollViewDelegate { self.ignoreScrollingEvents = false } - private func async(_ f: () -> Void) { + private func async(_ f: @escaping () -> Void) { DispatchQueue.global().async(execute: f) } - private func nodeForItem(synchronous: Bool, item: ListViewItem, previousNode: ListViewItemNode?, index: Int, previousItem: ListViewItem?, nextItem: ListViewItem?, width: CGFloat, updateAnimation: ListViewItemUpdateAnimation, completion: (ListViewItemNode, ListViewItemNodeLayout, () -> Void) -> Void) { + private func nodeForItem(synchronous: Bool, item: ListViewItem, previousNode: ListViewItemNode?, index: Int, previousItem: ListViewItem?, nextItem: ListViewItem?, width: CGFloat, updateAnimation: ListViewItemUpdateAnimation, completion: @escaping (ListViewItemNode, ListViewItemNodeLayout, @escaping () -> Void) -> Void) { if let previousNode = previousNode { item.updateNode(async: { f in if synchronous { @@ -1409,7 +1409,7 @@ public final class ListView: ASDisplayNode, UIScrollViewDelegate { return ListViewState(insets: self.insets, visibleSize: self.visibleSize, invisibleInset: self.invisibleInset, nodes: nodes, scrollPosition: nil, stationaryOffset: nil) } - public func deleteAndInsertItems(deleteIndices: [ListViewDeleteItem], insertIndicesAndItems: [ListViewInsertItem], updateIndicesAndItems: [ListViewUpdateItem], options: ListViewDeleteAndInsertOptions, scrollToItem: ListViewScrollToItem? = nil, updateSizeAndInsets: ListViewUpdateSizeAndInsets? = nil, stationaryItemRange: (Int, Int)? = nil, completion: (ListViewDisplayedItemRange) -> Void = { _ in }) { + public func deleteAndInsertItems(deleteIndices: [ListViewDeleteItem], insertIndicesAndItems: [ListViewInsertItem], updateIndicesAndItems: [ListViewUpdateItem], options: ListViewDeleteAndInsertOptions, scrollToItem: ListViewScrollToItem? = nil, updateSizeAndInsets: ListViewUpdateSizeAndInsets? = nil, stationaryItemRange: (Int, Int)? = nil, completion: @escaping (ListViewDisplayedItemRange) -> Void = { _ in }) { if deleteIndices.isEmpty && insertIndicesAndItems.isEmpty && updateIndicesAndItems.isEmpty && scrollToItem == nil && updateSizeAndInsets == nil { completion(self.immediateDisplayedItemRange()) return @@ -1427,9 +1427,9 @@ public final class ListView: ASDisplayNode, UIScrollViewDelegate { }) } - private func deleteAndInsertItemsTransaction(deleteIndices: [ListViewDeleteItem], insertIndicesAndItems: [ListViewInsertItem], updateIndicesAndItems: [ListViewUpdateItem], options: ListViewDeleteAndInsertOptions, scrollToItem: ListViewScrollToItem?, updateSizeAndInsets: ListViewUpdateSizeAndInsets?, stationaryItemRange: (Int, Int)?, completion: (Void) -> Void) { + private func deleteAndInsertItemsTransaction(deleteIndices: [ListViewDeleteItem], insertIndicesAndItems: [ListViewInsertItem], updateIndicesAndItems: [ListViewUpdateItem], options: ListViewDeleteAndInsertOptions, scrollToItem: ListViewScrollToItem?, updateSizeAndInsets: ListViewUpdateSizeAndInsets?, stationaryItemRange: (Int, Int)?, completion: @escaping (Void) -> Void) { if deleteIndices.isEmpty && insertIndicesAndItems.isEmpty && scrollToItem == nil { - if let updateSizeAndInsets = updateSizeAndInsets where self.items.count == 0 || (updateSizeAndInsets.size == self.visibleSize && updateSizeAndInsets.insets == self.insets) { + if let updateSizeAndInsets = updateSizeAndInsets , self.items.count == 0 || (updateSizeAndInsets.size == self.visibleSize && updateSizeAndInsets.insets == self.insets) { self.visibleSize = updateSizeAndInsets.size self.insets = updateSizeAndInsets.insets @@ -1709,7 +1709,7 @@ public final class ListView: ASDisplayNode, UIScrollViewDelegate { } } - private func updateAdjacent(synchronous: Bool, animated: Bool, state: ListViewState, updateAdjacentItemsIndices: Set, operations: [ListViewStateOperation], completion: (ListViewState, [ListViewStateOperation]) -> Void) { + private func updateAdjacent(synchronous: Bool, animated: Bool, state: ListViewState, updateAdjacentItemsIndices: Set, operations: [ListViewStateOperation], completion: @escaping (ListViewState, [ListViewStateOperation]) -> Void) { if updateAdjacentItemsIndices.isEmpty { completion(state, operations) } else { @@ -1722,7 +1722,7 @@ public final class ListView: ASDisplayNode, UIScrollViewDelegate { var i = 0 for node in state.nodes { - if case let .Node(index, _, referenceNode) = node where index == nodeIndex { + if case let .Node(index, _, referenceNode) = node , index == nodeIndex { if let referenceNode = referenceNode { continueWithoutNode = false self.items[index].updateNode(async: { f in @@ -1758,7 +1758,7 @@ public final class ListView: ASDisplayNode, UIScrollViewDelegate { } } - private func fillMissingNodes(synchronous: Bool, animated: Bool, inputAnimatedInsertIndices: Set, insertDirectionHints: [Int: ListViewItemOperationDirectionHint], inputState: ListViewState, inputPreviousNodes: [Int: ListViewItemNode], inputOperations: [ListViewStateOperation], inputCompletion: (ListViewState, [ListViewStateOperation]) -> Void) { + private func fillMissingNodes(synchronous: Bool, animated: Bool, inputAnimatedInsertIndices: Set, insertDirectionHints: [Int: ListViewItemOperationDirectionHint], inputState: ListViewState, inputPreviousNodes: [Int: ListViewItemNode], inputOperations: [ListViewStateOperation], inputCompletion: @escaping (ListViewState, [ListViewStateOperation]) -> Void) { let animatedInsertIndices = inputAnimatedInsertIndices var state = inputState var previousNodes = inputPreviousNodes @@ -1817,7 +1817,7 @@ public final class ListView: ASDisplayNode, UIScrollViewDelegate { } } - private func updateNodes(synchronous: Bool, animated: Bool, updateIndicesAndItems: [ListViewUpdateItem], inputState: ListViewState, previousNodes: [Int: ListViewItemNode], inputOperations: [ListViewStateOperation], completion: (ListViewState, [ListViewStateOperation]) -> Void) { + private func updateNodes(synchronous: Bool, animated: Bool, updateIndicesAndItems: [ListViewUpdateItem], inputState: ListViewState, previousNodes: [Int: ListViewItemNode], inputOperations: [ListViewStateOperation], completion: @escaping (ListViewState, [ListViewStateOperation]) -> Void) { var state = inputState var operations = inputOperations var updateIndicesAndItems = updateIndicesAndItems @@ -1895,7 +1895,7 @@ public final class ListView: ASDisplayNode, UIScrollViewDelegate { var offsetHeight = node.apparentHeight var takenAnimation = false - if let _ = previousFrame where animated && node.index != nil && nodeIndex != self.itemNodes.count - 1 { + if let _ = previousFrame , animated && node.index != nil && nodeIndex != self.itemNodes.count - 1 { let nextNode = self.itemNodes[nodeIndex + 1] if nextNode.index == nil { let nextHeight = nextNode.apparentHeight @@ -2121,7 +2121,7 @@ public final class ListView: ASDisplayNode, UIScrollViewDelegate { self.stopScrolling() for itemNode in self.itemNodes { - if let index = itemNode.index where index == scrollToItem.index { + if let index = itemNode.index , index == scrollToItem.index { let offset: CGFloat switch scrollToItem.position { case .Bottom: @@ -2157,7 +2157,7 @@ public final class ListView: ASDisplayNode, UIScrollViewDelegate { }*/ } else if let stationaryItemIndex = stationaryItemIndex { for itemNode in self.itemNodes { - if let index = itemNode.index where index == stationaryItemIndex { + if let index = itemNode.index , index == stationaryItemIndex { for (previousNode, previousFrame) in previousApparentFrames { if previousNode === itemNode { let offset = previousFrame.minY - itemNode.frame.minY @@ -2237,7 +2237,7 @@ public final class ListView: ASDisplayNode, UIScrollViewDelegate { self.updateAccessoryNodes(animated: animated, currentTimestamp: timestamp) self.updateFloatingAccessoryNodes(animated: animated, currentTimestamp: timestamp) - if let scrollToItem = scrollToItem where scrollToItem.animated { + if let scrollToItem = scrollToItem , scrollToItem.animated { if self.itemNodes.count != 0 { var offset: CGFloat? @@ -2275,7 +2275,7 @@ public final class ListView: ASDisplayNode, UIScrollViewDelegate { offset = offsetValue - sizeAndInsetsOffset } - if let offset = offset where abs(offset) > CGFloat(FLT_EPSILON) { + if let offset = offset , abs(offset) > CGFloat(FLT_EPSILON) { for itemNode in temporaryPreviousNodes { itemNode.frame = itemNode.frame.offsetBy(dx: 0.0, dy: offset) temporaryPreviousNodes.append(itemNode) @@ -2355,7 +2355,7 @@ public final class ListView: ASDisplayNode, UIScrollViewDelegate { if self.debugInfo { var previousMaxY: CGFloat? for node in self.itemNodes { - if let previousMaxY = previousMaxY where abs(previousMaxY - node.apparentFrame.minY) > CGFloat(FLT_EPSILON) { + if let previousMaxY = previousMaxY , abs(previousMaxY - node.apparentFrame.minY) > CGFloat(FLT_EPSILON) { print("monotonity violated") break } @@ -2397,7 +2397,7 @@ public final class ListView: ASDisplayNode, UIScrollViewDelegate { let nextItemNode = self.itemNodes[i] if let nextItemNodeIndex = nextItemNode.index { let nextItem = self.items[nextItemNodeIndex] - if let nextAccessoryItem = nextItem.accessoryItem where nextAccessoryItem.isEqualToItem(accessoryItem) { + if let nextAccessoryItem = nextItem.accessoryItem , nextAccessoryItem.isEqualToItem(accessoryItem) { if let nextAccessoryItemNode = nextItemNode.accessoryItemNode { didStealAccessoryNode = true @@ -2455,7 +2455,7 @@ public final class ListView: ASDisplayNode, UIScrollViewDelegate { let nextItemNode = self.itemNodes[i] if let nextItemNodeIndex = nextItemNode.index { let nextItem = self.items[nextItemNodeIndex] - if let nextHeaderAccessoryItem = nextItem.headerAccessoryItem where nextHeaderAccessoryItem.isEqualToItem(headerAccessoryItem) { + if let nextHeaderAccessoryItem = nextItem.headerAccessoryItem , nextHeaderAccessoryItem.isEqualToItem(headerAccessoryItem) { if let nextHeaderAccessoryItemNode = nextItemNode.headerAccessoryItemNode { didStealHeaderAccessoryNode = true @@ -2547,7 +2547,7 @@ public final class ListView: ASDisplayNode, UIScrollViewDelegate { } } - private func updateVisibleItemsTransaction(completion: (Void) -> Void) { + private func updateVisibleItemsTransaction(completion: @escaping (Void) -> Void) { if self.items.count == 0 && self.itemNodes.count == 0 { completion() return @@ -2605,7 +2605,7 @@ public final class ListView: ASDisplayNode, UIScrollViewDelegate { } i -= 1 } - if let firstIndex = firstIndex, lastIndex = lastIndex { + if let firstIndex = firstIndex, let lastIndex = lastIndex { var firstVisibleIndex: Int? for i in firstIndex.nodeIndex ... lastIndex.nodeIndex { if let index = self.itemNodes[i].index { @@ -2662,7 +2662,7 @@ public final class ListView: ASDisplayNode, UIScrollViewDelegate { } } - private func updateSizeAndInsetsTransaction(size: CGSize, insets: UIEdgeInsets, duration: Double, options: UIViewAnimationOptions, completion: (Void) -> Void) { + private func updateSizeAndInsetsTransaction(size: CGSize, insets: UIEdgeInsets, duration: Double, options: UIViewAnimationOptions, completion: @escaping (Void) -> Void) { if size.equalTo(self.visibleSize) && UIEdgeInsetsEqualToEdgeInsets(self.insets, insets) { completion() } else { @@ -2875,7 +2875,7 @@ public final class ListView: ASDisplayNode, UIScrollViewDelegate { self.selectionTouchDelayTimer?.invalidate() let timer = Timer(timeInterval: 0.08, target: ListViewTimerProxy { [weak self] in - if let strongSelf = self where strongSelf.selectionTouchLocation != nil { + if let strongSelf = self , strongSelf.selectionTouchLocation != nil { strongSelf.clearHighlightAnimated(false) let index = strongSelf.itemIndexAtPoint(strongSelf.touchesPosition) diff --git a/Display/ListViewAccessoryItemNode.swift b/Display/ListViewAccessoryItemNode.swift index 284bfcc13e..baeccbac18 100644 --- a/Display/ListViewAccessoryItemNode.swift +++ b/Display/ListViewAccessoryItemNode.swift @@ -1,7 +1,7 @@ import Foundation import AsyncDisplayKit -public class ListViewAccessoryItemNode: ASDisplayNode { +open class ListViewAccessoryItemNode: ASDisplayNode { var transitionOffset: CGPoint = CGPoint() { didSet { self.bounds = CGRect(origin: self.transitionOffset, size: self.bounds.size) @@ -10,7 +10,7 @@ public class ListViewAccessoryItemNode: ASDisplayNode { private var transitionOffsetAnimation: ListViewAnimation? - final func animateTransitionOffset(_ from: CGPoint, beginAt: Double, duration: Double, curve: (CGFloat) -> CGFloat) { + final func animateTransitionOffset(_ from: CGPoint, beginAt: Double, duration: Double, curve: @escaping (CGFloat) -> CGFloat) { self.transitionOffset = from self.transitionOffsetAnimation = ListViewAnimation(from: from, to: CGPoint(), duration: duration, curve: curve, beginAt: beginAt, update: { [weak self] _, currentValue in if let strongSelf = self { diff --git a/Display/ListViewAnimation.swift b/Display/ListViewAnimation.swift index a0e032ed5f..91b91d9c0e 100644 --- a/Display/ListViewAnimation.swift +++ b/Display/ListViewAnimation.swift @@ -94,7 +94,7 @@ public final class ListViewAnimation { private let update: (CGFloat, Interpolatable) -> Void private let completed: (Bool) -> Void - public init(from: T, to: T, duration: Double, curve: (CGFloat) -> CGFloat, beginAt: Double, update: (CGFloat, T) -> Void, completed: (Bool) -> Void = { _ in }) { + public init(from: T, to: T, duration: Double, curve: @escaping (CGFloat) -> CGFloat, beginAt: Double, update: @escaping (CGFloat, T) -> Void, completed: @escaping (Bool) -> Void = { _ in }) { self.from = from self.to = to self.duration = duration diff --git a/Display/ListViewItem.swift b/Display/ListViewItem.swift index e37b3e66ea..6c22519549 100644 --- a/Display/ListViewItem.swift +++ b/Display/ListViewItem.swift @@ -7,8 +7,8 @@ public enum ListViewItemUpdateAnimation { } public protocol ListViewItem { - func nodeConfiguredForWidth(async: (() -> Void) -> Void, width: CGFloat, previousItem: ListViewItem?, nextItem: ListViewItem?, completion: (ListViewItemNode, () -> Void) -> Void) - func updateNode(async: (() -> Void) -> Void, node: ListViewItemNode, width: CGFloat, previousItem: ListViewItem?, nextItem: ListViewItem?, animation: ListViewItemUpdateAnimation, completion: (ListViewItemNodeLayout, () -> Void) -> Void) + func nodeConfiguredForWidth(async: @escaping (@escaping () -> Void) -> Void, width: CGFloat, previousItem: ListViewItem?, nextItem: ListViewItem?, completion: @escaping (ListViewItemNode, @escaping () -> Void) -> Void) + func updateNode(async: @escaping (@escaping () -> Void) -> Void, node: ListViewItemNode, width: CGFloat, previousItem: ListViewItem?, nextItem: ListViewItem?, animation: ListViewItemUpdateAnimation, completion: @escaping (ListViewItemNodeLayout, @escaping () -> Void) -> Void) var accessoryItem: ListViewAccessoryItem? { get } var headerAccessoryItem: ListViewAccessoryItem? { get } @@ -38,7 +38,7 @@ public extension ListViewItem { func selected() { } - func updateNode(async: (() -> Void) -> Void, node: ListViewItemNode, width: CGFloat, previousItem: ListViewItem?, nextItem: ListViewItem?, animation: ListViewItemUpdateAnimation, completion: (ListViewItemNodeLayout, () -> Void) -> Void) { + func updateNode(async: @escaping (@escaping () -> Void) -> Void, node: ListViewItemNode, width: CGFloat, previousItem: ListViewItem?, nextItem: ListViewItem?, animation: ListViewItemUpdateAnimation, completion: @escaping (ListViewItemNodeLayout, @escaping () -> Void) -> Void) { completion(ListViewItemNodeLayout(contentSize: node.contentSize, insets: node.insets), {}) } } diff --git a/Display/ListViewItemNode.swift b/Display/ListViewItemNode.swift index f9673188b3..c2dfd53fbc 100644 --- a/Display/ListViewItemNode.swift +++ b/Display/ListViewItemNode.swift @@ -51,7 +51,7 @@ public struct ListViewItemNodeLayout { } } -public class ListViewItemNode: ASDisplayNode { +open class ListViewItemNode: ASDisplayNode { final var index: Int? final var accessoryItemNode: ListViewAccessoryItemNode? { @@ -164,7 +164,7 @@ public class ListViewItemNode: ASDisplayNode { private var _bounds: CGRect = CGRect() private var _position: CGPoint = CGPoint() - public override var frame: CGRect { + open override var frame: CGRect { get { return CGRect(origin: CGPoint(x: self._position.x - self._bounds.width / 2.0, y: self._position.y - self._bounds.height / 2.0), size: self._bounds.size) } set(value) { @@ -187,7 +187,7 @@ public class ListViewItemNode: ASDisplayNode { } } - public override var bounds: CGRect { + open override var bounds: CGRect { get { return self._bounds } set(value) { @@ -209,7 +209,7 @@ public class ListViewItemNode: ASDisplayNode { } } - public override var position: CGPoint { + open override var position: CGPoint { get { return self._position } set(value) { @@ -230,13 +230,13 @@ public class ListViewItemNode: ASDisplayNode { return bounds } - public func layoutAccessoryItemNode(_ accessoryItemNode: ListViewAccessoryItemNode) { + open func layoutAccessoryItemNode(_ accessoryItemNode: ListViewAccessoryItemNode) { } - public func layoutHeaderAccessoryItemNode(_ accessoryItemNode: ListViewAccessoryItemNode) { + open func layoutHeaderAccessoryItemNode(_ accessoryItemNode: ListViewAccessoryItemNode) { } - public func reuse() { + open func reuse() { } final func addScrollingOffset(_ scrollingOffset: CGFloat) { @@ -316,7 +316,7 @@ public class ListViewItemNode: ASDisplayNode { return continueAnimations } - public func layoutForWidth(_ width: CGFloat, item: ListViewItem, previousItem: ListViewItem?, nextItem: ListViewItem?) { + open func layoutForWidth(_ width: CGFloat, item: ListViewItem, previousItem: ListViewItem?, nextItem: ListViewItem?) { } public func animationForKey(_ key: String) -> ListViewAnimation? { @@ -404,19 +404,19 @@ public class ListViewItemNode: ASDisplayNode { self.setAnimationForKey("transitionOffset", animation: animation) } - public func animateInsertion(_ currentTimestamp: Double, duration: Double) { + open func animateInsertion(_ currentTimestamp: Double, duration: Double) { } - public func animateAdded(_ currentTimestamp: Double, duration: Double) { + open func animateAdded(_ currentTimestamp: Double, duration: Double) { } - public func setHighlighted(_ highlighted: Bool, animated: Bool) { + open func setHighlighted(_ highlighted: Bool, animated: Bool) { } - public func setupGestures() { + open func setupGestures() { } - public func animateFrameTransition(_ progress: CGFloat) { + open func animateFrameTransition(_ progress: CGFloat) { } } diff --git a/Display/ListViewTransactionQueue.swift b/Display/ListViewTransactionQueue.swift index d63c5a7807..0316299fa7 100644 --- a/Display/ListViewTransactionQueue.swift +++ b/Display/ListViewTransactionQueue.swift @@ -1,7 +1,7 @@ import Foundation import SwiftSignalKit -public typealias ListViewTransaction = ((Void) -> Void) -> Void +public typealias ListViewTransaction = @escaping (@escaping (Void) -> Void) -> Void public final class ListViewTransactionQueue { private var transactions: [ListViewTransaction] = [] diff --git a/Display/NavigationBar.swift b/Display/NavigationBar.swift index ad5d920054..fa4dd9cc10 100644 --- a/Display/NavigationBar.swift +++ b/Display/NavigationBar.swift @@ -155,7 +155,7 @@ public class NavigationBar: ASDisplayNode { get { return self._previousItem } set(value) { - if let previousValue = self._previousItem, previousItemListenerKey = self.previousItemListenerKey { + if let previousValue = self._previousItem, let previousItemListenerKey = self.previousItemListenerKey { previousValue.removeSetTitleListener(previousItemListenerKey) self.previousItemListenerKey = nil } @@ -312,7 +312,7 @@ public class NavigationBar: ASDisplayNode { } self.leftButtonNode.pressed = { [weak self] in - if let item = self?.item, leftBarButtonItem = item.leftBarButtonItem { + if let item = self?.item, let leftBarButtonItem = item.leftBarButtonItem { leftBarButtonItem.performActionOnTarget() } } @@ -411,7 +411,7 @@ public class NavigationBar: ASDisplayNode { if self.titleNode.supernode != nil { let titleSize = self.titleNode.measure(CGSize(width: max(1.0, size.width - leftTitleInset - leftTitleInset), height: nominalHeight)) - if let transitionState = self.transitionState, otherNavigationBar = transitionState.navigationBar { + if let transitionState = self.transitionState, let otherNavigationBar = transitionState.navigationBar { let progress = transitionState.progress switch transitionState.role { diff --git a/Display/NavigationController.swift b/Display/NavigationController.swift index f7f46264d3..f1f3e777cb 100644 --- a/Display/NavigationController.swift +++ b/Display/NavigationController.swift @@ -9,7 +9,7 @@ private class NavigationControllerView: UIView { } } -public class NavigationController: NavigationControllerProxy, ContainableController, UIGestureRecognizerDelegate { +open class NavigationController: NavigationControllerProxy, ContainableController, UIGestureRecognizerDelegate { public private(set) weak var overlayPresentingController: ViewController? private var containerLayout = ContainerViewLayout() @@ -25,12 +25,12 @@ public class NavigationController: NavigationControllerProxy, ContainableControl //private var pendingLayout: (NavigationControllerLayout, Double, Bool)? private var _presentedViewController: UIViewController? - public override var presentedViewController: UIViewController? { + open override var presentedViewController: UIViewController? { return self._presentedViewController } private var _viewControllers: [UIViewController] = [] - public override var viewControllers: [UIViewController] { + open override var viewControllers: [UIViewController] { get { return self._viewControllers } set(value) { @@ -38,7 +38,7 @@ public class NavigationController: NavigationControllerProxy, ContainableControl } } - public override var topViewController: UIViewController? { + open override var topViewController: UIViewController? { return self._viewControllers.last } @@ -97,7 +97,7 @@ public class NavigationController: NavigationControllerProxy, ContainableControl } } - public override func loadView() { + open override func loadView() { self.view = NavigationControllerView() self.view.clipsToBounds = true @@ -218,7 +218,7 @@ public class NavigationController: NavigationControllerProxy, ContainableControl })) } - public override func pushViewController(_ viewController: UIViewController, animated: Bool) { + open override func pushViewController(_ viewController: UIViewController, animated: Bool) { self.currentPushDisposable.set(nil) var controllers = self.viewControllers @@ -226,7 +226,7 @@ public class NavigationController: NavigationControllerProxy, ContainableControl self.setViewControllers(controllers, animated: animated) } - public override func popViewController(animated: Bool) -> UIViewController? { + open override func popViewController(animated: Bool) -> UIViewController? { var controller: UIViewController? var controllers = self.viewControllers if controllers.count != 0 { @@ -237,7 +237,7 @@ public class NavigationController: NavigationControllerProxy, ContainableControl return controller } - public override func setViewControllers(_ viewControllers: [UIViewController], animated: Bool) { + open override func setViewControllers(_ viewControllers: [UIViewController], animated: Bool) { for controller in viewControllers { controller.navigation_setNavigationController(self) } @@ -323,7 +323,7 @@ public class NavigationController: NavigationControllerProxy, ContainableControl }) } } else { - if let topController = self.viewControllers.last where topController.isViewLoaded { + if let topController = self.viewControllers.last , topController.isViewLoaded { topController.navigation_setNavigationController(nil) topController.view.removeFromSuperview() } @@ -337,7 +337,7 @@ public class NavigationController: NavigationControllerProxy, ContainableControl } } - override public func present(_ viewControllerToPresent: UIViewController, animated flag: Bool, completion: (() -> Void)? = nil) { + override open func present(_ viewControllerToPresent: UIViewController, animated flag: Bool, completion: (() -> Void)? = nil) { if let controller = viewControllerToPresent as? NavigationController { controller.navigation_setDismiss { [weak self] in if let strongSelf = self { @@ -382,7 +382,7 @@ public class NavigationController: NavigationControllerProxy, ContainableControl } } - override public func dismiss(animated flag: Bool, completion: (() -> Void)? = nil) { + override open func dismiss(animated flag: Bool, completion: (() -> Void)? = nil) { if let controller = self.presentedViewController { if flag { UIView.animate(withDuration: 0.3, delay: 0.0, options: UIViewAnimationOptions(rawValue: 7 << 16), animations: { diff --git a/Display/NavigationTransitionCoordinator.swift b/Display/NavigationTransitionCoordinator.swift index 2e650df56e..9e38577d36 100644 --- a/Display/NavigationTransitionCoordinator.swift +++ b/Display/NavigationTransitionCoordinator.swift @@ -54,7 +54,7 @@ class NavigationTransitionCoordinator { self.dimView.backgroundColor = UIColor.black self.shadowView = UIImageView(image: shadowImage) - if let topNavigationBar = topNavigationBar, bottomNavigationBar = bottomNavigationBar { + if let topNavigationBar = topNavigationBar, let bottomNavigationBar = bottomNavigationBar { var topFrame = topNavigationBar.view.convert(topNavigationBar.bounds, to: container) var bottomFrame = bottomNavigationBar.view.convert(bottomNavigationBar.bounds, to: container) topFrame.origin.x = 0.0 @@ -92,7 +92,7 @@ class NavigationTransitionCoordinator { } var dimInset: CGFloat = 0.0 - if let topNavigationBar = self.topNavigationBar where self.inlineNavigationBarTransition { + if let topNavigationBar = self.topNavigationBar , self.inlineNavigationBarTransition { dimInset = topNavigationBar.frame.size.height } @@ -109,7 +109,7 @@ class NavigationTransitionCoordinator { } func updateNavigationBarTransition() { - if let topNavigationBar = self.topNavigationBar, bottomNavigationBar = self.bottomNavigationBar { + if let topNavigationBar = self.topNavigationBar, let bottomNavigationBar = self.bottomNavigationBar { let position: CGFloat switch self.transition { case .Push: @@ -124,7 +124,7 @@ class NavigationTransitionCoordinator { } func maybeCreateNavigationBarTransition() { - if let topNavigationBar = self.topNavigationBar, bottomNavigationBar = self.bottomNavigationBar { + if let topNavigationBar = self.topNavigationBar, let bottomNavigationBar = self.bottomNavigationBar { let position: CGFloat switch self.transition { case .Push: @@ -139,13 +139,13 @@ class NavigationTransitionCoordinator { } func endNavigationBarTransition() { - if let topNavigationBar = self.topNavigationBar, bottomNavigationBar = self.bottomNavigationBar { + if let topNavigationBar = self.topNavigationBar, let bottomNavigationBar = self.bottomNavigationBar { topNavigationBar.transitionState = nil bottomNavigationBar.transitionState = nil } } - func animateCancel(_ completion: () -> ()) { + func animateCancel(_ completion: @escaping () -> ()) { UIView.animate(withDuration: 0.1, delay: 0.0, options: UIViewAnimationOptions(), animations: { () -> Void in self.progress = 0.0 }) { (completed) -> Void in @@ -175,7 +175,7 @@ class NavigationTransitionCoordinator { } } - func animateCompletion(_ velocity: CGFloat, completion: () -> ()) { + func animateCompletion(_ velocity: CGFloat, completion: @escaping () -> ()) { let distance = (1.0 - self.progress) * self.container.bounds.size.width let f = { switch self.transition { diff --git a/Display/PresentationContext.swift b/Display/PresentationContext.swift index 589fba9030..aad06a904a 100644 --- a/Display/PresentationContext.swift +++ b/Display/PresentationContext.swift @@ -40,7 +40,7 @@ final class PresentationContext { |> deliverOnMainQueue |> timeout(2.0, queue: Queue.mainQueue(), alternate: .single(true)) - if let view = self.view, initialLayout = self.layout { + if let view = self.view, let initialLayout = self.layout { controller.view.frame = CGRect(origin: CGPoint(), size: initialLayout.size) controller.containerLayoutUpdated(initialLayout, transition: .immediate) @@ -51,9 +51,9 @@ final class PresentationContext { } strongSelf.controllers.append(controller) - if let view = strongSelf.view, layout = strongSelf.layout { + if let view = strongSelf.view, let layout = strongSelf.layout { controller.navigation_setDismiss { [weak strongSelf, weak controller] in - if let strongSelf = strongSelf, controller = controller { + if let strongSelf = strongSelf, let controller = controller { strongSelf.dismiss(controller) } } @@ -110,7 +110,7 @@ final class PresentationContext { } private func addViews() { - if let view = self.view, layout = self.layout { + if let view = self.view, let layout = self.layout { for controller in self.controllers { controller.viewWillAppear(false) view.addSubview(controller.view) diff --git a/Display/StatusBarManager.swift b/Display/StatusBarManager.swift index d085008c12..f8efdf92e1 100644 --- a/Display/StatusBarManager.swift +++ b/Display/StatusBarManager.swift @@ -27,7 +27,7 @@ private func optimizeMappedSurface(statusBarSize: CGSize, surface: MappedStatusB if surface.statusBars[i].style != surface.statusBars[i - 1].style || abs(surface.statusBars[i].frame.origin.y - surface.statusBars[i - 1].frame.origin.y) > CGFloat(FLT_EPSILON) { return surface } - if let lhsStatusBar = surface.statusBars[i - 1].statusBar, rhsStatusBar = surface.statusBars[i].statusBar where !lhsStatusBar.alpha.isEqual(to: rhsStatusBar.alpha) { + if let lhsStatusBar = surface.statusBars[i - 1].statusBar, let rhsStatusBar = surface.statusBars[i].statusBar , !lhsStatusBar.alpha.isEqual(to: rhsStatusBar.alpha) { return surface } } @@ -91,7 +91,7 @@ class StatusBarManager { outer: for surface in mappedSurfaces { for mappedStatusBar in surface.statusBars { if mappedStatusBar.frame.origin.equalTo(CGPoint()) { - if let statusBar = mappedStatusBar.statusBar where !statusBar.layer.hasPositionOrOpacityAnimations() { + if let statusBar = mappedStatusBar.statusBar , !statusBar.layer.hasPositionOrOpacityAnimations() { mappedSurfaces = [MappedStatusBarSurface(statusBars: [mappedStatusBar], surface: surface.surface)] break outer } diff --git a/Display/StatusBarProxyNode.swift b/Display/StatusBarProxyNode.swift index 2141f6c1df..b9c2ffc258 100644 --- a/Display/StatusBarProxyNode.swift +++ b/Display/StatusBarProxyNode.swift @@ -29,22 +29,22 @@ private class StatusBarItemNode: ASDisplayNode { func update() { let context = DrawingContext(size: self.targetView.frame.size, clear: true) - if let contents = self.targetView.layer.contents where (self.targetView.layer.sublayers?.count ?? 0) == 0 && CFGetTypeID(contents) == CGImage.typeID && false { + if let contents = self.targetView.layer.contents, (self.targetView.layer.sublayers?.count ?? 0) == 0 && CFGetTypeID(contents as! CFTypeRef) == CGImage.typeID && false { let image = contents as! CGImage context.withFlippedContext { c in c.setAlpha(CGFloat(self.targetView.layer.opacity)) - c.draw(in: CGRect(origin: CGPoint(), size: context.size), image: image) + c.draw(image, in: CGRect(origin: CGPoint(), size: context.size)) c.setAlpha(1.0) } if let sublayers = self.targetView.layer.sublayers { for sublayer in sublayers { let origin = sublayer.frame.origin - if let contents = sublayer.contents where CFGetTypeID(contents) == CGImage.typeID { + if let contents = sublayer.contents , CFGetTypeID(contents as! CFTypeRef) == CGImage.typeID { let image = contents as! CGImage context.withFlippedContext { c in c.translateBy(x: origin.x, y: origin.y) - c.draw(in: CGRect(origin: CGPoint(), size: context.size), image: image) + c.draw(image, in: CGRect(origin: CGPoint(), size: context.size)) c.translateBy(x: -origin.x, y: -origin.y) } } else { @@ -82,7 +82,7 @@ private func tintStatusBarItem(_ context: DrawingContext, type: StatusBarItemTyp let maxY = Int(context.size.height * context.scale) let maxX = Int(context.size.width * context.scale) if minY < maxY && minX < maxX { - let basePixel = UnsafeMutablePointer(context.bytes) + let basePixel = context.bytes.assumingMemoryBound(to: UInt32.self) let pixelsPerRow = context.bytesPerRow / 4 let midX = (maxX + minX) / 2 @@ -152,8 +152,8 @@ private func tintStatusBarItem(_ context: DrawingContext, type: StatusBarItemTyp let baseG = (baseColor >> 8) & 0xff let baseB = baseColor & 0xff - var pixel = UnsafeMutablePointer(context.bytes) - let end = UnsafeMutablePointer(context.bytes + context.length) + var pixel = context.bytes.assumingMemoryBound(to: UInt32.self) + let end = context.bytes.advanced(by: context.length).assumingMemoryBound(to: UInt32.self) while pixel != end { let alpha = (pixel.pointee & 0xff000000) >> 24 @@ -188,8 +188,8 @@ private func tintStatusBarItem(_ context: DrawingContext, type: StatusBarItemTyp } } case .Generic: - var pixel = UnsafeMutablePointer(context.bytes) - let end = UnsafeMutablePointer(context.bytes + context.length) + var pixel = context.bytes.assumingMemoryBound(to: UInt32.self) + let end = context.bytes.advanced(by: context.length).assumingMemoryBound(to: UInt32.self) let baseColor: UInt32 switch style { @@ -222,7 +222,7 @@ private let batteryItemClass: AnyClass? = NSClassFromString("UIStatusBarBatteryI private class StatusBarProxyNodeTimerTarget: NSObject { let action: () -> Void - init(action: () -> Void) { + init(action: @escaping () -> Void) { self.action = action } diff --git a/Display/SystemContainedControllerTransitionCoordinator.swift b/Display/SystemContainedControllerTransitionCoordinator.swift index 69c6025858..723d5e36b5 100644 --- a/Display/SystemContainedControllerTransitionCoordinator.swift +++ b/Display/SystemContainedControllerTransitionCoordinator.swift @@ -1,6 +1,6 @@ import UIKit -final class SystemContainedControllerTransitionCoordinator:NSObject, UIViewControllerTransitionCoordinator { +final class SystemContainedControllerTransitionCoordinator: NSObject, UIViewControllerTransitionCoordinator { public var isAnimated: Bool { return false } @@ -39,11 +39,11 @@ final class SystemContainedControllerTransitionCoordinator:NSObject, UIViewContr return .easeInOut } - public func viewController(forKey key: String) -> UIViewController? { + public func viewController(forKey key: UITransitionContextViewControllerKey) -> UIViewController? { return nil } - public func view(forKey key: String) -> UIView? { + public func view(forKey key: UITransitionContextViewKey) -> UIView? { return nil } @@ -55,19 +55,19 @@ final class SystemContainedControllerTransitionCoordinator:NSObject, UIViewContr return CGAffineTransform.identity } - public func animate(alongsideTransition animation: ((UIViewControllerTransitionCoordinatorContext) -> Swift.Void)?, completion: ((UIViewControllerTransitionCoordinatorContext) -> Swift.Void)? = nil) -> Bool { + public func animate(alongsideTransition animation: ((UIViewControllerTransitionCoordinatorContext) -> Swift.Void)?, completion: (@escaping (UIViewControllerTransitionCoordinatorContext) -> Swift.Void)? = nil) -> Bool { return false } - public func animateAlongsideTransition(in view: UIView?, animation: ((UIViewControllerTransitionCoordinatorContext) -> Swift.Void)?, completion: ((UIViewControllerTransitionCoordinatorContext) -> Swift.Void)? = nil) -> Bool { + public func animateAlongsideTransition(in view: UIView?, animation: ((UIViewControllerTransitionCoordinatorContext) -> Swift.Void)?, completion: (@escaping (UIViewControllerTransitionCoordinatorContext) -> Swift.Void)? = nil) -> Bool { return false } - public func notifyWhenInteractionEnds(_ handler: (UIViewControllerTransitionCoordinatorContext) -> ()) { + public func notifyWhenInteractionEnds(_ handler: @escaping (UIViewControllerTransitionCoordinatorContext) -> ()) { } - public func notifyWhenInteractionChanges(_ handler: (UIViewControllerTransitionCoordinatorContext) -> ()) { + public func notifyWhenInteractionChanges(_ handler: @escaping (UIViewControllerTransitionCoordinatorContext) -> ()) { } } diff --git a/Display/TabBarContollerNode.swift b/Display/TabBarContollerNode.swift index 7ef4acd2af..7c8ff8792a 100644 --- a/Display/TabBarContollerNode.swift +++ b/Display/TabBarContollerNode.swift @@ -14,7 +14,7 @@ final class TabBarControllerNode: ASDisplayNode { } } - init(itemSelected: (Int) -> Void) { + init(itemSelected: @escaping (Int) -> Void) { self.tabBarNode = TabBarNode(itemSelected: itemSelected) super.init(viewBlock: { diff --git a/Display/TabBarNode.swift b/Display/TabBarNode.swift index 387d91eaa5..a9d51ee2f9 100644 --- a/Display/TabBarNode.swift +++ b/Display/TabBarNode.swift @@ -68,7 +68,7 @@ class TabBarNode: ASDisplayNode { let separatorNode: ASDisplayNode private var tabBarNodes: [ASImageNode] = [] - init(itemSelected: (Int) -> Void) { + init(itemSelected: @escaping (Int) -> Void) { self.itemSelected = itemSelected self.separatorNode = ASDisplayNode() @@ -96,7 +96,7 @@ class TabBarNode: ASDisplayNode { node.displaysAsynchronously = false node.displayWithoutProcessing = true node.isLayerBacked = true - if let selectedIndex = self.selectedIndex where selectedIndex == i { + if let selectedIndex = self.selectedIndex , selectedIndex == i { node.image = tabBarItemImage(item.selectedImage, title: item.title ?? "", tintColor: UIColor(0x1195f2)) } else { node.image = tabBarItemImage(item.image, title: item.title ?? "", tintColor: UIColor(0x929292)) @@ -115,7 +115,7 @@ class TabBarNode: ASDisplayNode { let node = self.tabBarNodes[index] let item = self.tabBarItems[index] - if let selectedIndex = self.selectedIndex where selectedIndex == index { + if let selectedIndex = self.selectedIndex , selectedIndex == index { node.image = tabBarItemImage(item.selectedImage, title: item.title ?? "", tintColor: UIColor(0x1195f2)) } else { node.image = tabBarItemImage(item.image, title: item.title ?? "", tintColor: UIColor(0x929292)) diff --git a/Display/UniversalTapRecognizer.swift b/Display/UniversalTapRecognizer.swift index 47477fff9d..a98268147b 100644 --- a/Display/UniversalTapRecognizer.swift +++ b/Display/UniversalTapRecognizer.swift @@ -4,7 +4,7 @@ import UIKit.UIGestureRecognizerSubclass private class TimerTargetWrapper: NSObject { let f: () -> Void - init(_ f: () -> Void) { + init(_ f: @escaping () -> Void) { self.f = f } diff --git a/Display/ViewController.swift b/Display/ViewController.swift index 4564136d5f..aaa22f1f77 100644 --- a/Display/ViewController.swift +++ b/Display/ViewController.swift @@ -3,7 +3,20 @@ import UIKit import AsyncDisplayKit import SwiftSignalKit -@objc public class ViewController: UIViewController, ContainableController { +private func findCurrentResponder(_ view: UIView) -> UIResponder? { + if view.isFirstResponder { + return view + } else { + for subview in view.subviews { + if let result = findCurrentResponder(subview) { + return result + } + } + return nil + } +} + +@objc open class ViewController: UIViewController, ContainableController { private var containerLayout = ContainerViewLayout() private let presentationContext: PresentationContext @@ -37,8 +50,11 @@ import SwiftSignalKit public var displayNavigationBar = true + private weak var activeInputViewCandidate: UIResponder? + private weak var activeInputView: UIResponder? + private let _ready = Promise(true) - public var ready: Promise { + open var ready: Promise { return self._ready } @@ -53,7 +69,7 @@ import SwiftSignalKit private func updateScrollToTopView() { if self.scrollToTop != nil { - if let displayNode = self._displayNode where self.scrollToTopView == nil { + if let displayNode = self._displayNode , self.scrollToTopView == nil { let scrollToTopView = ScrollToTopView(frame: CGRect(x: 0.0, y: -1.0, width: displayNode.frame.size.width, height: 1.0)) scrollToTopView.action = { [weak self] in if let scrollToTop = self?.scrollToTop { @@ -91,7 +107,7 @@ import SwiftSignalKit } - public func containerLayoutUpdated(_ layout: ContainerViewLayout, transition: ContainedViewLayoutTransition) { + open func containerLayoutUpdated(_ layout: ContainerViewLayout, transition: ContainedViewLayoutTransition) { self.containerLayout = layout if !self.isViewLoaded { @@ -122,19 +138,19 @@ import SwiftSignalKit } } - public override func loadView() { + open override func loadView() { self.view = self.displayNode.view self.displayNode.addSubnode(self.navigationBar) self.view.addSubview(self.statusBar.view) self.presentationContext.view = self.view } - public func loadDisplayNode() { + open func loadDisplayNode() { self.displayNode = ASDisplayNode() self.displayNodeDidLoad() } - public func displayNodeDidLoad() { + open func displayNodeDidLoad() { self.updateScrollToTopView() } @@ -158,11 +174,11 @@ import SwiftSignalKit } } - override public func present(_ viewControllerToPresent: UIViewController, animated flag: Bool, completion: (() -> Void)? = nil) { + override open func present(_ viewControllerToPresent: UIViewController, animated flag: Bool, completion: (() -> Void)? = nil) { preconditionFailure("use present(_:in)") } - override public func dismiss(animated flag: Bool, completion: (() -> Void)? = nil) { + override open func dismiss(animated flag: Bool, completion: (() -> Void)? = nil) { if let navigationController = self.navigationController as? NavigationController { navigationController.dismiss(animated: flag, completion: completion) } else { @@ -192,4 +208,22 @@ import SwiftSignalKit self.window?.present(controller) } } + + open override func viewWillDisappear(_ animated: Bool) { + self.activeInputViewCandidate = findCurrentResponder(self.view) + + super.viewWillDisappear(animated) + } + + open override func viewDidDisappear(_ animated: Bool) { + self.activeInputView = self.activeInputViewCandidate + + super.viewDidDisappear(animated) + } + + open override func viewDidAppear(_ animated: Bool) { + self.activeInputView = nil + + super.viewDidAppear(animated) + } } diff --git a/Display/Window.swift b/Display/Window.swift index 2b724f13dd..bfe5fc62ea 100644 --- a/Display/Window.swift +++ b/Display/Window.swift @@ -305,7 +305,7 @@ public class Window: UIWindow { } } - public func addPostUpdateToInterfaceOrientationBlock(f: (Void) -> Void) { + public func addPostUpdateToInterfaceOrientationBlock(f: @escaping (Void) -> Void) { postUpdateToInterfaceOrientationBlocks.append(f) }