From 7064d5d8f57331504ebd9ad781cb926e29c3c802 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Sun, 12 Apr 2020 11:48:14 -0500 Subject: [PATCH] Fix regression where navigating back and paging back from an article happened at the same time. --- NetNewsWire.xcodeproj/project.pbxproj | 6 ++++- iOS/Article/ArticleViewController.swift | 27 ++++++++++++++++++- .../UIPageViewController-Extensions.swift | 22 +++++++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 iOS/UIKit Extensions/UIPageViewController-Extensions.swift diff --git a/NetNewsWire.xcodeproj/project.pbxproj b/NetNewsWire.xcodeproj/project.pbxproj index a3254266e..2ea40713b 100644 --- a/NetNewsWire.xcodeproj/project.pbxproj +++ b/NetNewsWire.xcodeproj/project.pbxproj @@ -115,6 +115,7 @@ 517630042336215100E15FFF /* main.js in Resources */ = {isa = PBXBuildFile; fileRef = 517630032336215100E15FFF /* main.js */; }; 517630052336215100E15FFF /* main.js in Resources */ = {isa = PBXBuildFile; fileRef = 517630032336215100E15FFF /* main.js */; }; 517630232336657E00E15FFF /* WebViewProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 517630222336657E00E15FFF /* WebViewProvider.swift */; }; + 517A745B2443665000B553B9 /* UIPageViewController-Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 517A745A2443665000B553B9 /* UIPageViewController-Extensions.swift */; }; 5183CCD0226E1E880010922C /* NonIntrinsicLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5183CCCF226E1E880010922C /* NonIntrinsicLabel.swift */; }; 5183CCDA226E31A50010922C /* NonIntrinsicImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5183CCD9226E31A50010922C /* NonIntrinsicImageView.swift */; }; 5183CCE5226F4DFA0010922C /* RefreshInterval.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5183CCE4226F4DFA0010922C /* RefreshInterval.swift */; }; @@ -1324,6 +1325,7 @@ 51707438232AA97100A461A3 /* ShareFolderPickerController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShareFolderPickerController.swift; sourceTree = ""; }; 517630032336215100E15FFF /* main.js */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.javascript; path = main.js; sourceTree = ""; }; 517630222336657E00E15FFF /* WebViewProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebViewProvider.swift; sourceTree = ""; }; + 517A745A2443665000B553B9 /* UIPageViewController-Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIPageViewController-Extensions.swift"; sourceTree = ""; }; 5183CCCF226E1E880010922C /* NonIntrinsicLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NonIntrinsicLabel.swift; sourceTree = ""; }; 5183CCD9226E31A50010922C /* NonIntrinsicImageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NonIntrinsicImageView.swift; sourceTree = ""; }; 5183CCE4226F4DFA0010922C /* RefreshInterval.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RefreshInterval.swift; sourceTree = ""; }; @@ -1927,6 +1929,7 @@ 51C45245226506C800C03939 /* UIKit Extensions */ = { isa = PBXGroup; children = ( + 51F9F3FA23DFB25700A314FD /* Animations.swift */, 51F85BFA2275D85000C787DC /* Array-Extensions.swift */, 51F85BF42273625800C787DC /* Bundle-Extensions.swift */, 51627A92238A3836007B3B4B /* CroppingPreviewParameters.swift */, @@ -1944,13 +1947,13 @@ C5A6ED6C23C9B0C800AB6BE2 /* UIActivityViewController-Extensions.swift */, 51F85BF82274AA7B00C787DC /* UIBarButtonItem-Extensions.swift */, 51F85BF622749FA100C787DC /* UIFont-Extensions.swift */, + 517A745A2443665000B553B9 /* UIPageViewController-Extensions.swift */, 51C4524E226506F400C03939 /* UIStoryboard-Extensions.swift */, 51F9F3F823DFB16300A314FD /* UITableView-Extensions.swift */, 518ED21C23D0F26000E0A862 /* UIViewController-Extensions.swift */, 51FFF0C3235EE8E5002762AA /* VibrantButton.swift */, 5186A634235EF3A800C97195 /* VibrantLabel.swift */, 5F323808231DF9F000706F6B /* VibrantTableViewCell.swift */, - 51F9F3FA23DFB25700A314FD /* Animations.swift */, ); path = "UIKit Extensions"; sourceTree = ""; @@ -3950,6 +3953,7 @@ 51EF0F77227716200050506E /* FaviconGenerator.swift in Sources */, 51938DF3231AFC660055A1A0 /* SearchTimelineFeedDelegate.swift in Sources */, 51C4525A226508D600C03939 /* UIStoryboard-Extensions.swift in Sources */, + 517A745B2443665000B553B9 /* UIPageViewController-Extensions.swift in Sources */, 51BB7C272335A8E5008E8144 /* ArticleActivityItemSource.swift in Sources */, 51F85BF52273625800C787DC /* Bundle-Extensions.swift in Sources */, 51C452A622650A3500C03939 /* Node-Extensions.swift in Sources */, diff --git a/iOS/Article/ArticleViewController.swift b/iOS/Article/ArticleViewController.swift index 3768d3441..8b47ffa05 100644 --- a/iOS/Article/ArticleViewController.swift +++ b/iOS/Article/ArticleViewController.swift @@ -92,8 +92,15 @@ class ArticleViewController: UIViewController { pageViewController = UIPageViewController(transitionStyle: .scroll, navigationOrientation: .horizontal, options: [:]) pageViewController.delegate = self pageViewController.dataSource = self + + // This code is to disallow paging if we scroll from the left edge. If this code is removed + // PoppableGestureRecognizerDelegate will allow us to both navigate back and page back at the + // same time. That is really weird when it happens. + let panGestureRecognizer = UIPanGestureRecognizer() + panGestureRecognizer.delegate = self + pageViewController.scrollViewInsidePageControl?.addGestureRecognizer(panGestureRecognizer) + pageViewController.view.translatesAutoresizingMaskIntoConstraints = false - view.addSubview(pageViewController.view) addChild(pageViewController!) NSLayoutConstraint.activate([ @@ -329,6 +336,24 @@ extension ArticleViewController: UIPageViewControllerDelegate { } +// MARK: UIGestureRecognizerDelegate + +extension ArticleViewController: UIGestureRecognizerDelegate { + + func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool { + return true + } + + func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool { + let point = gestureRecognizer.location(in: nil) + if point.x > 40 { + return true + } + return false + } + +} + // MARK: Private private extension ArticleViewController { diff --git a/iOS/UIKit Extensions/UIPageViewController-Extensions.swift b/iOS/UIKit Extensions/UIPageViewController-Extensions.swift new file mode 100644 index 000000000..8db0ce553 --- /dev/null +++ b/iOS/UIKit Extensions/UIPageViewController-Extensions.swift @@ -0,0 +1,22 @@ +// +// UIPageViewController-Extensions.swift +// NetNewsWire-iOS +// +// Created by Maurice Parker on 4/12/20. +// Copyright © 2020 Ranchero Software. All rights reserved. +// + +import UIKit + +extension UIPageViewController { + + var scrollViewInsidePageControl: UIScrollView? { + for view in view.subviews { + if let scrollView = view as? UIScrollView { + return scrollView + } + } + return nil + } + +}