Skip to content

Commit

Permalink
BTPB-2280: Add a new kind to Filter model called freeTextOnly (#407)
Browse files Browse the repository at this point in the history
* Add freeTextOnly to Filter model

* Handle isFreeTextOnlySelected in RootFilterViewController

* Dismiss view if freeTextOnly option is selected

* Check if freeTextOnly option has been selected

* Update Package.resolved

* Improve navigation flow UX for search bar

* Code improvements over PR review
  • Loading branch information
nssina authored Apr 24, 2024
1 parent db18685 commit deba773
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 7 deletions.
13 changes: 11 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/finn-no/FinniversKit.git",
"state" : {
"revision" : "ae037d661da2da43a81c3996649c8fbe7d079566",
"version" : "119.0.0"
"revision" : "cf78ea25f68a5a4f4da5617e53559874d03f27ff",
"version" : "137.0.1"
}
},
{
"identity" : "warp-ios",
"kind" : "remoteSourceControl",
"location" : "https://github.com/warp-ds/warp-ios.git",
"state" : {
"revision" : "eff9401d45e51115e3902cee9a01466fcc9fb28c",
"version" : "0.0.7"
}
}
],
Expand Down
5 changes: 3 additions & 2 deletions Sources/Charcoal/CharcoalViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,9 @@ public final class CharcoalViewController: UINavigationController {
guard let rootFilterViewController = rootFilterViewController else { return }
popToRootViewController(animated: false)

if filter.kind == .freeText {
if filter.kind == .freeText || filter.kind == .freeTextOnly {
rootFilterViewController.focusOnFreeTextFilterOnNextAppearance = true
rootFilterViewController.dismissFiltersOnNextFreeTextSelection = filter.kind == .freeTextOnly
return
}

Expand Down Expand Up @@ -260,7 +261,7 @@ extension CharcoalViewController: FilterViewControllerDelegate {

public func filterViewController(_ viewController: FilterViewController, didSelectFilter filter: Filter) {
switch filter.kind {
case .standard, .freeText:
case .standard, .freeText, .freeTextOnly:
guard !filter.subfilters.isEmpty else { break }

let listViewController = ListFilterViewController(filter: filter, selectionStore: selectionStore)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public class FreeTextFilterViewController: ScrollViewController {

weak var delegate: FreeTextFilterViewControllerDelegate?

// MARK: - Internal Properties

var dismissFiltersOnNextFreeTextSelection = false

// MARK: - Private Properties

private var didClearText = false
Expand Down Expand Up @@ -61,10 +65,11 @@ public class FreeTextFilterViewController: ScrollViewController {

// MARK: - Init

init(filter: Filter, selectionStore: FilterSelectionStore, notificationCenter: NotificationCenter = .default) {
init(filter: Filter, selectionStore: FilterSelectionStore, notificationCenter: NotificationCenter = .default, dismissFiltersOnNextFreeTextSelection: Bool = false) {
self.filter = filter
self.selectionStore = selectionStore
self.notificationCenter = notificationCenter
self.dismissFiltersOnNextFreeTextSelection = dismissFiltersOnNextFreeTextSelection
super.init(nibName: nil, bundle: nil)
}

Expand Down Expand Up @@ -223,13 +228,22 @@ extension FreeTextFilterViewController: UISearchBarDelegate {

private extension FreeTextFilterViewController {
func returnToSuperView() {
if dismissFiltersOnNextFreeTextSelection {
dismissView()
dismissFiltersOnNextFreeTextSelection = false
}

if view.superview != nil {
searchBar.endEditing(false)
searchBar.setShowsCancelButton(false, animated: false)
delegate?.freeTextFilterViewControllerWillEndEditing(self)
}
}

func dismissView() {
dismiss(animated: true)
}

func setup() {
searchBar.removeFromSuperview()
view.insertSubview(tableView, belowSubview: topShadowView)
Expand Down
8 changes: 7 additions & 1 deletion Sources/Charcoal/Filters/Root/RootFilterViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ final class RootFilterViewController: FilterViewController {
didSet { freeTextFilterViewController?.filterDataSource = freeTextFilterDataSource }
}

var dismissFiltersOnNextFreeTextSelection: Bool = false
var focusOnFreeTextFilterOnNextAppearance: Bool = false

// MARK: - Private properties
Expand Down Expand Up @@ -114,6 +115,11 @@ final class RootFilterViewController: FilterViewController {
freeTextFilterViewController?.searchBar.becomeFirstResponder()
focusOnFreeTextFilterOnNextAppearance = false
}

if dismissFiltersOnNextFreeTextSelection {
freeTextFilterViewController?.dismissFiltersOnNextFreeTextSelection = true
dismissFiltersOnNextFreeTextSelection = false
}
}

override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
Expand Down Expand Up @@ -469,7 +475,7 @@ private extension RootFilterViewController {
guard let freeTextFilter = filterContainer.freeTextFilter else { return }

if freeTextFilterViewController == nil {
let freeTextFilterViewController = FreeTextFilterViewController(filter: freeTextFilter, selectionStore: selectionStore)
let freeTextFilterViewController = FreeTextFilterViewController(filter: freeTextFilter, selectionStore: selectionStore, dismissFiltersOnNextFreeTextSelection: dismissFiltersOnNextFreeTextSelection)
self.freeTextFilterViewController = freeTextFilterViewController
freeTextFilterViewController.delegate = self
freeTextFilterViewController.filterDelegate = freeTextFilterDelegate
Expand Down
8 changes: 7 additions & 1 deletion Sources/Charcoal/Models/Filter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public final class Filter {

public enum Kind: Equatable {
case freeText
case freeTextOnly
case standard
case grid
case stepper(config: StepperFilterConfiguration)
Expand Down Expand Up @@ -72,7 +73,12 @@ extension Filter {
let title = title ?? "searchPlaceholder".localized()
return Filter(kind: .freeText, title: title, key: key, value: nil, numberOfResults: 0)
}


public static func freeTextOnly(title: String? = nil, key: String) -> Filter {
let title = title ?? "searchPlaceholder".localized()
return Filter(kind: .freeTextOnly, title: title, key: key, value: nil, numberOfResults: 0)
}

public static func inline(title: String, key: String, subfilters: [Filter]) -> Filter {
return Filter(title: title, key: key, value: nil, numberOfResults: 0, subfilters: subfilters)
}
Expand Down

0 comments on commit deba773

Please sign in to comment.