mirror of
https://github.com/Finb/Bark.git
synced 2025-12-08 21:36:01 +00:00
兼容 iOS13
This commit is contained in:
parent
c00fe98b8d
commit
c412fc7d0f
@ -78,10 +78,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
|
|||||||
setupRealm()
|
setupRealm()
|
||||||
|
|
||||||
IQKeyboardManager.shared.enable = true
|
IQKeyboardManager.shared.enable = true
|
||||||
if #available(iOS 14, *), UIDevice.current.userInterfaceIdiom == .pad {
|
if UIDevice.current.userInterfaceIdiom == .pad {
|
||||||
let splitViewController = BarkSplitViewController.init(style: .doubleColumn)
|
let splitViewController = BarkSplitViewController()
|
||||||
splitViewController.initViewControllers()
|
splitViewController.initViewControllers()
|
||||||
self.window?.rootViewController = splitViewController;
|
self.window?.rootViewController = BarkSnackbarController(rootViewController: splitViewController)
|
||||||
} else {
|
} else {
|
||||||
let tabBarController = StateStorageTabBarController()
|
let tabBarController = StateStorageTabBarController()
|
||||||
tabBarController.tabBar.tintColor = BKColor.grey.darken4
|
tabBarController.tabBar.tintColor = BKColor.grey.darken4
|
||||||
|
|||||||
@ -18,12 +18,14 @@ class Client: NSObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var currentNavigationController: UINavigationController? {
|
var currentNavigationController: UINavigationController? {
|
||||||
|
// TODO: iPad 取值不对
|
||||||
let controller = UIApplication.shared.delegate?.window??.rootViewController as? BarkSnackbarController
|
let controller = UIApplication.shared.delegate?.window??.rootViewController as? BarkSnackbarController
|
||||||
let nav = (controller?.rootViewController as? UITabBarController)?.selectedViewController as? UINavigationController
|
let nav = (controller?.rootViewController as? UITabBarController)?.selectedViewController as? UINavigationController
|
||||||
return nav
|
return nav
|
||||||
}
|
}
|
||||||
|
|
||||||
var currentTabBarController: StateStorageTabBarController? {
|
var currentTabBarController: StateStorageTabBarController? {
|
||||||
|
// TODO: iPad 取值不对
|
||||||
let controller = UIApplication.shared.delegate?.window??.rootViewController as? BarkSnackbarController
|
let controller = UIApplication.shared.delegate?.window??.rootViewController as? BarkSnackbarController
|
||||||
return controller?.rootViewController as? StateStorageTabBarController
|
return controller?.rootViewController as? StateStorageTabBarController
|
||||||
}
|
}
|
||||||
@ -49,13 +51,12 @@ class Client: NSObject {
|
|||||||
|
|
||||||
func registerForRemoteNotifications() {
|
func registerForRemoteNotifications() {
|
||||||
let center = UNUserNotificationCenter.current()
|
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 {
|
if granted {
|
||||||
dispatch_sync_safely_main_queue {
|
dispatch_sync_safely_main_queue {
|
||||||
UIApplication.shared.registerForRemoteNotifications()
|
UIApplication.shared.registerForRemoteNotifications()
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
print("没有打开推送")
|
print("没有打开推送")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -69,8 +70,7 @@ class Client: NSObject {
|
|||||||
self.currentNavigationController?.present(BarkSFSafariViewController(url: url), animated: true, completion: nil)
|
self.currentNavigationController?.present(BarkSFSafariViewController(url: url), animated: true, completion: nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
UIApplication.shared.open(url, options: [:], completionHandler: nil)
|
UIApplication.shared.open(url, options: [:], completionHandler: nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,63 +6,57 @@
|
|||||||
// Copyright © 2024 Fin. All rights reserved.
|
// Copyright © 2024 Fin. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
import UIKit
|
|
||||||
import Material
|
import Material
|
||||||
|
import UIKit
|
||||||
|
|
||||||
class BarkSplitViewController: UISplitViewController {
|
class BarkSplitViewController: UISplitViewController {
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
// self.displayModeButtonItem.tintColor = BKColor.grey.darken4
|
// 暂时没找到 oneOverSecondary 模式下,怎么显示左侧导航栏按钮
|
||||||
// self.delegate = self
|
// 先强制显示 primary 吧
|
||||||
// Do any additional setup after loading the view.
|
self.preferredDisplayMode = .oneBesideSecondary
|
||||||
|
self.delegate = self
|
||||||
}
|
}
|
||||||
|
|
||||||
func initViewControllers() {
|
let sectionViewController = BarkNavigationController(
|
||||||
if #available(iOS 14, *) {
|
rootViewController: SectionViewController_iPad(viewModel: SectionViewModel())
|
||||||
let sectionViewController = BarkNavigationController(rootViewController: SectionViewController_iPad(viewModel: SectionViewModel()));
|
)
|
||||||
let homeViewController = BarkNavigationController(rootViewController: HomeViewController(viewModel: HomeViewModel()));
|
let homeViewController = BarkNavigationController(
|
||||||
let tabBarController = StateStorageTabBarController()
|
rootViewController: HomeViewController(viewModel: HomeViewModel())
|
||||||
tabBarController.tabBar.tintColor = BKColor.grey.darken4
|
)
|
||||||
|
// Compact 下替换显示成 snackBarController
|
||||||
let snackBarController = BarkSnackbarController(
|
let snackBarController: StateStorageTabBarController = {
|
||||||
rootViewController: tabBarController
|
let tabBarController = StateStorageTabBarController()
|
||||||
)
|
tabBarController.tabBar.tintColor = BKColor.grey.darken4
|
||||||
|
|
||||||
tabBarController.viewControllers = [
|
tabBarController.viewControllers = [
|
||||||
BarkNavigationController(rootViewController: HomeViewController(viewModel: HomeViewModel())),
|
BarkNavigationController(rootViewController: HomeViewController(viewModel: HomeViewModel())),
|
||||||
BarkNavigationController(rootViewController: MessageListViewController(viewModel: MessageListViewModel())),
|
BarkNavigationController(rootViewController: MessageListViewController(viewModel: MessageListViewModel())),
|
||||||
BarkNavigationController(rootViewController: MessageSettingsViewController(viewModel: MessageSettingsViewModel()))
|
BarkNavigationController(rootViewController: MessageSettingsViewController(viewModel: MessageSettingsViewModel()))
|
||||||
]
|
]
|
||||||
|
|
||||||
let tabBarItems = [
|
let tabBarItems = [
|
||||||
UITabBarItem(title: NSLocalizedString("service"), image: UIImage(named: "baseline_gite_black_24pt"), tag: 0),
|
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("historyMessage"), image: Icon.history, tag: 1),
|
||||||
UITabBarItem(title: NSLocalizedString("settings"), image: UIImage(named: "baseline_manage_accounts_black_24pt"), tag: 2)
|
UITabBarItem(title: NSLocalizedString("settings"), image: UIImage(named: "baseline_manage_accounts_black_24pt"), tag: 2)
|
||||||
]
|
]
|
||||||
for (index, viewController) in tabBarController.viewControllers!.enumerated() {
|
for (index, viewController) in tabBarController.viewControllers!.enumerated() {
|
||||||
viewController.tabBarItem = tabBarItems[index]
|
viewController.tabBarItem = tabBarItems[index]
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
self.setViewController(sectionViewController, for: .primary)
|
|
||||||
self.setViewController(homeViewController, for: .secondary)
|
|
||||||
self.setViewController(snackBarController, for: .compact)
|
|
||||||
}
|
}
|
||||||
|
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.
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,13 +14,16 @@ import RxDataSources
|
|||||||
import RxSwift
|
import RxSwift
|
||||||
|
|
||||||
class SectionViewController_iPad: BaseViewController<SectionViewModel>, UITableViewDelegate {
|
class SectionViewController_iPad: BaseViewController<SectionViewModel>, UITableViewDelegate {
|
||||||
|
|
||||||
let tableView: UITableView = {
|
let tableView: UITableView = {
|
||||||
let tableView = UITableView(frame: .zero, style: .grouped)
|
let tableView = UITableView(frame: .zero, style: .grouped)
|
||||||
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "\(UITableViewCell.self)")
|
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "\(UITableViewCell.self)")
|
||||||
tableView.backgroundColor = BKColor.background.primary
|
tableView.backgroundColor = BKColor.background.primary
|
||||||
return tableView
|
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() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
@ -34,6 +37,22 @@ class SectionViewController_iPad: BaseViewController<SectionViewModel>, UITableV
|
|||||||
tableView.snp.makeConstraints { make in
|
tableView.snp.makeConstraints { make in
|
||||||
make.edges.equalToSuperview()
|
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() {
|
override func bindViewModel() {
|
||||||
@ -43,92 +62,18 @@ class SectionViewController_iPad: BaseViewController<SectionViewModel>, UITableV
|
|||||||
guard let cell = tableView.dequeueReusableCell(withIdentifier: "\(UITableViewCell.self)") else {
|
guard let cell = tableView.dequeueReusableCell(withIdentifier: "\(UITableViewCell.self)") else {
|
||||||
return UITableViewCell()
|
return UITableViewCell()
|
||||||
}
|
}
|
||||||
|
|
||||||
if #available(iOS 14, *) {
|
|
||||||
cell.backgroundConfiguration = UIBackgroundConfiguration.listPlainCell()
|
|
||||||
}
|
|
||||||
cell.selectionStyle = .gray
|
cell.selectionStyle = .gray
|
||||||
cell.imageView?.image = item.image
|
cell.imageView?.image = item.image
|
||||||
cell.imageView?.tintColor = BKColor.grey.darken4
|
cell.imageView?.tintColor = BKColor.grey.darken4
|
||||||
cell.textLabel?.text = item.title
|
cell.textLabel?.text = item.title
|
||||||
return cell
|
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
|
output.items
|
||||||
.bind(to: tableView.rx.items(dataSource: dataSource))
|
.bind(to: tableView.rx.items(dataSource: dataSource))
|
||||||
.disposed(by: rx.disposeBag)
|
.disposed(by: rx.disposeBag)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
|
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
|
||||||
return 55
|
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.
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user