|
|
|
@@ -136,21 +136,27 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
|
|
|
|
|
if consoleSize.width < UIScreen.portraitSize.width - 112 {
|
|
|
|
|
|
|
|
|
|
// Four endpoints, one for each corner.
|
|
|
|
|
var endpoints = [CGPoint(x: consoleSize.width / 2 + 12,
|
|
|
|
|
y: (UIScreen.hasRoundedCorners ? 44 : 16) + consoleSize.height / 2 + 12),
|
|
|
|
|
CGPoint(x: consoleSize.width / 2 + 12,
|
|
|
|
|
y: UIScreen.portraitSize.height - consoleSize.height / 2 - (keyboardHeight ?? consoleWindow?.safeAreaInsets.bottom ?? 0) - 12),
|
|
|
|
|
CGPoint(x: UIScreen.portraitSize.width - consoleSize.width / 2 - 12,
|
|
|
|
|
y: (UIScreen.hasRoundedCorners ? 44 : 16) + consoleSize.height / 2 + 12),
|
|
|
|
|
CGPoint(x: UIScreen.portraitSize.width - consoleSize.width / 2 - 12,
|
|
|
|
|
y: UIScreen.portraitSize.height - consoleSize.height / 2 - (keyboardHeight ?? consoleWindow?.safeAreaInsets.bottom ?? 0) - 12)]
|
|
|
|
|
var endpoints = [
|
|
|
|
|
|
|
|
|
|
// Top endpoints.
|
|
|
|
|
CGPoint(x: consoleSize.width / 2 + 12,
|
|
|
|
|
y: (UIScreen.hasRoundedCorners ? 44 : 16) + consoleSize.height / 2 + 12),
|
|
|
|
|
CGPoint(x: UIScreen.portraitSize.width - consoleSize.width / 2 - 12,
|
|
|
|
|
y: (UIScreen.hasRoundedCorners ? 44 : 16) + consoleSize.height / 2 + 12),
|
|
|
|
|
|
|
|
|
|
// Bottom endpoints.
|
|
|
|
|
CGPoint(x: consoleSize.width / 2 + 12,
|
|
|
|
|
y: UIScreen.portraitSize.height - consoleSize.height / 2 - (keyboardHeight ?? consoleWindow?.safeAreaInsets.bottom ?? 0) - 12),
|
|
|
|
|
CGPoint(x: UIScreen.portraitSize.width - consoleSize.width / 2 - 12,
|
|
|
|
|
y: UIScreen.portraitSize.height - consoleSize.height / 2 - (keyboardHeight ?? consoleWindow?.safeAreaInsets.bottom ?? 0) - 12)]
|
|
|
|
|
|
|
|
|
|
if consoleView.frame.minX <= 0 {
|
|
|
|
|
|
|
|
|
|
endpoints = [endpoints[0], endpoints[1]]
|
|
|
|
|
// Left edge endpoints.
|
|
|
|
|
endpoints = [endpoints[0], endpoints[2]]
|
|
|
|
|
|
|
|
|
|
// Left edge hiding endpoints.
|
|
|
|
|
if consoleView.center.y < UIScreen.portraitSize.height / 2 {
|
|
|
|
|
if consoleView.center.y < (UIScreen.portraitSize.height - (temporaryKeyboardHeightValueTracker ?? 0)) / 2 {
|
|
|
|
|
endpoints.append(CGPoint(x: -consoleSize.width / 2 + 10,
|
|
|
|
|
y: endpoints[0].y))
|
|
|
|
|
} else {
|
|
|
|
@@ -159,10 +165,11 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
|
|
|
|
|
}
|
|
|
|
|
} else if consoleView.frame.maxX >= UIScreen.portraitSize.width {
|
|
|
|
|
|
|
|
|
|
endpoints = [endpoints[2], endpoints[3]]
|
|
|
|
|
// Right edge endpoints.
|
|
|
|
|
endpoints = [endpoints[1], endpoints[3]]
|
|
|
|
|
|
|
|
|
|
// Right edge hiding endpoints.
|
|
|
|
|
if consoleView.center.y < UIScreen.portraitSize.height / 2 {
|
|
|
|
|
if consoleView.center.y < (UIScreen.portraitSize.height - (temporaryKeyboardHeightValueTracker ?? 0)) / 2 {
|
|
|
|
|
endpoints.append(CGPoint(x: UIScreen.portraitSize.width + consoleSize.width / 2 - 10,
|
|
|
|
|
y: endpoints[0].y))
|
|
|
|
|
} else {
|
|
|
|
@@ -184,7 +191,7 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
|
|
|
|
|
if consoleView.frame.minX <= 0 {
|
|
|
|
|
|
|
|
|
|
// Left edge hiding endpoints.
|
|
|
|
|
if consoleView.center.y < UIScreen.portraitSize.height / 2 {
|
|
|
|
|
if consoleView.center.y < (UIScreen.portraitSize.height - (temporaryKeyboardHeightValueTracker ?? 0)) / 2 {
|
|
|
|
|
endpoints.append(CGPoint(x: -consoleSize.width / 2 + 10,
|
|
|
|
|
y: endpoints[0].y))
|
|
|
|
|
} else {
|
|
|
|
@@ -194,7 +201,7 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
|
|
|
|
|
} else if consoleView.frame.maxX >= UIScreen.portraitSize.width {
|
|
|
|
|
|
|
|
|
|
// Right edge hiding endpoints.
|
|
|
|
|
if consoleView.center.y < UIScreen.portraitSize.height / 2 {
|
|
|
|
|
if consoleView.center.y < (UIScreen.portraitSize.height - (temporaryKeyboardHeightValueTracker ?? 0)) / 2 {
|
|
|
|
|
endpoints.append(CGPoint(x: UIScreen.portraitSize.width + consoleSize.width / 2 - 10,
|
|
|
|
|
y: endpoints[0].y))
|
|
|
|
|
} else {
|
|
|
|
@@ -217,7 +224,12 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
|
|
|
|
|
consoleView.layer.shadowRadius = 16
|
|
|
|
|
consoleView.layer.shadowOpacity = 0.5
|
|
|
|
|
consoleView.layer.shadowOffset = CGSize(width: 0, height: 2)
|
|
|
|
|
consoleView.center = possibleEndpoints.first!
|
|
|
|
|
|
|
|
|
|
let cachedConsolePosition = CGPoint(x: UserDefaults.standard.object(forKey: "LocalConsole_X") as? CGFloat ?? possibleEndpoints.first!.x,
|
|
|
|
|
y: UserDefaults.standard.object(forKey: "LocalConsole_Y") as? CGFloat ?? possibleEndpoints.first!.y)
|
|
|
|
|
|
|
|
|
|
consoleView.center = nearestTargetTo(cachedConsolePosition, possibleTargets: possibleEndpoints)
|
|
|
|
|
|
|
|
|
|
consoleView.alpha = 0
|
|
|
|
|
|
|
|
|
|
consoleView.layer.cornerRadius = 22
|
|
|
|
@@ -294,6 +306,11 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
|
|
|
|
|
menuButton.showsMenuAsPrimaryAction = true
|
|
|
|
|
consoleView.addSubview(menuButton)
|
|
|
|
|
|
|
|
|
|
if consoleView.center.x < 0 || consoleView.center.x > UIScreen.portraitSize.width {
|
|
|
|
|
grabberMode = true
|
|
|
|
|
scrollLocked = !grabberMode
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name: UIResponder.keyboardWillHideNotification, object: nil)
|
|
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow), name: UIResponder.keyboardWillShowNotification, object: nil)
|
|
|
|
|
}
|
|
|
|
@@ -404,11 +421,12 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
|
|
|
|
|
UIViewPropertyAnimator(duration: 0.3, dampingRatio: 1) { [self] in
|
|
|
|
|
consoleTextView.alpha = 0
|
|
|
|
|
menuButton.alpha = 0
|
|
|
|
|
borderView.alpha = 0
|
|
|
|
|
}.startAnimation()
|
|
|
|
|
|
|
|
|
|
UIViewPropertyAnimator(duration: 0.5, dampingRatio: 1) { [self] in
|
|
|
|
|
lumaView.foregroundView.alpha = 0
|
|
|
|
|
borderView.alpha = 0
|
|
|
|
|
|
|
|
|
|
}.startAnimation()
|
|
|
|
|
|
|
|
|
|
lumaHeightAnchor.constant = 96
|
|
|
|
@@ -462,18 +480,25 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
|
|
|
|
|
|
|
|
|
|
// MARK: - Private
|
|
|
|
|
|
|
|
|
|
var temporaryKeyboardHeightValueTracker: CGFloat?
|
|
|
|
|
|
|
|
|
|
// MARK: Handle keyboard show/hide.
|
|
|
|
|
private var keyboardHeight: CGFloat? = nil {
|
|
|
|
|
didSet {
|
|
|
|
|
|
|
|
|
|
temporaryKeyboardHeightValueTracker = oldValue
|
|
|
|
|
|
|
|
|
|
if consoleView.center != possibleEndpoints[0] && consoleView.center != possibleEndpoints[1] {
|
|
|
|
|
let nearestTargetPosition = nearestTargetTo(consoleView.center, possibleTargets: [possibleEndpoints[1], possibleEndpoints[3]])
|
|
|
|
|
let nearestTargetPosition = nearestTargetTo(consoleView.center, possibleTargets: possibleEndpoints.suffix(2))
|
|
|
|
|
|
|
|
|
|
Swift.print(possibleEndpoints.suffix(2))
|
|
|
|
|
|
|
|
|
|
UIViewPropertyAnimator(duration: 0.55, dampingRatio: 1) {
|
|
|
|
|
self.consoleView.center = nearestTargetPosition
|
|
|
|
|
}.startAnimation()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
temporaryKeyboardHeightValueTracker = keyboardHeight
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -592,10 +617,6 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@objc func toggleLock() {
|
|
|
|
|
scrollLocked.toggle()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func commitTextChanges(requestMenuUpdate menuUpdateRequested: Bool) {
|
|
|
|
|
|
|
|
|
|
if consoleTextView.contentOffset.y > consoleTextView.contentSize.height - consoleTextView.bounds.size.height - 20 {
|
|
|
|
@@ -744,7 +765,7 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
|
|
|
|
|
}.startAnimation()
|
|
|
|
|
case .cancelled, .ended:
|
|
|
|
|
|
|
|
|
|
scrollLocked = true
|
|
|
|
|
if !grabberMode { scrollLocked = true }
|
|
|
|
|
|
|
|
|
|
UIViewPropertyAnimator(duration: 0.8, dampingRatio: 0.5) { [self] in
|
|
|
|
|
consoleView.transform = .init(scaleX: 1, y: 1)
|
|
|
|
@@ -804,13 +825,16 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
|
|
|
|
|
dy: relativeVelocity(forVelocity: velocity.y, from: consoleView.center.y, to: nearestTargetPosition.y)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
let timingParameters = UISpringTimingParameters(damping: 1, response: 0.4, initialVelocity: relativeInitialVelocity)
|
|
|
|
|
let timingParameters = UISpringTimingParameters(damping: 0.85, response: 0.45, initialVelocity: relativeInitialVelocity)
|
|
|
|
|
let positionAnimator = UIViewPropertyAnimator(duration: 0, timingParameters: timingParameters)
|
|
|
|
|
positionAnimator.addAnimations { [self] in
|
|
|
|
|
consoleView.center = nearestTargetPosition
|
|
|
|
|
}
|
|
|
|
|
positionAnimator.startAnimation()
|
|
|
|
|
|
|
|
|
|
UserDefaults.standard.set(nearestTargetPosition.x, forKey: "LocalConsole_X")
|
|
|
|
|
UserDefaults.standard.set(nearestTargetPosition.y, forKey: "LocalConsole_Y")
|
|
|
|
|
|
|
|
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) {
|
|
|
|
|
self.grabberMode = nearestTargetPosition.x < 0 || nearestTargetPosition.x > UIScreen.portraitSize.width
|
|
|
|
|
self.scrollLocked = !self.grabberMode
|
|
|
|
@@ -852,15 +876,9 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
|
|
|
|
|
switch recognizer.state {
|
|
|
|
|
case .began:
|
|
|
|
|
consolePiPTouchDown()
|
|
|
|
|
case .cancelled:
|
|
|
|
|
consolePiPTouchUp()
|
|
|
|
|
case .changed:
|
|
|
|
|
break
|
|
|
|
|
case .ended:
|
|
|
|
|
consolePiPTouchUp()
|
|
|
|
|
case .failed:
|
|
|
|
|
consolePiPTouchUp()
|
|
|
|
|
case .possible:
|
|
|
|
|
case .ended, .cancelled, .possible, .failed:
|
|
|
|
|
consolePiPTouchUp()
|
|
|
|
|
@unknown default:
|
|
|
|
|
break
|
|
|
|
|