Skip to content

Commit e84f565

Browse files
committed
add shake to present opt in
1 parent 8858140 commit e84f565

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// The MIT License (MIT)
2+
//
3+
// Copyright (c) 2020-2024 Alexander Grebenyuk (github.com/kean).
4+
5+
import UIKit
6+
import SwiftUI
7+
8+
#if os(iOS)
9+
10+
extension UIViewController {
11+
12+
// swiftlint:disable:next override_in_extension
13+
open override func motionBegan(_ motion: UIEvent.EventSubtype, with event: UIEvent?) {
14+
15+
if #available(iOS 16.0, *),
16+
motion == .motionShake,
17+
UserDefaults.standard.bool(forKey: ConsoleView.shakeToPresentIsEnableKey) {
18+
19+
let logVC = UIHostingController(rootView: NavigationStack { ConsoleView() })
20+
present(logVC, animated: true, completion: nil)
21+
}
22+
23+
next?.motionBegan(motion, with: event)
24+
}
25+
}
26+
27+
extension ConsoleView {
28+
static let shakeToPresentIsEnableKey = "pulse-shake-to-present-is-enabled"
29+
30+
public static func shakeToPresent(isEnabled: Bool) {
31+
UserDefaults.standard.set(isEnabled, forKey: shakeToPresentIsEnableKey)
32+
}
33+
}
34+
35+
#endif

0 commit comments

Comments
 (0)