Procházet zdrojové kódy

added TabBarRestorer to store and restore last active tabs in user defaults

nayooti před 5 roky
rodič
revize
f2ae5d2674
1 změnil soubory, kde provedl 16 přidání a 0 odebrání
  1. 16 0
      deltachat-ios/Handler/TabBarRestorer.swift

+ 16 - 0
deltachat-ios/Handler/TabBarRestorer.swift

@@ -0,0 +1,16 @@
+import UIKit
+
+class TabBarRestorer: NSObject, UITabBarControllerDelegate {
+
+    private let userDefaultKey = "last_active_tab"
+
+    func restoreLastActiveTab() -> Int {
+        return UserDefaults.standard.integer(forKey: userDefaultKey)
+    }
+
+    func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
+        let activeTab = tabBarController.selectedIndex
+        UserDefaults.standard.set(activeTab, forKey: userDefaultKey)
+        UserDefaults.standard.synchronize()
+    }
+}