Compare commits

...

4 Commits

Author SHA1 Message Date
Duraid Abdul da9d78f559 Merge branch 'main' of https://github.com/duraidabdul/LocalConsole 2022-01-21 12:47:53 -08:00
Duraid Abdul 50e4ce4e03 Update LCManager.swift 2022-01-21 12:47:50 -08:00
Duraid Abdul ae73be37b4 Update README.md 2022-01-17 12:08:39 -08:00
Duraid Abdul eeece2fda8 Update LCManager.swift
Fix for touch passthrough.
2021-12-26 00:39:38 -08:00
2 changed files with 38 additions and 6 deletions
+1 -1
View File
@@ -21,7 +21,7 @@ let consoleManager = LCManager.shared
```
## **Usage**
Once prepared, the localConsole can be used throughout your project.
Once prepared, the consoleManager can be used throughout your project.
```swift
// Activate the console view.
+37 -5
View File
@@ -391,7 +391,7 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
consoleWindow?.windowLevel = UIWindow.Level.statusBar
consoleWindow?.isHidden = false
viewController = ConsoleViewController()
viewController.view = PassthroughView()
consoleWindow?.rootViewController = viewController
@@ -534,10 +534,20 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
/// Print items to the console view.
public func print(_ items: Any) {
if currentText == "" {
currentText = "\(items)"
let _currentText: String = {
if currentText == "" {
return "\(items)"
} else {
return currentText + "\n\(items)"
}
}()
// Cut down string if it exceeds 300,000 characters to keep text view running smoothly.
if _currentText.count > 300000 {
let shortenedString = String(_currentText.suffix(300000))
currentText = shortenedString.stringAfterFirstOccurenceOf(delimiter: "\n") ?? shortenedString
} else {
currentText = currentText + "\n\(items)"
currentText = _currentText
}
}
@@ -995,6 +1005,18 @@ class ConsoleWindow: UIWindow {
}
}
// Custom view for the console to appear above other windows while passing touches down.
class PassthroughView: UIView {
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
if let hitView = super.hitTest(point, with: event) {
return hitView.isKind(of: PassthroughView.self) ? nil : hitView
}
return super.hitTest(point, with: event)
}
}
import UIKit.UIGestureRecognizerSubclass
@@ -1122,7 +1144,7 @@ class InvertedTextView: UITextView {
var pendingOffsetChange = false
// Thanks to WWDC21 Lab!
// Thanks to WWDC21 UIKit Lab!
override func layoutSubviews() {
super.layoutSubviews()
@@ -1154,6 +1176,14 @@ extension UIDevice {
}
}
extension String {
func stringAfterFirstOccurenceOf(delimiter: String) -> String? {
guard let upperIndex = (self.range(of: delimiter)?.upperBound) else { return nil }
let trailingString: String = .init(self.suffix(from: upperIndex))
return trailingString
}
}
extension TimeInterval {
var formattedString: String? {
let formatter = DateComponentsFormatter()
@@ -1168,6 +1198,8 @@ fileprivate func _debugPrint(_ items: Any) {
// Support for auto-rotate.
class ConsoleViewController: UIViewController {
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
// Cancel the panner console is being panned to allow for location manipulation.