兼容 iOS13

This commit is contained in:
Fin 2024-08-19 16:07:25 +08:00 committed by Feng
parent c00fe98b8d
commit c412fc7d0f
4 changed files with 73 additions and 134 deletions

View File

@ -78,10 +78,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
setupRealm()
IQKeyboardManager.shared.enable = true
if #available(iOS 14, *), UIDevice.current.userInterfaceIdiom == .pad {
let splitViewController = BarkSplitViewController.init(style: .doubleColumn)
if UIDevice.current.userInterfaceIdiom == .pad {
let splitViewController = BarkSplitViewController()
splitViewController.initViewControllers()
self.window?.rootViewController = splitViewController;
self.window?.rootViewController = BarkSnackbarController(rootViewController: splitViewController)
} else {
let tabBarController = StateStorageTabBarController()
tabBarController.tabBar.tintColor = BKColor.grey.darken4

View File

@ -18,12 +18,14 @@ class Client: NSObject {
}
var currentNavigationController: UINavigationController? {
// TODO: iPad
let controller = UIApplication.shared.delegate?.window??.rootViewController as? BarkSnackbarController
let nav = (controller?.rootViewController as? UITabBarController)?.selectedViewController as? UINavigationController
return nav
}
var currentTabBarController: StateStorageTabBarController? {
// TODO: iPad
let controller = UIApplication.shared.delegate?.window??.rootViewController as? BarkSnackbarController
return controller?.rootViewController as? StateStorageTabBarController
}
@ -49,13 +51,12 @@ class Client: NSObject {
func registerForRemoteNotifications() {
let center = UNUserNotificationCenter.current()
center.requestAuthorization(options: [.alert, .sound, .badge], completionHandler: { (_ granted: Bool, _: Error?) -> Void in
center.requestAuthorization(options: [.alert, .sound, .badge], completionHandler: { (_ granted: Bool, _: Error?) in
if granted {
dispatch_sync_safely_main_queue {
UIApplication.shared.registerForRemoteNotifications()
}
}
else {
} else {
print("没有打开推送")
}
})
@ -69,8 +70,7 @@ class Client: NSObject {
self.currentNavigationController?.present(BarkSFSafariViewController(url: url), animated: true, completion: nil)
}
}
}
else {
} else {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
}

View File

@ -6,63 +6,57 @@
// Copyright © 2024 Fin. All rights reserved.
//
import UIKit
import Material
import UIKit
class BarkSplitViewController: UISplitViewController {
override func viewDidLoad() {
super.viewDidLoad()
// self.displayModeButtonItem.tintColor = BKColor.grey.darken4
// self.delegate = self
// Do any additional setup after loading the view.
// oneOverSecondary
// primary
self.preferredDisplayMode = .oneBesideSecondary
self.delegate = self
}
func initViewControllers() {
if #available(iOS 14, *) {
let sectionViewController = BarkNavigationController(rootViewController: SectionViewController_iPad(viewModel: SectionViewModel()));
let homeViewController = BarkNavigationController(rootViewController: HomeViewController(viewModel: HomeViewModel()));
let tabBarController = StateStorageTabBarController()
tabBarController.tabBar.tintColor = BKColor.grey.darken4
let snackBarController = BarkSnackbarController(
rootViewController: tabBarController
)
tabBarController.viewControllers = [
BarkNavigationController(rootViewController: HomeViewController(viewModel: HomeViewModel())),
BarkNavigationController(rootViewController: MessageListViewController(viewModel: MessageListViewModel())),
BarkNavigationController(rootViewController: MessageSettingsViewController(viewModel: MessageSettingsViewModel()))
]
let tabBarItems = [
UITabBarItem(title: NSLocalizedString("service"), image: UIImage(named: "baseline_gite_black_24pt"), tag: 0),
UITabBarItem(title: NSLocalizedString("historyMessage"), image: Icon.history, tag: 1),
UITabBarItem(title: NSLocalizedString("settings"), image: UIImage(named: "baseline_manage_accounts_black_24pt"), tag: 2)
]
for (index, viewController) in tabBarController.viewControllers!.enumerated() {
viewController.tabBarItem = tabBarItems[index]
}
self.setViewController(sectionViewController, for: .primary)
self.setViewController(homeViewController, for: .secondary)
self.setViewController(snackBarController, for: .compact)
let sectionViewController = BarkNavigationController(
rootViewController: SectionViewController_iPad(viewModel: SectionViewModel())
)
let homeViewController = BarkNavigationController(
rootViewController: HomeViewController(viewModel: HomeViewModel())
)
// Compact snackBarController
let snackBarController: StateStorageTabBarController = {
let tabBarController = StateStorageTabBarController()
tabBarController.tabBar.tintColor = BKColor.grey.darken4
tabBarController.viewControllers = [
BarkNavigationController(rootViewController: HomeViewController(viewModel: HomeViewModel())),
BarkNavigationController(rootViewController: MessageListViewController(viewModel: MessageListViewModel())),
BarkNavigationController(rootViewController: MessageSettingsViewController(viewModel: MessageSettingsViewModel()))
]
let tabBarItems = [
UITabBarItem(title: NSLocalizedString("service"), image: UIImage(named: "baseline_gite_black_24pt"), tag: 0),
UITabBarItem(title: NSLocalizedString("historyMessage"), image: Icon.history, tag: 1),
UITabBarItem(title: NSLocalizedString("settings"), image: UIImage(named: "baseline_manage_accounts_black_24pt"), tag: 2)
]
for (index, viewController) in tabBarController.viewControllers!.enumerated() {
viewController.tabBarItem = tabBarItems[index]
}
return tabBarController
}()
func initViewControllers() {
self.viewControllers = [sectionViewController, homeViewController]
}
}
extension BarkSplitViewController: UISplitViewControllerDelegate {
func primaryViewController(forExpanding splitViewController: UISplitViewController) -> UIViewController? {
sectionViewController
}
func primaryViewController(forCollapsing splitViewController: UISplitViewController) -> UIViewController? {
snackBarController
}
// func splitViewController(_ splitViewController: UISplitViewController, collapseSecondary secondaryViewController: UIViewController, onto primaryViewController: UIViewController) -> Bool {
// return true
// }
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
}
*/
}

View File

@ -14,13 +14,16 @@ import RxDataSources
import RxSwift
class SectionViewController_iPad: BaseViewController<SectionViewModel>, UITableViewDelegate {
let tableView: UITableView = {
let tableView = UITableView(frame: .zero, style: .grouped)
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "\(UITableViewCell.self)")
tableView.backgroundColor = BKColor.background.primary
return tableView
}()
let homeController = BarkNavigationController(rootViewController: HomeViewController(viewModel: HomeViewModel()))
let messageListController = BarkNavigationController(rootViewController: MessageListViewController(viewModel: MessageListViewModel()))
let settingsController = BarkNavigationController(rootViewController: MessageSettingsViewController(viewModel: MessageSettingsViewModel()))
override func viewDidLoad() {
super.viewDidLoad()
@ -34,6 +37,22 @@ class SectionViewController_iPad: BaseViewController<SectionViewModel>, UITableV
tableView.snp.makeConstraints { make in
make.edges.equalToSuperview()
}
tableView.rx
.itemSelected
.flatMapLatest { indexPath -> Observable<IndexPath> in
return Observable.just(indexPath)
}
.subscribe { [weak self] indexPath in
guard let self, indexPath.row < 3 else {
return
}
self.splitViewController?.showDetailViewController([
self.homeController,
self.messageListController,
self.settingsController
][indexPath.row], sender: self)
}.disposed(by: rx.disposeBag)
}
override func bindViewModel() {
@ -43,92 +62,18 @@ class SectionViewController_iPad: BaseViewController<SectionViewModel>, UITableV
guard let cell = tableView.dequeueReusableCell(withIdentifier: "\(UITableViewCell.self)") else {
return UITableViewCell()
}
if #available(iOS 14, *) {
cell.backgroundConfiguration = UIBackgroundConfiguration.listPlainCell()
}
cell.selectionStyle = .gray
cell.imageView?.image = item.image
cell.imageView?.tintColor = BKColor.grey.darken4
cell.textLabel?.text = item.title
return cell
}
tableView.rx
.itemSelected
.flatMapLatest { indexPath -> Observable<IndexPath> in
return Observable.just(indexPath)
}
.subscribe { indexPath in
if #available(iOS 14, *) {
if indexPath.row == 0 {
self.splitViewController?.setViewController(
BarkNavigationController(rootViewController: HomeViewController(viewModel: HomeViewModel())), for: .secondary)
} else if indexPath.row == 1 {
self.splitViewController?.setViewController(
BarkNavigationController(rootViewController: MessageListViewController(viewModel: MessageListViewModel())), for: .secondary)
} else if (indexPath.row == 2) {
self.splitViewController?.setViewController(
BarkNavigationController(rootViewController: MessageSettingsViewController(viewModel: MessageSettingsViewModel())), for: .secondary)
}
} else {
//
}
}.disposed(by: rx.disposeBag)
output.items
.bind(to: tableView.rx.items(dataSource: dataSource))
.disposed(by: rx.disposeBag)
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 55
}
/*
// Override to support conditional editing of the table view.
override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
// Return false if you do not want the specified item to be editable.
return true
}
*/
/*
// Override to support editing the table view.
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
// Delete the row from the data source
tableView.deleteRows(at: [indexPath], with: .fade)
} else if editingStyle == .insert {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
*/
/*
// Override to support rearranging the table view.
override func tableView(_ tableView: UITableView, moveRowAt fromIndexPath: IndexPath, to: IndexPath) {
}
*/
/*
// Override to support conditional rearranging of the table view.
override func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
// Return false if you do not want the item to be re-orderable.
return true
}
*/
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
}
*/
}