Skip to content

Commit

Permalink
Merge pull request #162 from cocoatype/128-search-button-auto-dismiss…
Browse files Browse the repository at this point in the history
…es-on-ipad

Fix dismissal of seek and destroy on iPad
  • Loading branch information
Arclite authored Jun 25, 2024
2 parents 60be353 + 78cf4c0 commit 3dba6cb
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ class PhotoEditingNavigationController: NavigationController, PhotoEditingProtec
(viewControllers.first as? PhotoEditingViewController)?.finishSeeking(sender)
}

@objc public func seekBarDidChangeText(_ sender: UISearchTextField) {
(viewControllers.first as? PhotoEditingViewController)?.seekBarDidChangeText(sender)
}

// MARK: Dismissal

@objc func dismissPhotoEditingViewController(_ sender: UIBarButtonItem) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ public class PhotoEditingViewController: UIViewController, UIScrollViewDelegate,

open override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)

guard let previousTraitCollection,
previousTraitCollection.horizontalSizeClass != traitCollection.horizontalSizeClass ||
previousTraitCollection.verticalSizeClass != traitCollection.verticalSizeClass
else { return }

updateToolbarItems(animated: false)
updateSeekPresentation()
}
Expand Down Expand Up @@ -209,7 +215,7 @@ public class PhotoEditingViewController: UIViewController, UIScrollViewDelegate,
let seekViewController = TabletSeekViewController()
seekViewController.popoverPresentationController?.barButtonItem = sender as? UIBarButtonItem
seekViewController.popoverPresentationController?.delegate = self
present(seekViewController, animated: true, completion: nil)
present(seekViewController, animated: true)
} else {
seekBar.becomeFirstResponder()
}
Expand Down Expand Up @@ -258,7 +264,7 @@ public class PhotoEditingViewController: UIViewController, UIScrollViewDelegate,
open override var canResignFirstResponder: Bool { true }

public func presentationControllerDidDismiss(_ presentationController: UIPresentationController) {
self.cancelSeeking(presentationController)
cancelSeeking(presentationController)
}

public func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Created by Geoff Pado on 6/24/24.
// Copyright © 2024 Cocoatype, LLC. All rights reserved.

import UIKit

class TabletSeekSearchBar: UISearchBar, UISearchTextFieldDelegate {
init() {
super.init(frame: .zero)
searchTextField.delegate = self
returnKeyType = .done
translatesAutoresizingMaskIntoConstraints = false

searchTextField.addTarget(nil, action: #selector(PhotoEditingViewController.seekBarDidChangeText(_:)), for: .editingChanged)
}

func textFieldShouldReturn(_ textField: UITextField) -> Bool {
chain(selector: #selector(PhotoEditingViewController.finishSeeking(_:)))
return false
}

// MARK: Boilerplate

@available(*, unavailable)
required init(coder: NSCoder) {
let typeName = NSStringFromClass(type(of: self))
fatalError("\(typeName) does not implement init(coder:)")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,3 @@ class TabletSeekView: UIView {
fatalError("\(typeName) does not implement init(coder:)")
}
}

class TabletSeekSearchBar: UISearchBar, UISearchTextFieldDelegate {
init() {
super.init(frame: .zero)
searchTextField.delegate = self
returnKeyType = .done
translatesAutoresizingMaskIntoConstraints = false

searchTextField.addTarget(nil, action: #selector(PhotoEditingViewController.seekBarDidChangeText(_:)), for: .editingChanged)
}

func textFieldShouldReturn(_ textField: UITextField) -> Bool {
chain(selector: #selector(PhotoEditingViewController.finishSeeking(_:)))
return false
}

// MARK: Boilerplate

@available(*, unavailable)
required init(coder: NSCoder) {
let typeName = NSStringFromClass(type(of: self))
fatalError("\(typeName) does not implement init(coder:)")
}
}

0 comments on commit 3dba6cb

Please sign in to comment.