Skip to content

Commit

Permalink
Replace FTPopOverMenu_Swift with Apple native implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
dogo committed Nov 15, 2024
1 parent 0666e50 commit b1fe936
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,14 @@ final class UserCollectionPresenter: UserCollectionPresenterProtocol {
private let dispatchQueue: DispatchQueueType
private let database: DatabaseProtocol?
private let navigator: UserCollectionNavigator
private let manager: PopoverMenuManagerType
private var currentSortIndex = 0

init(controller: UserCollectionViewControllerProtocol,
dispatchQueue: DispatchQueueType = DispatchQueue.main,
manager: PopoverMenuManagerType = PopoverMenuManager(),
database: DatabaseProtocol?,
navigator: UserCollectionNavigator) {
self.controller = controller
self.dispatchQueue = dispatchQueue
self.manager = manager
self.database = database
self.navigator = navigator
}
Expand All @@ -43,11 +40,39 @@ final class UserCollectionPresenter: UserCollectionPresenterProtocol {
}

func setupNavigationItems(completion: ([UIBarButtonItem]?, [UIBarButtonItem]?) -> Void) {
let shareBarItem = UIBarButtonItem(barButtonSystemItem: .action, target: self, action: #selector(share(_:)))
let addCardBarItem = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(navigateToAddCard))
let shareAction = UIAction { [weak self] action in
if let barButtonItem = action.sender as? UIBarButtonItem {
self?.share(barButtonItem)
}
}

let shareBarItem = UIBarButtonItem(systemItem: .action, primaryAction: shareAction)

let addCardAction = UIAction { [weak self] _ in
self?.navigateToAddCard()
}

let addCardBarItem = UIBarButtonItem(systemItem: .add, primaryAction: addCardAction)

let rightBarButtonItems = [addCardBarItem, shareBarItem]
let leftBarButtonItem = UIBarButtonItem(image: Asset.NavigationBar.icSort.image, style: .plain, target: self, action: #selector(sort(_:event:)))

let sortAZAction = UIAction(title: L10n.aToZ) { [weak self] _ in
self?.controller?.sort(0)
self?.currentSortIndex = 0
}

let sortCardNumberAction = UIAction(title: L10n.cardNumber) { [weak self] _ in
self?.controller?.sort(1)
self?.currentSortIndex = 1
}

let sortColorAction = UIAction(title: L10n.color) { [weak self] _ in
self?.controller?.sort(2)
self?.currentSortIndex = 2
}

let sortMenu = UIMenu(children: [sortAZAction, sortCardNumberAction, sortColorAction])
let leftBarButtonItem = UIBarButtonItem(image: Asset.NavigationBar.icSort.image, menu: sortMenu)

completion([leftBarButtonItem], rightBarButtonItems)
}
Expand All @@ -62,7 +87,6 @@ final class UserCollectionPresenter: UserCollectionPresenterProtocol {
navigator.navigate(to: .cardDetail(database: database, with: cardList, card: card))
}

@objc
func navigateToAddCard() {
navigator.navigate(to: .addCard(database: database, with: getUserCollection()))
}
Expand All @@ -83,7 +107,6 @@ final class UserCollectionPresenter: UserCollectionPresenterProtocol {
return user
}

@objc
private func share(_ sender: UIBarButtonItem) {
var collectionList = ""

Expand Down Expand Up @@ -114,16 +137,6 @@ final class UserCollectionPresenter: UserCollectionPresenterProtocol {
}
}
}

@objc
private func sort(_ sender: UIBarButtonItem, event: UIEvent) {
manager.showPopoverMenu(forEvent: event,
with: [L10n.aToZ, L10n.cardNumber, L10n.color],
done: { [weak self] selectedIndex in
self?.controller?.sort(selectedIndex)
self?.currentSortIndex = selectedIndex
}, cancel: {})
}
}

