-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathSuggestionSection.swift
More file actions
62 lines (58 loc) · 2.03 KB
/
SuggestionSection.swift
File metadata and controls
62 lines (58 loc) · 2.03 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import SwiftUI
struct SuggestionSection: View {
@AppStorage(\.realtimeSuggestionToggle) var realtimeSuggestionToggle
@AppStorage(\.suggestionFeatureEnabledProjectList) var suggestionFeatureEnabledProjectList
@AppStorage(\.acceptSuggestionWithTab) var acceptSuggestionWithTab
@State var isSuggestionFeatureDisabledLanguageListViewOpen = false
@State private var shouldPresentTurnoffSheet = false
var realtimeSuggestionBinding : Binding<Bool> {
Binding(
get: { realtimeSuggestionToggle },
set: {
if !$0 {
shouldPresentTurnoffSheet = true
} else {
realtimeSuggestionToggle = $0
}
}
)
}
var body: some View {
SettingsSection(title: "Suggestion Settings") {
SettingsToggle(
title: "Request suggestions while typing",
isOn: realtimeSuggestionBinding
)
Divider()
SettingsToggle(
title: "Accept suggestions with Tab",
isOn: $acceptSuggestionWithTab
)
} footer: {
HStack {
Spacer()
Button("Disabled language list") {
isSuggestionFeatureDisabledLanguageListViewOpen = true
}
}
}
.sheet(isPresented: $isSuggestionFeatureDisabledLanguageListViewOpen) {
DisabledLanguageList(isOpen: $isSuggestionFeatureDisabledLanguageListViewOpen)
}
.alert(
"Disable suggestions while typing",
isPresented: $shouldPresentTurnoffSheet
) {
Button("Disable") { realtimeSuggestionToggle = false }
Button("Cancel", role: .cancel, action: {})
} message: {
Text("""
If you disable requesting suggestions while typing, you will \
not see any suggestions until requested manually.
""")
}
}
}
#Preview {
SuggestionSection()
}