@@ -60,6 +60,16 @@ class NewGutenbergViewController: PostGBKEditorViewController, PostEditor, Publi
6060
6161 // TODO: reimplemet
6262// internal private(set) var contentInfo: ContentInfo?
63+ private var isUndoButtonDisabled = true {
64+ didSet {
65+ updateUndoButtonIfNavigationIsEnabled ( )
66+ }
67+ }
68+ private var isRedoButtonDisabled = true {
69+ didSet {
70+ updateRedoButtonIfNavigationIsEnabled ( )
71+ }
72+ }
6373
6474 // MARK: - GutenbergKit
6575
@@ -154,28 +164,58 @@ class NewGutenbergViewController: PostGBKEditorViewController, PostEditor, Publi
154164
155165 private func gutenbergDidRequestToggleRedoButton( _ isDisabled: Bool ) {
156166 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- }
167+ self . isRedoButtonDisabled = isDisabled
161168 }
162169 }
163170
164171 private func gutenbergDidRequestToggleUndoButton( _ isDisabled: Bool ) {
165172 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- }
173+ self . isUndoButtonDisabled = isDisabled
170174 }
171175 }
172176
173177 private func setNavigationItemsEnabled( _ enabled: Bool ) {
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+ if enabled {
183+ updateUndoButton ( )
184+ updateRedoButton ( )
185+ } else {
186+ updateHistoryButton ( navigationBarManager. undoButton, isDisabled: true )
187+ updateHistoryButton ( navigationBarManager. redoButton, isDisabled: true )
188+ }
189+ }
190+
191+ private func updateUndoButtonIfNavigationIsEnabled( ) {
192+ guard navigationBarManager. closeButton. isEnabled else {
193+ return
194+ }
195+ updateUndoButton ( )
196+ }
197+
198+ private func updateRedoButtonIfNavigationIsEnabled( ) {
199+ guard navigationBarManager. closeButton. isEnabled else {
200+ return
201+ }
202+ updateRedoButton ( )
203+ }
204+
205+ private func updateUndoButton( ) {
206+ updateHistoryButton ( navigationBarManager. undoButton, isDisabled: isUndoButtonDisabled)
207+ }
208+
209+ private func updateRedoButton( ) {
210+ updateHistoryButton ( navigationBarManager. redoButton, isDisabled: isRedoButtonDisabled)
211+ }
212+
213+ private func updateHistoryButton( _ button: UIButton , isDisabled: Bool ) {
214+ let isEnabled = !isDisabled
215+ UIView . animate ( withDuration: 0.2 ) {
216+ button. isEnabled = isEnabled
217+ button. alpha = isEnabled ? 1.0 : 0.3
218+ }
179219 }
180220
181221 private func performAutoSave( ) {
0 commit comments