Repository navigation
Expand file tree
/
Copy pathLGUIStateTweak.swift
More file actions
47 lines (43 loc) · 1.97 KB
/
Copy pathLGUIStateTweak.swift
File metadata and controls
47 lines (43 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import LUIAppleBackend
import SwiftUI
@MainActor
enum LGUIStateTweak {
static func register(in registry: LUIAppleExtensionRegistry) throws {
try registry.registerTweak(LUIAppleTweak(
identifier: "ui-state",
fingerprint: "lui-tweak-v1|8:ui-state|profiles:ios/swiftui|properties:13:editor-active:bool:required:none,17:presentation-open:bool:required:none,6:screen:string:required:none",
properties: [
.init(name: "screen", kind: .string, isRequired: true),
.init(name: "editor-active", kind: .bool, isRequired: true),
.init(name: "presentation-open", kind: .bool, isRequired: true),
]
) { content, context in
AnyView(LGUIStateContent(content: content, context: context))
})
}
}
private struct LGUIStateContent: View {
let content: AnyView
let context: LUIAppleExtensionViewContext
private struct State: Equatable {
let screen: String
let editorActive: Bool
let presentationOpen: Bool
}
var body: some View {
let _ = context.revision
let screen: String = if case let .string(value) = context.property("screen") { value } else { "unknown" }
let state = State(screen: screen, editorActive: context.property("editor-active") == .bool(true),
presentationOpen: context.property("presentation-open") == .bool(true))
content
#if os(iOS)
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
.ignoresSafeArea(.keyboard, edges: state.presentationOpen ? .bottom : [])
.onChange(of: state, initial: true) { _, state in
LogseqCrashReporting.uiState(screen: .init(rawValue: state.screen) ?? .unknown,
editorActive: state.editorActive)
LogseqCrashReporting.presentation(.core, open: state.presentationOpen)
}
#endif
}
}