Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d5a06c013e | |||
| 3c2683c6bf |
@@ -5,8 +5,6 @@
|
||||
// Copyright © 2021 Duraid Abdul. All rights reserved.
|
||||
//
|
||||
|
||||
//#if canImport(UIKit)
|
||||
|
||||
import UIKit
|
||||
import SwiftUI
|
||||
|
||||
@@ -62,10 +60,11 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
|
||||
|
||||
lumaView.translatesAutoresizingMaskIntoConstraints = false
|
||||
|
||||
lumaWidthAnchor = lumaView.widthAnchor.constraint(equalTo: consoleView.widthAnchor)
|
||||
lumaHeightAnchor = lumaView.heightAnchor.constraint(equalToConstant: consoleView.frame.size.height)
|
||||
|
||||
NSLayoutConstraint.activate([
|
||||
lumaView.widthAnchor.constraint(equalTo: consoleView.widthAnchor),
|
||||
lumaWidthAnchor,
|
||||
lumaHeightAnchor,
|
||||
lumaView.centerXAnchor.constraint(equalTo: consoleView.centerXAnchor),
|
||||
lumaView.centerYAnchor.constraint(equalTo: consoleView.centerYAnchor)
|
||||
@@ -74,6 +73,32 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
|
||||
return lumaView
|
||||
}()
|
||||
|
||||
lazy var hideButton: UIButton = {
|
||||
let button = UIButton()
|
||||
|
||||
button.addAction(UIAction(handler: { [self] _ in
|
||||
UIViewPropertyAnimator(duration: 0.5, dampingRatio: 1) {
|
||||
consoleView.center = nearestTargetTo(consoleView.center, possibleTargets: possibleEndpoints.dropLast())
|
||||
}.startAnimation()
|
||||
grabberMode = false
|
||||
}), for: .touchUpInside)
|
||||
|
||||
consoleView.addSubview(button)
|
||||
|
||||
button.translatesAutoresizingMaskIntoConstraints = false
|
||||
|
||||
NSLayoutConstraint.activate([
|
||||
button.widthAnchor.constraint(equalTo: consoleView.widthAnchor),
|
||||
button.heightAnchor.constraint(equalTo: consoleView.heightAnchor),
|
||||
button.centerXAnchor.constraint(equalTo: consoleView.centerXAnchor),
|
||||
button.centerYAnchor.constraint(equalTo: consoleView.centerYAnchor)
|
||||
])
|
||||
|
||||
button.isHidden = true
|
||||
|
||||
return button
|
||||
}()
|
||||
|
||||
/// The fixed size of the console view.
|
||||
lazy var consoleSize = defaultConsoleSize {
|
||||
didSet {
|
||||
@@ -157,10 +182,10 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
|
||||
|
||||
// Left edge hiding endpoints.
|
||||
if consoleView.center.y < (UIScreen.portraitSize.height - (temporaryKeyboardHeightValueTracker ?? 0)) / 2 {
|
||||
endpoints.append(CGPoint(x: -consoleSize.width / 2 + 10,
|
||||
endpoints.append(CGPoint(x: -consoleSize.width / 2 + 28,
|
||||
y: endpoints[0].y))
|
||||
} else {
|
||||
endpoints.append(CGPoint(x: -consoleSize.width / 2 + 10,
|
||||
endpoints.append(CGPoint(x: -consoleSize.width / 2 + 28,
|
||||
y: endpoints[1].y))
|
||||
}
|
||||
} else if consoleView.frame.maxX >= UIScreen.portraitSize.width {
|
||||
@@ -170,10 +195,10 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
|
||||
|
||||
// Right edge hiding endpoints.
|
||||
if consoleView.center.y < (UIScreen.portraitSize.height - (temporaryKeyboardHeightValueTracker ?? 0)) / 2 {
|
||||
endpoints.append(CGPoint(x: UIScreen.portraitSize.width + consoleSize.width / 2 - 10,
|
||||
endpoints.append(CGPoint(x: UIScreen.portraitSize.width + consoleSize.width / 2 - 28,
|
||||
y: endpoints[0].y))
|
||||
} else {
|
||||
endpoints.append(CGPoint(x: UIScreen.portraitSize.width + consoleSize.width / 2 - 10,
|
||||
endpoints.append(CGPoint(x: UIScreen.portraitSize.width + consoleSize.width / 2 - 28,
|
||||
y: endpoints[1].y))
|
||||
}
|
||||
}
|
||||
@@ -300,6 +325,8 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
|
||||
menuButton.showsMenuAsPrimaryAction = true
|
||||
consoleView.addSubview(menuButton)
|
||||
|
||||
let _ = hideButton
|
||||
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name: UIResponder.keyboardWillHideNotification, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow), name: UIResponder.keyboardWillShowNotification, object: nil)
|
||||
}
|
||||
@@ -308,6 +335,25 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
|
||||
func configureWindow() {
|
||||
var windowSceneFound = false
|
||||
|
||||
// Update console cached based on last-cached origin.
|
||||
func updateConsoleOrigin() {
|
||||
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 = cachedConsolePosition // Update console center so possibleEndpoints are calculated correctly.
|
||||
consoleView.center = nearestTargetTo(cachedConsolePosition, possibleTargets: possibleEndpoints)
|
||||
|
||||
if consoleView.center.x < 0 || consoleView.center.x > UIScreen.portraitSize.width {
|
||||
grabberMode = true
|
||||
scrollLocked = !grabberMode
|
||||
|
||||
consoleView.layer.removeAllAnimations()
|
||||
lumaView.layer.removeAllAnimations()
|
||||
menuButton.layer.removeAllAnimations()
|
||||
consoleTextView.layer.removeAllAnimations()
|
||||
}
|
||||
}
|
||||
|
||||
// Configure console window.
|
||||
func fetchWindowScene() {
|
||||
let windowScene = UIApplication.shared
|
||||
@@ -326,11 +372,11 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
|
||||
consoleWindow?.addSubview(consoleView)
|
||||
|
||||
UIWindow.swizzleStatusBarAppearanceOverride
|
||||
|
||||
updateConsoleOrigin()
|
||||
}
|
||||
}
|
||||
|
||||
fetchWindowScene()
|
||||
|
||||
/// Ensures the window is configured (i.e. scene has been found). If not, delay and wait for a scene to prepare itself, then try again.
|
||||
for i in 1...10 {
|
||||
|
||||
@@ -347,16 +393,6 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
|
||||
consoleView.layer.removeAllAnimations()
|
||||
isVisible = true
|
||||
}
|
||||
|
||||
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 = cachedConsolePosition // Update console center so possibleEndpoints are calculated correctly.
|
||||
consoleView.center = nearestTargetTo(cachedConsolePosition, possibleTargets: possibleEndpoints)
|
||||
|
||||
if consoleView.center.x < 0 || consoleView.center.x > UIScreen.portraitSize.width {
|
||||
grabberMode = true
|
||||
scrollLocked = !grabberMode
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -411,11 +447,9 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
|
||||
|
||||
if grabberMode {
|
||||
|
||||
if oldValue == false {
|
||||
lumaView.layer.cornerRadius = consoleView.layer.cornerRadius
|
||||
lumaHeightAnchor.constant = consoleView.frame.size.height
|
||||
consoleView.layoutIfNeeded()
|
||||
}
|
||||
lumaView.layer.cornerRadius = consoleView.layer.cornerRadius
|
||||
lumaHeightAnchor.constant = consoleView.frame.size.height
|
||||
consoleView.layoutIfNeeded()
|
||||
|
||||
UIViewPropertyAnimator(duration: 0.3, dampingRatio: 1) { [self] in
|
||||
consoleTextView.alpha = 0
|
||||
@@ -425,9 +459,9 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
|
||||
|
||||
UIViewPropertyAnimator(duration: 0.5, dampingRatio: 1) { [self] in
|
||||
lumaView.foregroundView.alpha = 0
|
||||
|
||||
}.startAnimation()
|
||||
|
||||
lumaWidthAnchor.constant = -34
|
||||
lumaHeightAnchor.constant = 96
|
||||
UIViewPropertyAnimator(duration: 0.4, dampingRatio: 1) { [self] in
|
||||
lumaView.layer.cornerRadius = 8
|
||||
@@ -435,9 +469,12 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
|
||||
}.startAnimation(afterDelay: 0.06)
|
||||
|
||||
consoleTextView.isUserInteractionEnabled = false
|
||||
hideButton.isHidden = false
|
||||
|
||||
} else {
|
||||
|
||||
lumaHeightAnchor.constant = consoleView.frame.size.height
|
||||
lumaWidthAnchor.constant = 0
|
||||
UIViewPropertyAnimator(duration: 0.4, dampingRatio: 1) { [self] in
|
||||
consoleView.layoutIfNeeded()
|
||||
lumaView.layer.cornerRadius = consoleView.layer.cornerRadius
|
||||
@@ -454,6 +491,7 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
|
||||
}.startAnimation()
|
||||
|
||||
consoleTextView.isUserInteractionEnabled = true
|
||||
hideButton.isHidden = true
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -767,7 +805,7 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
|
||||
if !grabberMode { scrollLocked = true }
|
||||
|
||||
UIViewPropertyAnimator(duration: 0.8, dampingRatio: 0.5) { [self] in
|
||||
consoleView.transform = .init(scaleX: 1, y: 1)
|
||||
consoleView.transform = .identity
|
||||
}.startAnimation()
|
||||
|
||||
UIViewPropertyAnimator(duration: 0.4, dampingRatio: 1) { [self] in
|
||||
@@ -798,13 +836,9 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
|
||||
consoleView.center.y = initialViewLocation.y + translation.y
|
||||
|
||||
if consoleView.frame.maxX > 30 && consoleView.frame.minX < UIScreen.portraitSize.width - 30 {
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) {
|
||||
self.grabberMode = false
|
||||
}
|
||||
self.grabberMode = false
|
||||
} else {
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) {
|
||||
self.grabberMode = true
|
||||
}
|
||||
self.grabberMode = true
|
||||
}
|
||||
|
||||
case .ended, .cancelled:
|
||||
@@ -945,8 +979,6 @@ extension UIWindow {
|
||||
}
|
||||
}
|
||||
|
||||
//#endif
|
||||
|
||||
class LumaView: UIView {
|
||||
lazy var visualEffectView: UIView = {
|
||||
Bundle(path: "/Sys" + "tem/Lib" + "rary/Private" + "Frameworks/Material" + "Kit." + "framework")!.load()
|
||||
@@ -1010,6 +1042,9 @@ class LumaView: UIView {
|
||||
let _ = visualEffectView
|
||||
let _ = foregroundView
|
||||
|
||||
visualEffectView.isUserInteractionEnabled = false
|
||||
foregroundView.isUserInteractionEnabled = false
|
||||
|
||||
layer.cornerCurve = .continuous
|
||||
clipsToBounds = true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user