Skip to content

Commit

Permalink
Merge pull request #74 from iZettle/fix-navigation-controller-root-bug
Browse files Browse the repository at this point in the history
Fix navigation controller root bug
  • Loading branch information
CJEkman authored Jan 13, 2021
2 parents ab9d83e + c8547f8 commit 6f05074
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 1.13.3
- [Bug fix] Fix bug related to presenting a `UINavigationController` modally without an explicit root `UIViewController`, resulting in unexpected behaviour of `UITextField` input cursors.

# 1.13.2
- Update project settings for Xcode 12 and fix some deprecation warnings

Expand Down
4 changes: 4 additions & 0 deletions Examples/StylesAndOptions/Example/AppFlow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ extension AppFlow: Presentable {
return containerController.present(Presentation(TestNavigationBarHiding(), style: .modal)).toVoid()
}

if options.contains(.modalNavigationControllerFlow) {
return containerController.present(Presentation(TestNavigationControllerFlow(), style: .modal, configure: withDismiss))
}

if options.contains(.allowSwipeDismissAlways) {
struct NavigationStack: Presentable {
func materialize() -> (UIViewController, Disposable) {
Expand Down
2 changes: 2 additions & 0 deletions Examples/StylesAndOptions/Example/ChooseOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ struct ChoosePresentationOptions { }
extension PresentationOptions {
static let navigationBarPreference = PresentationOptions()
static let showAlertOnDidAttemptToDismiss = PresentationOptions()
static let modalNavigationControllerFlow = PresentationOptions()
}

extension PresentationOptions {
static func namedOptionsDataSource() -> DataSource<NamedPresentationOptions> {
let presentationOptions: [(String, PresentationOptions)] = [
("Default", .defaults),
("Embed In Navigation Controller", .embedInNavigationController),
("Modal Navigation Controller flow", .modalNavigationControllerFlow),
("Dont Wait For Dismiss Animation", .dontWaitForDismissAnimation),
("Unanimated", .unanimated),
("Restore first responder", .restoreFirstResponder),
Expand Down
20 changes: 18 additions & 2 deletions Examples/StylesAndOptions/Example/NavigationExample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import Flow

struct NavigationExample { }

struct TestNavigationBarHiding {
struct TestNavigationBarHiding { }

}
struct TestNavigationControllerFlow { }

extension TestNavigationBarHiding: Presentable {
func materialize() -> (UIViewController, Disposable) {
Expand Down Expand Up @@ -52,3 +52,19 @@ extension NavigationExample: Presentable {
})
}
}

extension TestNavigationControllerFlow: Presentable {
public func materialize() -> (UIViewController, Future<Void>) {
let nc = UINavigationController()

return (nc, Future { completion in
let bag = DisposeBag()

bag += nc.present(NavigationExample()).onValueDisposePrevious { _ in
nc.present(NavigationExample()).onValue { completion(.success)}
}

return bag
})
}
}
21 changes: 21 additions & 0 deletions Examples/StylesAndOptions/ExampleUITests/ExampleUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,27 @@ class ExampleUITests: XCTestCase {

app.terminate()
}

func testModalNavigationController() {
app.launch()

let navBar = app.navigationBars["UIView"]
let cancelButton = app.buttons["Cancel"]
let nextButton = app.buttons["Next"]
let backButton = navBar.buttons["Back"]

chooseStyleAndOption(style: "default", option: "Modal Navigation Controller flow")

XCTAssertTrue(navBar.exists)
cancelButton.waitForExistenceAndTap()

chooseStyleAndOption(style: "default", option: "Modal Navigation Controller flow")

nextButton.waitForExistenceAndTap()
backButton.waitForExistenceAndTap()
nextButton.waitForExistenceAndTap()
nextButton.waitForExistenceAndTap()
}

// MARK: - Helpers
func verifyForAllContainerConfigurations(_ verify: () -> ()) {
Expand Down
2 changes: 1 addition & 1 deletion Presentation/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.13.2</string>
<string>1.13.3</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
3 changes: 3 additions & 0 deletions Presentation/PresentationStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ public extension PresentationStyle {
}
}

bag += viewController.installDismissButton().onValue {
completion(.failure(PresentError.dismissed))
}
bag += presented.installDismissButton().onValue {
completion(.failure(PresentError.dismissed))
}
Expand Down
2 changes: 1 addition & 1 deletion Presentation/UIViewController+Presentation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public extension UIViewController {
// iOS 13 temporary fix for issue #40: https://github.com/iZettle/Presentation/issues/40
let shouldPresentImmediately: Bool
if #available(iOS 13.0, *) {
shouldPresentImmediately = root is UISplitViewController || vc is UISplitViewController
shouldPresentImmediately = root is UISplitViewController || vc is UISplitViewController || (root as? UINavigationController)?.viewControllers.isEmpty == true
} else {
shouldPresentImmediately = false
}
Expand Down
2 changes: 1 addition & 1 deletion PresentationFramework.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "PresentationFramework"
s.version = "1.13.2"
s.version = "1.13.3"
s.module_name = "Presentation"
s.summary = "Driving presentations from model to result"
s.description = <<-DESC
Expand Down
2 changes: 1 addition & 1 deletion PresentationTests/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.13.2</string>
<string>1.13.3</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
Expand Down

0 comments on commit 6f05074

Please sign in to comment.