mirror of
https://github.com/Finb/Bark.git
synced 2025-12-08 21:36:01 +00:00
点击tab按钮时,刷新当前页面
This commit is contained in:
parent
5a23ade436
commit
fd96fb0d09
@ -55,6 +55,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
|
||||
}
|
||||
let tabBarController = StateStorageTabBarController()
|
||||
tabBarController.tabBar.tintColor = UIColor.black
|
||||
|
||||
self.window?.backgroundColor = Color.grey.lighten5
|
||||
self.window?.rootViewController = BarkSnackbarController(
|
||||
rootViewController: tabBarController
|
||||
)
|
||||
|
||||
tabBarController.viewControllers = [
|
||||
BarkNavigationController(rootViewController:HomeViewController(viewModel: HomeViewModel())),
|
||||
BarkNavigationController(rootViewController:MessageListViewController(viewModel: MessageListViewModel())),
|
||||
@ -68,10 +74,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
|
||||
viewController.tabBarItem = tabBarItems[index]
|
||||
}
|
||||
|
||||
self.window?.backgroundColor = Color.grey.lighten5
|
||||
self.window?.rootViewController = BarkSnackbarController(
|
||||
rootViewController: tabBarController
|
||||
)
|
||||
self.window?.makeKeyAndVisible()
|
||||
|
||||
UNUserNotificationCenter.current().delegate = self
|
||||
|
||||
@ -48,7 +48,7 @@ copyParameter = "If the URL has a copy parameter then the value of the copy \npa
|
||||
automaticallyCopyTitle = "Automatically copy push content (No longer available after iOS14.5)";
|
||||
automaticallyCopy = "Automatically copy push content \nwhen a push is received";
|
||||
|
||||
historyMessage = "History Message";
|
||||
historyMessage = "Message History";
|
||||
|
||||
unknown = "Unknown";
|
||||
available = "Available";
|
||||
|
||||
@ -23,6 +23,12 @@ class Client: NSObject {
|
||||
return nav
|
||||
}
|
||||
}
|
||||
var currentTabBarController:StateStorageTabBarController? {
|
||||
get {
|
||||
let controller = UIApplication.shared.delegate?.window??.rootViewController as? BarkSnackbarController
|
||||
return controller?.rootViewController as? StateStorageTabBarController
|
||||
}
|
||||
}
|
||||
|
||||
let appVersion:String = {
|
||||
var version = "0.0.0"
|
||||
|
||||
@ -8,6 +8,8 @@
|
||||
|
||||
import UIKit
|
||||
import Material
|
||||
import RxSwift
|
||||
|
||||
class BarkNavigationController: UINavigationController{
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
@ -21,19 +23,48 @@ class BarkSnackbarController: SnackbarController {
|
||||
}
|
||||
}
|
||||
|
||||
class StateStorageTabBarController: UITabBarController, UITabBarControllerDelegate {
|
||||
enum TabPage: Int {
|
||||
case unknown = -1
|
||||
case service = 0
|
||||
case messageHistory = 1
|
||||
case settings = 2
|
||||
}
|
||||
|
||||
class StateStorageTabBarController: UITabBarController, UITabBarControllerDelegate {
|
||||
|
||||
// 标记当前显示的页面,再次点击相同的页面时当做页面点击事件。
|
||||
var currentSelectedIndex: Int = 0
|
||||
|
||||
// 点击当前页面的 tabBarItem , 可以用以点击刷新当前页面等操作
|
||||
lazy var tabBarItemDidClick: Observable<TabPage> = {
|
||||
return self.rx.didSelect
|
||||
.flatMapLatest { _ -> Single<TabPage> in
|
||||
let single = Single<TabPage>.create { single in
|
||||
if self.currentSelectedIndex == self.selectedIndex {
|
||||
single(.success(TabPage(rawValue: self.selectedIndex) ?? .unknown))
|
||||
}
|
||||
self.currentSelectedIndex = self.selectedIndex
|
||||
return Disposables.create()
|
||||
}
|
||||
return single
|
||||
}
|
||||
}()
|
||||
|
||||
var isFirstAppear = true
|
||||
override func viewWillAppear(_ animated: Bool) {
|
||||
super.viewWillAppear(animated)
|
||||
if self.delegate == nil {
|
||||
if isFirstAppear {
|
||||
isFirstAppear = false
|
||||
|
||||
//开启APP时,默认选择上次打开的页面
|
||||
if let index:Int = Settings[.selectedViewControllerIndex] {
|
||||
self.selectedIndex = index
|
||||
}
|
||||
self.delegate = self
|
||||
//保存打开的页面Index
|
||||
self.rx.didSelect.subscribe(onNext: {_ in
|
||||
Settings[.selectedViewControllerIndex] = self.selectedIndex
|
||||
}).disposed(by: rx.disposeBag)
|
||||
}
|
||||
}
|
||||
|
||||
func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
|
||||
Settings[.selectedViewControllerIndex] = self.selectedIndex
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -55,6 +55,13 @@ class HomeViewController: BaseViewController {
|
||||
make.top.equalTo(150)
|
||||
}
|
||||
|
||||
Client.shared.currentTabBarController?
|
||||
.tabBarItemDidClick
|
||||
.filter{ $0 == .service }
|
||||
.subscribe(onNext: {[weak self] index in
|
||||
self?.tableView.scrollToRow(at: IndexPath(row: 0, section: 0), at: .top, animated: true)
|
||||
}).disposed(by: self.rx.disposeBag)
|
||||
|
||||
}
|
||||
override func bindViewModel() {
|
||||
guard let viewModel = self.viewModel as? HomeViewModel else {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user