@@ -6,6 +6,7 @@ struct EditorView: View {
6
6
@State private var isModalDialogOpen = false
7
7
@State private var hasUndo = false
8
8
@State private var hasRedo = false
9
+ @State private var isCodeEditorEnabled = false
9
10
@State private var editorViewController : EditorViewController ?
10
11
@Environment ( \. dismiss) private var dismiss
11
12
@@ -19,6 +20,7 @@ struct EditorView: View {
19
20
isModalDialogOpen: $isModalDialogOpen,
20
21
hasUndo: $hasUndo,
21
22
hasRedo: $hasRedo,
23
+ isCodeEditorEnabled: $isCodeEditorEnabled,
22
24
editorViewController: $editorViewController
23
25
)
24
26
. navigationBarBackButtonHidden ( true )
@@ -58,9 +60,14 @@ struct EditorView: View {
58
60
private var moreMenu : some View {
59
61
Menu {
60
62
Section {
61
- Button ( action: { } , label: {
62
- Label ( " Code Editor " , systemImage: " curlybraces " )
63
- } ) . disabled ( true )
63
+ Button ( action: {
64
+ isCodeEditorEnabled. toggle ( )
65
+ } , label: {
66
+ Label (
67
+ isCodeEditorEnabled ? " Visual Editor " : " Code Editor " ,
68
+ systemImage: isCodeEditorEnabled ? " doc.richtext " : " curlybraces "
69
+ )
70
+ } )
64
71
Button ( action: /*@START_MENU_TOKEN@*/{ } /*@END_MENU_TOKEN@*/, label: {
65
72
Label ( " Preview " , systemImage: " safari " )
66
73
} ) . disabled ( true )
@@ -90,19 +97,22 @@ private struct _EditorView: UIViewControllerRepresentable {
90
97
@Binding var isModalDialogOpen : Bool
91
98
@Binding var hasUndo : Bool
92
99
@Binding var hasRedo : Bool
100
+ @Binding var isCodeEditorEnabled : Bool
93
101
@Binding var editorViewController : EditorViewController ?
94
102
95
103
init (
96
104
configuration: EditorConfiguration ,
97
105
isModalDialogOpen: Binding < Bool > ,
98
106
hasUndo: Binding < Bool > ,
99
107
hasRedo: Binding < Bool > ,
108
+ isCodeEditorEnabled: Binding < Bool > ,
100
109
editorViewController: Binding < EditorViewController ? >
101
110
) {
102
111
self . configuration = configuration
103
112
self . _isModalDialogOpen = isModalDialogOpen
104
113
self . _hasUndo = hasUndo
105
114
self . _hasRedo = hasRedo
115
+ self . _isCodeEditorEnabled = isCodeEditorEnabled
106
116
self . _editorViewController = editorViewController
107
117
}
108
118
@@ -132,7 +142,7 @@ private struct _EditorView: UIViewControllerRepresentable {
132
142
}
133
143
134
144
func updateUIViewController( _ uiViewController: EditorViewController , context: Context ) {
135
- // Do nothing
145
+ uiViewController . isCodeEditorEnabled = isCodeEditorEnabled
136
146
}
137
147
138
148
@MainActor
0 commit comments