extension UserCollectionPresenter: UserCollectionProtocol {
Expand Down
41 changes: 0 additions & 41 deletions SWDestinyTrades/Classes/Utils/PopoverMenuManager.swift

This file was deleted.

31 changes: 0 additions & 31 deletions SWDestinyTradesTests/Doubles/PopoverMenuManagerSpy.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,15 @@ final class UserCollectionPresenterTests: XCTestCase {
private var controller: UserCollectionViewControllerSpy!
private var navigator: UserCollectionNavigator!
private var database: RealmDatabase?
private var manager: PopoverMenuManagerSpy!

override func setUp() {
super.setUp()
controller = UserCollectionViewControllerSpy()
navigationController = UINavigationControllerMock(rootViewController: controller)
database = RealmDatabaseHelper.createMemoryDatabase(identifier: #function)
manager = PopoverMenuManagerSpy()
navigator = UserCollectionNavigator(controller)
sut = UserCollectionPresenter(controller: controller,
dispatchQueue: DispatchQueueSpy(),
manager: manager,
database: database,
navigator: navigator)
}
Expand Down Expand Up @@ -74,20 +71,18 @@ final class UserCollectionPresenterTests: XCTestCase {
let sortButton = barButtonItems?.0?[0]
_ = sortButton?.target?.perform(sortButton!.action, with: nil)

XCTAssertEqual(manager.didCallShowPopoverMenuCount, 1)
// XCTAssertEqual(manager.didCallShowPopoverMenuCount, 1)
}

func test_sort_selecting_item() {
manager.executeDoneBlock = true

var barButtonItems: ([UIBarButtonItem]?, [UIBarButtonItem]?)?
sut.setupNavigationItems { leftItems, rightItems in
barButtonItems = (leftItems, rightItems)
}
let sortButton = barButtonItems?.0?[0]
_ = sortButton?.target?.perform(sortButton!.action, with: nil)

XCTAssertEqual(manager.didCallShowPopoverMenuCount, 1)
// XCTAssertEqual(manager.didCallShowPopoverMenuCount, 1)
XCTAssertEqual(controller.didCallSort.count, 1)
XCTAssertEqual(controller.didCallSort[0], 0)
}
Expand Down Expand Up @@ -195,11 +190,9 @@ final class UserCollectionPresenterTests: XCTestCase {
controller = UserCollectionViewControllerSpy()
navigationController = UINavigationControllerMock(rootViewController: controller)
database = RealmDatabaseHelper.createMemoryDatabase(identifier: databaseName)
manager = PopoverMenuManagerSpy()
navigator = UserCollectionNavigator(controller)
sut = UserCollectionPresenter(controller: controller,
dispatchQueue: DispatchQueueSpy(),
manager: manager,
database: database,
navigator: navigator)
}
Expand Down
9 changes: 0 additions & 9 deletions Tuist/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,6 @@
"version" : "11.1.0"
}
},
{
"identity" : "ftpopovermenu_swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/liufengting/FTPopOverMenu_Swift",
"state" : {
"revision" : "3ace7adc009b39ad0cc9dd5e1df256264828d115",
"version" : "0.4.5"
}
},
{
"identity" : "googleappmeasurement",
"kind" : "remoteSourceControl",
Expand Down
1 change: 0 additions & 1 deletion Tuist/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ let package = Package(
.package(url: "https://github.com/danielgindi/Charts", from: "5.0.0"),
.package(url: "https://github.com/onevcat/Kingfisher", from: "5.15.8"),
.package(url: "https://github.com/dogo/PKHUD", branch: "fix/spm-resource"),
.package(url: "https://github.com/liufengting/FTPopOverMenu_Swift", from: "0.4.5"),
.package(url: "https://github.com/zvonicek/ImageSlideshow", from: "1.9.1"),
.package(url: "https://github.com/firebase/firebase-ios-sdk", from: "11.1.0"),
.package(url: "https://github.com/SwiftKickMobile/SwiftMessages", from: "10.0.0-beta"),
Expand Down
1 change: 0 additions & 1 deletion Tuist/ProjectDescriptionHelpers/Target.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public extension Project {
.external(name: "DGCharts"),
.external(name: "FirebaseAnalytics"),
.external(name: "FirebaseCrashlytics"),
.external(name: "FTPopOverMenu"),
.external(name: "ImageSlideshow"),
.external(name: "Kingfisher"),
.external(name: "PKHUD"),
Expand Down

0 comments on commit b1fe936

Please sign in to comment.