@@ -199,6 +199,9 @@ public final class ReaderPresenter: NSObject, SplitViewDisplayable {
199199 /// column (split view) or pushing to the navigation stack.
200200 private func show( _ viewController: UIViewController , isLargeTitle: Bool = false ) {
201201 if let splitViewController {
202+ guard !self . contentIsAlreadyDisplayed ( viewController, in: splitViewController, for: . secondary) else {
203+ return
204+ }
202205 ( viewController as? ReaderStreamViewController ) ? . isNotificationsBarButtonEnabled = true
203206
204207 let navigationVC = UINavigationController ( rootViewController: viewController)
@@ -207,6 +210,11 @@ public final class ReaderPresenter: NSObject, SplitViewDisplayable {
207210 }
208211 splitViewController. setViewController ( navigationVC, for: . secondary)
209212 } else {
213+ // Don't push a view controller on top of another with the same content
214+ guard !self . contentIsAlreadyDisplayed ( viewController, in: mainNavigationController) else {
215+ return
216+ }
217+
210218 mainNavigationController. safePushViewController ( viewController, animated: true )
211219 }
212220 }
@@ -215,14 +223,59 @@ public final class ReaderPresenter: NSObject, SplitViewDisplayable {
215223 /// the `.secondary` column (split view) or to the main navigation stack.
216224 private func push( _ viewController: UIViewController ) {
217225 if let splitViewController {
226+ // Don't push a view controller on top of another with the same content
227+ guard !contentIsAlreadyDisplayed( viewController, in: splitViewController, for: . secondary) else {
228+ return
229+ }
218230 let navigationVC = splitViewController. viewController ( for: . secondary) as? UINavigationController
219231 wpAssert ( navigationVC != nil )
220232 navigationVC? . safePushViewController ( viewController, animated: true )
221233 } else {
234+ // Don't push a view controller on top of another with the same content
235+ guard !self . contentIsAlreadyDisplayed ( viewController, in: mainNavigationController) else {
236+ return
237+ }
238+
222239 mainNavigationController. safePushViewController ( viewController, animated: true )
223240 }
224241 }
225242
243+ private func contentIsAlreadyDisplayed( _ viewController: UIViewController , in nav: UINavigationController ) -> Bool {
244+ if let current = nav. topViewController as? ContentIdentifiable {
245+ if let new = viewController as? ContentIdentifiable {
246+ if new. contentIdentifier == current. contentIdentifier {
247+ return true
248+ }
249+ }
250+ }
251+
252+ return false
253+ }
254+
255+ private func contentIsAlreadyDisplayed(
256+ _ viewController: UIViewController ,
257+ in split: UISplitViewController ,
258+ for column: UISplitViewController . Column
259+ ) -> Bool {
260+ guard let top = split. viewController ( for: column) else {
261+ return false
262+ }
263+
264+ if let nav = top as? UINavigationController {
265+ return contentIsAlreadyDisplayed ( viewController, in: nav)
266+ }
267+
268+ if let current = top as? ContentIdentifiable {
269+ if let new = viewController as? ContentIdentifiable {
270+ if new. contentIdentifier == current. contentIdentifier {
271+ return true
272+ }
273+ }
274+ }
275+
276+ return false
277+ }
278+
226279 // MARK: - Deep Links (ReaderNavigationPath)
227280
228281 func navigate( to path: ReaderNavigationPath ) {
0 commit comments