no message

This commit is contained in:
Peter 2018-06-29 20:14:18 +03:00
parent 3dfd2af198
commit f3ec180e4d
14 changed files with 127 additions and 88 deletions

View File

@ -1404,7 +1404,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 9.0; IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = YES; MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES; ONLY_ACTIVE_ARCH = YES;
OTHER_CFLAGS = "-DMINIMAL_ASDK"; OTHER_CFLAGS = "-DMINIMAL_ASDK=1";
SDKROOT = iphoneos; SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_OPTIMIZATION_LEVEL = "-Onone";
TARGETED_DEVICE_FAMILY = "1,2"; TARGETED_DEVICE_FAMILY = "1,2";
@ -1446,7 +1446,7 @@
GCC_WARN_UNUSED_VARIABLE = YES; GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0; IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = NO; MTL_ENABLE_DEBUG_INFO = NO;
OTHER_CFLAGS = "-DMINIMAL_ASDK"; OTHER_CFLAGS = "-DMINIMAL_ASDK=1";
SDKROOT = iphoneos; SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2"; TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES; VALIDATE_PRODUCT = YES;
@ -1572,7 +1572,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 9.0; IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = YES; MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES; ONLY_ACTIVE_ARCH = YES;
OTHER_CFLAGS = "-DMINIMAL_ASDK"; OTHER_CFLAGS = "-DMINIMAL_ASDK=1";
SDKROOT = iphoneos; SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_OPTIMIZATION_LEVEL = "-Onone";
TARGETED_DEVICE_FAMILY = "1,2"; TARGETED_DEVICE_FAMILY = "1,2";
@ -1652,7 +1652,7 @@
GCC_WARN_UNUSED_VARIABLE = YES; GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0; IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = NO; MTL_ENABLE_DEBUG_INFO = NO;
OTHER_CFLAGS = "-DMINIMAL_ASDK"; OTHER_CFLAGS = "-DMINIMAL_ASDK=1";
SDKROOT = iphoneos; SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2"; TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES; VALIDATE_PRODUCT = YES;
@ -1732,7 +1732,7 @@
GCC_WARN_UNUSED_VARIABLE = YES; GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0; IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = NO; MTL_ENABLE_DEBUG_INFO = NO;
OTHER_CFLAGS = "-DMINIMAL_ASDK"; OTHER_CFLAGS = "-DMINIMAL_ASDK=1";
SDKROOT = iphoneos; SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2"; TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES; VALIDATE_PRODUCT = YES;

View File

@ -12,7 +12,7 @@
<key>DisplayMac.xcscheme</key> <key>DisplayMac.xcscheme</key>
<dict> <dict>
<key>orderHint</key> <key>orderHint</key>
<integer>25</integer> <integer>24</integer>
</dict> </dict>
<key>DisplayTests.xcscheme</key> <key>DisplayTests.xcscheme</key>
<dict> <dict>

View File

