@@ -60,6 +60,15 @@ class NewGutenbergViewController: PostGBKEditorViewController, PostEditor, Publi
6060
6161 // TODO: reimplemet
6262// internal private(set) var contentInfo: ContentInfo?
63+ private var isNavigationEnabled = true {
64+ didSet { updateHistoryButtons ( ) }
65+ }
66+ private var isUndoButtonDisabled = true {
67+ didSet { updateHistoryButtons ( ) }
68+ }
69+ private var isRedoButtonDisabled = true {
70+ didSet { updateHistoryButtons ( ) }
71+ }
6372
6473 // MARK: - GutenbergKit
6574
@@ -154,28 +163,34 @@ class NewGutenbergViewController: PostGBKEditorViewController, PostEditor, Publi
154163
155164 private func gutenbergDidRequestToggleRedoButton( _ isDisabled: Bool ) {
156165 DispatchQueue . main. async {
157- UIView . animate ( withDuration: 0.2 ) {
158- self . navigationBarManager. redoButton. isUserInteractionEnabled = isDisabled ? false : true
159- self . navigationBarManager. redoButton. alpha = isDisabled ? 0.3 : 1.0
160- }
166+ self . isRedoButtonDisabled = isDisabled
161167 }
162168 }
163169
164170 private func gutenbergDidRequestToggleUndoButton( _ isDisabled: Bool ) {
165171 DispatchQueue . main. async {
166- UIView . animate ( withDuration: 0.2 ) {
167- self . navigationBarManager. undoButton. isUserInteractionEnabled = isDisabled ? false : true
168- self . navigationBarManager. undoButton. alpha = isDisabled ? 0.3 : 1.0
169- }
172+ self . isUndoButtonDisabled = isDisabled
170173 }
171174 }
172175
173176 private func setNavigationItemsEnabled( _ enabled: Bool ) {
177+ isNavigationEnabled = enabled
174178 navigationBarManager. closeButton. isEnabled = enabled
175179 navigationBarManager. moreButton. isEnabled = enabled
176- navigationBarManager. publishButton. isEnabled = enabled
177- navigationBarManager. undoButton. isEnabled = enabled
178- navigationBarManager. redoButton. isEnabled = enabled
180+ navigationBarManager. publishButton. isEnabled = enabled && isPublishButtonEnabled
181+ }
182+
183+ private func updateHistoryButtons( ) {
184+ updateHistoryButton ( navigationBarManager. undoButton, isDisabled: !isNavigationEnabled || isUndoButtonDisabled)
185+ updateHistoryButton ( navigationBarManager. redoButton, isDisabled: !isNavigationEnabled || isRedoButtonDisabled)
186+ }
187+
188+ private func updateHistoryButton( _ button: UIButton , isDisabled: Bool ) {
189+ let isEnabled = !isDisabled
190+ UIView . animate ( withDuration: 0.2 ) {
191+ button. isEnabled = isEnabled
192+ button. alpha = isEnabled ? 1.0 : 0.3
193+ }
179194 }
180195
181196 private func performAutoSave( ) {
0 commit comments