@ -38,8 +38,8 @@ public class ActionSheetCheckboxItemNode: ActionSheetItemNode {
private var item: ActionSheetCheckboxItem? private var item: ActionSheetCheckboxItem?
private let button: HighlightTrackingButton private let button: HighlightTrackingButton
private let titleNode: ASTextNode private let titleNode: ImmediateTextNode
private let labelNode: ASTextNode private let labelNode: ImmediateTextNode
private let checkNode: ASImageNode private let checkNode: ASImageNode
override public init(theme: ActionSheetControllerTheme) { override public init(theme: ActionSheetControllerTheme) {
@ -47,14 +47,13 @@ public class ActionSheetCheckboxItemNode: ActionSheetItemNode {
self.button = HighlightTrackingButton() self.button = HighlightTrackingButton()
self.titleNode = ASTextNode() self.titleNode = ImmediateTextNode()
self.titleNode.maximumNumberOfLines = 1 self.titleNode.maximumNumberOfLines = 1
self.titleNode.isUserInteractionEnabled = false self.titleNode.isUserInteractionEnabled = false
self.titleNode.displaysAsynchronously = false self.titleNode.displaysAsynchronously = false
self.labelNode = ASTextNode() self.labelNode = ImmediateTextNode()
self.labelNode.maximumNumberOfLines = 1 self.labelNode.maximumNumberOfLines = 1
self.labelNode.truncationMode = .byTruncatingTail
self.labelNode.isUserInteractionEnabled = false self.labelNode.isUserInteractionEnabled = false
self.labelNode.displaysAsynchronously = false self.labelNode.displaysAsynchronously = false
@ -115,8 +114,8 @@ public class ActionSheetCheckboxItemNode: ActionSheetItemNode {
self.button.frame = CGRect(origin: CGPoint(), size: size) self.button.frame = CGRect(origin: CGPoint(), size: size)
let labelSize = self.labelNode.measure(CGSize(width: size.width - 44.0 - 15.0 - 8.0, height: size.height)) let labelSize = self.labelNode.updateLayout(CGSize(width: size.width - 44.0 - 15.0 - 8.0, height: size.height))
let titleSize = self.titleNode.measure(CGSize(width: size.width - 44.0 - labelSize.width - 15.0 - 8.0, height: size.height)) let titleSize = self.titleNode.updateLayout(CGSize(width: size.width - 44.0 - labelSize.width - 15.0 - 8.0, height: size.height))
self.titleNode.frame = CGRect(origin: CGPoint(x: 44.0, y: floorToScreenPixels((size.height - titleSize.height) / 2.0)), size: titleSize) self.titleNode.frame = CGRect(origin: CGPoint(x: 44.0, y: floorToScreenPixels((size.height - titleSize.height) / 2.0)), size: titleSize)
self.labelNode.frame = CGRect(origin: CGPoint(x: size.width - 15.0 - labelSize.width, y: floorToScreenPixels((size.height - labelSize.height) / 2.0)), size: labelSize) self.labelNode.frame = CGRect(origin: CGPoint(x: size.width - 15.0 - labelSize.width, y: floorToScreenPixels((size.height - labelSize.height) / 2.0)), size: labelSize)

View File

@ -588,7 +588,7 @@ open class GridNode: GridNodeScroller, UIScrollViewDelegate {
} }
if scrollToItem.adjustForTopInset { if scrollToItem.adjustForTopInset {
additionalOffset += -gridLayout.insets.top + self.initialOffset additionalOffset += -gridLayout.insets.top// + self.initialOffset
} }
} else if scrollToItem.adjustForTopInset { } else if scrollToItem.adjustForTopInset {
additionalOffset = -gridLayout.insets.top additionalOffset = -gridLayout.insets.top
@ -712,7 +712,7 @@ open class GridNode: GridNodeScroller, UIScrollViewDelegate {
var lowestHeaderNode: ASDisplayNode? var lowestHeaderNode: ASDisplayNode?
var lowestHeaderNodeIndex: Int? var lowestHeaderNodeIndex: Int?
for (_, headerNode) in self.sectionNodes { for (_, headerNode) in self.sectionNodes {
if let index = self.subnodes.index(of: headerNode) { if let index = self.subnodes?.index(of: headerNode) {
if lowestHeaderNodeIndex == nil || index < lowestHeaderNodeIndex! { if lowestHeaderNodeIndex == nil || index < lowestHeaderNodeIndex! {
lowestHeaderNodeIndex = index lowestHeaderNodeIndex = index
lowestHeaderNode = headerNode lowestHeaderNode = headerNode
@ -1039,7 +1039,7 @@ open class GridNode: GridNodeScroller, UIScrollViewDelegate {
var topVisible: (Int, GridItem) = (topIndex, self.items[topIndex]) var topVisible: (Int, GridItem) = (topIndex, self.items[topIndex])
let bottomVisible: (Int, GridItem) = (bottomIndex, self.items[bottomIndex]) let bottomVisible: (Int, GridItem) = (bottomIndex, self.items[bottomIndex])
let lowerDisplayBound = presentationLayoutTransition.layout.contentOffset.y let lowerDisplayBound = presentationLayoutTransition.layout.contentOffset.y + presentationLayoutTransition.layout.layout.insets.top
//let upperDisplayBound = presentationLayoutTransition.layout.contentOffset.y + self.gridLayout.size.height //let upperDisplayBound = presentationLayoutTransition.layout.contentOffset.y + self.gridLayout.size.height
for item in presentationLayoutTransition.layout.items { for item in presentationLayoutTransition.layout.items {

View File

@ -61,7 +61,7 @@ final class ListViewBackingView: UIView {
} }
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? { override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
if let target = target, target.limitHitTestToNodes { if let target = self.target, target.limitHitTestToNodes {
if !target.internalHitTest(point, with: event) { if !target.internalHitTest(point, with: event) {
return nil return nil
} }
@ -1695,7 +1695,7 @@ open class ListView: ASDisplayNode, UIScrollViewDelegate, UIGestureRecognizerDel
if let _ = previousFrame, 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] let nextNode = self.itemNodes[nodeIndex + 1]
if nextNode.index == nil && nextNode.subnodes.isEmpty { if nextNode.index == nil && nextNode.subnodes == nil || nextNode.subnodes!.isEmpty {
let nextHeight = nextNode.apparentHeight let nextHeight = nextNode.apparentHeight
if abs(nextHeight - previousApparentHeight) < CGFloat.ulpOfOne { if abs(nextHeight - previousApparentHeight) < CGFloat.ulpOfOne {
if let animation = nextNode.animationForKey("apparentHeight") { if let animation = nextNode.animationForKey("apparentHeight") {
@ -1836,7 +1836,7 @@ open class ListView: ASDisplayNode, UIScrollViewDelegate, UIGestureRecognizerDel
var lowestHeaderNode: ASDisplayNode? var lowestHeaderNode: ASDisplayNode?
var lowestHeaderNodeIndex: Int? var lowestHeaderNodeIndex: Int?
for (_, headerNode) in self.itemHeaderNodes { for (_, headerNode) in self.itemHeaderNodes {
if let index = self.subnodes.index(of: headerNode) { if let index = self.subnodes?.index(of: headerNode) {
if lowestHeaderNodeIndex == nil || index < lowestHeaderNodeIndex! { if lowestHeaderNodeIndex == nil || index < lowestHeaderNodeIndex! {
lowestHeaderNodeIndex = index lowestHeaderNodeIndex = index
lowestHeaderNode = headerNode lowestHeaderNode = headerNode

View File

@ -52,13 +52,7 @@ final class NavigationBarBadgeNode: ASDisplayNode {
let backgroundSize = CGSize(width: max(18.0, badgeSize.width + 10.0 + 1.0), height: 18.0) let backgroundSize = CGSize(width: max(18.0, badgeSize.width + 10.0 + 1.0), height: 18.0)
let backgroundFrame = CGRect(origin: CGPoint(), size: backgroundSize) let backgroundFrame = CGRect(origin: CGPoint(), size: backgroundSize)
self.backgroundNode.frame = backgroundFrame self.backgroundNode.frame = backgroundFrame
let textOffset: CGFloat self.textNode.frame = CGRect(origin: CGPoint(x: floorToScreenPixels(backgroundFrame.midX - badgeSize.width / 2.0), y: floorToScreenPixels((backgroundFrame.size.height - badgeSize.height) / 2.0)), size: badgeSize)
if UIScreenPixel.isLessThanOrEqualTo(1.0 / 3.0) {
textOffset = UIScreenPixel * 2.0
} else {
textOffset = UIScreenPixel
}
self.textNode.frame = CGRect(origin: CGPoint(x: floorToScreenPixels(backgroundFrame.midX - badgeSize.width / 2.0), y: floorToScreenPixels((backgroundFrame.size.height - badgeSize.height) / 2.0) + textOffset), size: badgeSize)
return backgroundSize return backgroundSize
} }

View File

@ -120,14 +120,16 @@ private final class NavigationButtonItemNode: ASTextNode {
self.displaysAsynchronously = false self.displaysAsynchronously = false
} }
override public func calculateSizeThatFits(_ constrainedSize: CGSize) -> CGSize { func updateLayout(_ constrainedSize: CGSize) -> CGSize {
let superSize = super.calculateSizeThatFits(constrainedSize) let superSize = super.calculateSizeThatFits(constrainedSize)
if let node = self.node { if let node = self.node {
let nodeSize = node.measure(constrainedSize) let nodeSize = node.measure(constrainedSize)
return CGSize(width: max(nodeSize.width, superSize.width), height: max(nodeSize.height, superSize.height)) let size = CGSize(width: max(nodeSize.width, superSize.width), height: max(nodeSize.height, superSize.height))
node.frame = CGRect(origin: CGPoint(), size: nodeSize)
return size
} else if let imageNode = self.imageNode { } else if let imageNode = self.imageNode {
let nodeSize = imageNode.measure(constrainedSize) let nodeSize = imageNode.image?.size ?? CGSize()
let size = CGSize(width: max(nodeSize.width, superSize.width), height: max(nodeSize.height, superSize.height)) let size = CGSize(width: max(nodeSize.width, superSize.width), height: max(nodeSize.height, superSize.height))
imageNode.frame = CGRect(origin: CGPoint(x: floorToScreenPixels((size.width - nodeSize.width) / 2.0) + 5.0, y: floorToScreenPixels((size.height - nodeSize.height) / 2.0)), size: nodeSize) imageNode.frame = CGRect(origin: CGPoint(x: floorToScreenPixels((size.width - nodeSize.width) / 2.0) + 5.0, y: floorToScreenPixels((size.height - nodeSize.height) / 2.0)), size: nodeSize)
return size return size
@ -135,14 +137,6 @@ private final class NavigationButtonItemNode: ASTextNode {
return superSize return superSize
} }
override public func layout() {
super.layout()
if let node = self.node {
node.frame = CGRect(origin: CGPoint(), size: node.calculatedSize)
}
}
private func touchInsideApparentBounds(_ touch: UITouch) -> Bool { private func touchInsideApparentBounds(_ touch: UITouch) -> Bool {
var apparentBounds = self.bounds var apparentBounds = self.bounds
let hitTestSlop = self.hitTestSlop let hitTestSlop = self.hitTestSlop
@ -330,7 +324,7 @@ final class NavigationButtonNode: ASDisplayNode {
totalSize.width += 16.0 totalSize.width += 16.0
nodeOrigin.x += 16.0 nodeOrigin.x += 16.0
} }
var nodeSize = node.calculateSizeThatFits(constrainedSize) var nodeSize = node.updateLayout(constrainedSize)
nodeSize.width = ceil(nodeSize.width) nodeSize.width = ceil(nodeSize.width)
nodeSize.height = ceil(nodeSize.height) nodeSize.height = ceil(nodeSize.height)
totalSize.width += nodeSize.width totalSize.width += nodeSize.width

View File

@ -127,9 +127,13 @@ public final class PeekControllerGestureRecognizer: UIPanGestureRecognizer {
override public func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent) { override public func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent) {
super.touchesEnded(touches, with: event) super.touchesEnded(touches, with: event)
if self.activateBySingleTap, self.candidateContent != nil, self.presentedController == nil { if self.activateBySingleTap, self.presentedController == nil {
self.longTapTimerFired() self.longTapTimer?.invalidate()
self.pressTimerFired() self.pressTimer?.invalidate()
if let tapLocation = self.tapLocation {
self.checkCandidateContent(at: tapLocation, forceActivate: true)
}
self.state = .ended
} else { } else {
let velocity = self.velocity(in: self.view) let velocity = self.velocity(in: self.view)
@ -184,7 +188,10 @@ public final class PeekControllerGestureRecognizer: UIPanGestureRecognizer {
(presentedController.displayNode as? PeekControllerNode)?.activateMenu() (presentedController.displayNode as? PeekControllerNode)?.activateMenu()
self.menuActivation = nil self.menuActivation = nil
self.presentedController = nil self.presentedController = nil
self.candidateContent = nil
self.state = .ended self.state = .ended
self.candidateContentDisposable.set(nil)
return
} }
} }
} }
@ -216,30 +223,50 @@ public final class PeekControllerGestureRecognizer: UIPanGestureRecognizer {
} }
} }
private func checkCandidateContent(at touchLocation: CGPoint) { private func checkCandidateContent(at touchLocation: CGPoint, forceActivate: Bool = false) {
//print("check begin")
if let contentSignal = self.contentAtPoint(touchLocation) { if let contentSignal = self.contentAtPoint(touchLocation) {
self.candidateContentDisposable.set((contentSignal |> deliverOnMainQueue).start(next: { [weak self] result in self.candidateContentDisposable.set((contentSignal
|> deliverOnMainQueue).start(next: { [weak self] result in
if let strongSelf = self { if let strongSelf = self {
switch strongSelf.state { let processResult: Bool
case .possible, .changed: if forceActivate {
if let (sourceNode, content) = result { processResult = true
if let currentContent = strongSelf.candidateContent { } else {
if !currentContent.1.isEqual(to: content) { switch strongSelf.state {
strongSelf.tapLocation = touchLocation case .possible, .changed:
strongSelf.candidateContent = (sourceNode, content) processResult = true
strongSelf.menuActivation = content.menuActivation() default:
if let presentedController = strongSelf.presentedController, presentedController.isNodeLoaded { processResult = false
presentedController.sourceNode = { }
return sourceNode }
} //print("check received, will process: \(processResult), force: \(forceActivate), state: \(strongSelf.state)")
(presentedController.displayNode as? PeekControllerNode)?.updateContent(content: content) if processResult {
if let (sourceNode, content) = result {
if let currentContent = strongSelf.candidateContent {
if !currentContent.1.isEqual(to: content) {
strongSelf.tapLocation = touchLocation
strongSelf.candidateContent = (sourceNode, content)
strongSelf.menuActivation = content.menuActivation()
if let presentedController = strongSelf.presentedController, presentedController.isNodeLoaded {
presentedController.sourceNode = {
return sourceNode
} }
(presentedController.displayNode as? PeekControllerNode)?.updateContent(content: content)
} }
} else { }
if let presentedController = strongSelf.present(content, sourceNode) { } else {
if let presentedController = strongSelf.present(content, sourceNode) {
if forceActivate {
strongSelf.candidateContent = nil
if case .press = content.menuActivation() {
(presentedController.displayNode as? PeekControllerNode)?.activateMenu()
}
} else {
strongSelf.candidateContent = (sourceNode, content) strongSelf.candidateContent = (sourceNode, content)
strongSelf.menuActivation = content.menuActivation() strongSelf.menuActivation = content.menuActivation()
strongSelf.presentedController = presentedController strongSelf.presentedController = presentedController
strongSelf.state = .began strongSelf.state = .began
switch content.menuActivation() { switch content.menuActivation() {
@ -256,11 +283,12 @@ public final class PeekControllerGestureRecognizer: UIPanGestureRecognizer {
} }
} }
} }
} else if strongSelf.presentedController == nil { }
} else if strongSelf.presentedController == nil {
if strongSelf.state != .possible && strongSelf.state != .ended {
strongSelf.state = .failed strongSelf.state = .failed
} }
default: }
break
} }
} }
})) }))

View File

@ -34,7 +34,7 @@ open class TabBarController: ViewController {
} }
} }
private var controllers: [ViewController] = [] public private(set) var controllers: [ViewController] = []
private var _selectedIndex: Int? private var _selectedIndex: Int?
public var selectedIndex: Int { public var selectedIndex: Int {
@ -50,10 +50,6 @@ open class TabBarController: ViewController {
_selectedIndex = index _selectedIndex = index
self.updateSelectedIndex() self.updateSelectedIndex()
} else {
if let controller = self.currentController {
controller.scrollToTopWithTabBar?()
}
} }
} }
} }
@ -116,7 +112,13 @@ open class TabBarController: ViewController {
} }
strongSelf.pendingControllerDisposable.set((strongSelf.controllers[index].ready.get() |> deliverOnMainQueue).start(next: { _ in strongSelf.pendingControllerDisposable.set((strongSelf.controllers[index].ready.get() |> deliverOnMainQueue).start(next: { _ in
if let strongSelf = self { if let strongSelf = self {
strongSelf.selectedIndex = index if strongSelf.selectedIndex == index {
if let controller = strongSelf.currentController {
controller.scrollToTopWithTabBar?()
}
} else {
strongSelf.selectedIndex = index
}
} }
})) }))
} }

View File

@ -35,7 +35,7 @@ private final class TextAlertContentActionNode: HighlightableButtonNode {
super.init() super.init()
self.titleNode.maximumNumberOfLines = 2 self.titleNode.maximumNumberOfLines = 2
let font = Font.regular(17.0) var font = Font.regular(17.0)
var color = theme.accentColor var color = theme.accentColor
switch action.type { switch action.type {
case .defaultAction, .genericAction: case .defaultAction, .genericAction:
@ -43,6 +43,12 @@ private final class TextAlertContentActionNode: HighlightableButtonNode {
case .destructiveAction: case .destructiveAction:
color = theme.destructiveColor color = theme.destructiveColor
} }
switch action.type {
case .defaultAction:
font = Font.semibold(17.0)
case .destructiveAction, .genericAction:
break
}
self.setAttributedTitle(NSAttributedString(string: action.title, font: font, textColor: color, paragraphAlignment: .center), for: []) self.setAttributedTitle(NSAttributedString(string: action.title, font: font, textColor: color, paragraphAlignment: .center), for: [])
self.highligthedChanged = { [weak self] value in self.highligthedChanged = { [weak self] value in

View File

@ -479,6 +479,9 @@ public class TextNode: ASDisplayNode {
return (layout, { return (layout, {
node.cachedLayout = layout node.cachedLayout = layout
if updated { if updated {
if layout.size.width.isZero && layout.size.height.isZero {
node.contents = nil
}
node.setNeedsDisplay() node.setNeedsDisplay()
} }

View File

@ -15,6 +15,7 @@ final class VolumeControlStatusBar: UIView {
var valueChanged: ((Float, Float) -> Void)? var valueChanged: ((Float, Float) -> Void)?
private var disposable: Disposable? private var disposable: Disposable?
private var ignoreAdjustmentOnce = false
init(frame: CGRect, shouldBeVisible: Signal<Bool, NoError>) { init(frame: CGRect, shouldBeVisible: Signal<Bool, NoError>) {
self.control = MPVolumeView(frame: CGRect(origin: CGPoint(), size: CGSize(width: 100.0, height: 20.0))) self.control = MPVolumeView(frame: CGRect(origin: CGPoint(), size: CGSize(width: 100.0, height: 20.0)))
@ -24,12 +25,22 @@ final class VolumeControlStatusBar: UIView {
self.addSubview(self.control) self.addSubview(self.control)
self.observer = NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: volumeNotificationKey), object: nil, queue: OperationQueue.main, using: { [weak self] notification in self.observer = NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: volumeNotificationKey), object: nil, queue: OperationQueue.main, using: { [weak self] notification in
if let strongSelf = self { if let strongSelf = self, let userInfo = notification.userInfo {
if let volume = notification.userInfo?[volumeParameterKey] as? Float { /*guard let category = userInfo["AVSystemController_AudioCategoryNotificationParameter"] as? String else {
return
}*/
if let volume = userInfo[volumeParameterKey] as? Float {
let previous = strongSelf.currentValue let previous = strongSelf.currentValue
strongSelf.currentValue = volume if !previous.isEqual(to: volume) {
if strongSelf.control.superview != nil { strongSelf.currentValue = volume
strongSelf.valueChanged?(previous, volume) if strongSelf.ignoreAdjustmentOnce {
strongSelf.ignoreAdjustmentOnce = false
} else {
if strongSelf.control.superview != nil {
strongSelf.valueChanged?(previous, volume)
}
}
} }
} }
} }
@ -42,10 +53,12 @@ final class VolumeControlStatusBar: UIView {
} }
if value { if value {
if strongSelf.control.superview == nil { if strongSelf.control.superview == nil {
strongSelf.ignoreAdjustmentOnce = true
strongSelf.addSubview(strongSelf.control) strongSelf.addSubview(strongSelf.control)
} }
} else { } else {
strongSelf.control.removeFromSuperview() strongSelf.control.removeFromSuperview()
strongSelf.ignoreAdjustmentOnce = false
} }
}) })
} }

View File

@ -154,7 +154,7 @@ private func encodeText(_ string: String, _ key: Int) -> String {
return result return result
} }
private func doesViewTreeDisableInteractiveTransitionGestureRecognizer(_ view: UIView) -> Bool { public func doesViewTreeDisableInteractiveTransitionGestureRecognizer(_ view: UIView) -> Bool {
if view.disablesInteractiveTransitionGestureRecognizer { if view.disablesInteractiveTransitionGestureRecognizer {
return true return true
} }
@ -204,7 +204,7 @@ private func applyThemeToPreviewingEffectView(_ view: UIView) {
} }
} }
private func getFirstResponderAndAccessoryHeight(_ view: UIView, _ accessoryHeight: CGFloat? = nil) -> (UIView?, CGFloat?) { public func getFirstResponderAndAccessoryHeight(_ view: UIView, _ accessoryHeight: CGFloat? = nil) -> (UIView?, CGFloat?) {
if view.isFirstResponder { if view.isFirstResponder {
return (view, accessoryHeight) return (view, accessoryHeight)
} else { } else {
@ -283,12 +283,12 @@ private func safeInsetsForScreenSize(_ size: CGSize) -> UIEdgeInsets {
return UIEdgeInsets() return UIEdgeInsets()
} }
private final class KeyboardGestureRecognizerDelegate: NSObject, UIGestureRecognizerDelegate { public final class WindowKeyboardGestureRecognizerDelegate: NSObject, UIGestureRecognizerDelegate {
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool { public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
return true return true
} }
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRequireFailureOf otherGestureRecognizer: UIGestureRecognizer) -> Bool { public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRequireFailureOf otherGestureRecognizer: UIGestureRecognizer) -> Bool {
return false return false
} }
} }
@ -330,7 +330,7 @@ public class Window1 {
} }
private var windowPanRecognizer: WindowPanRecognizer? private var windowPanRecognizer: WindowPanRecognizer?
private let keyboardGestureRecognizerDelegate = KeyboardGestureRecognizerDelegate() private let keyboardGestureRecognizerDelegate = WindowKeyboardGestureRecognizerDelegate()
private var keyboardGestureBeginLocation: CGPoint? private var keyboardGestureBeginLocation: CGPoint?
private var keyboardGestureAccessoryHeight: CGFloat? private var keyboardGestureAccessoryHeight: CGFloat?

View File

@ -1,13 +1,13 @@
import Foundation import Foundation
final class WindowPanRecognizer: UIGestureRecognizer { public final class WindowPanRecognizer: UIGestureRecognizer {
var began: ((CGPoint) -> Void)? public var began: ((CGPoint) -> Void)?
var moved: ((CGPoint) -> Void)? public var moved: ((CGPoint) -> Void)?
var ended: ((CGPoint, CGPoint?) -> Void)? public var ended: ((CGPoint, CGPoint?) -> Void)?
private var previousPoints: [(CGPoint, Double)] = [] private var previousPoints: [(CGPoint, Double)] = []
override func reset() { override public func reset() {
super.reset() super.reset()
self.previousPoints.removeAll() self.previousPoints.removeAll()
@ -40,7 +40,7 @@ final class WindowPanRecognizer: UIGestureRecognizer {
} }
} }
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent) { override public func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent) {
super.touchesBegan(touches, with: event) super.touchesBegan(touches, with: event)
if let touch = touches.first { if let touch = touches.first {
@ -50,7 +50,7 @@ final class WindowPanRecognizer: UIGestureRecognizer {
} }
} }
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent) { override public func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent) {
super.touchesMoved(touches, with: event) super.touchesMoved(touches, with: event)
if let touch = touches.first { if let touch = touches.first {
@ -60,7 +60,7 @@ final class WindowPanRecognizer: UIGestureRecognizer {
} }
} }
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent) { override public func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent) {
super.touchesEnded(touches, with: event) super.touchesEnded(touches, with: event)
if let touch = touches.first { if let touch = touches.first {
@ -70,7 +70,7 @@ final class WindowPanRecognizer: UIGestureRecognizer {
} }
} }
override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent) { override public func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent) {
super.touchesCancelled(touches, with: event) super.touchesCancelled(touches, with: event)
if let touch = touches.first { if let touch = touches.first {