Files
Folo/apps/mobile/native/ios/Modules/TabBar/TabBarBottomAccessoryModule.swift
Innei 87ea8b7a20 feat(tabbar): add TabBarBottomAccessoryModule and enhance TabBarRootView
- Introduced `TabBarBottomAccessoryModule` to provide a new bottom accessory view for the tab bar.
- Updated `TabBarRootView` to utilize a custom tab bar controller, improving the management of the tab bar's visibility and behavior.
- Refactored `UIWindow` extension methods for better readability and structure.
- Enhanced `expo-module.config.json` to include the new module and improved formatting for better clarity.

These changes aim to enhance the tab bar functionality and improve the overall user interface experience in the mobile application.

Signed-off-by: Innei <tukon479@gmail.com>
2025-09-25 23:06:51 +08:00

74 lines
1.5 KiB
Swift

//
// TabBarBottomAccessoryModule.swift
// FollowNative
//
// Created by Innei on 2025-09-25
//
import ExpoModulesCore
import UIKit
public class TabBarBottomAccessoryModule: Module {
public func definition() -> ModuleDefinition {
Name("TabBarBottomAccessory")
View(TabBarBottomAccessoryView.self) {
}
}
}
class TabBarBottomAccessoryView: ExpoView {
private weak var attachedRoot: TabBarRootView?
required init(appContext: AppContext? = nil) {
super.init(appContext: appContext)
}
deinit {
detachFromRoot()
}
override func didMoveToWindow() {
super.didMoveToWindow()
attachToNearestTabBarRoot()
}
override func willMove(toWindow newWindow: UIWindow?) {
if newWindow == nil {
detachFromRoot()
}
super.willMove(toWindow: newWindow)
}
#if RCT_NEW_ARCH_ENABLED
override func mountChildComponentView(_ childComponentView: UIView, index: Int) {
attachToNearestTabBarRoot()
}
override func unmountChildComponentView(_ childComponentView: UIView, index: Int) {
detachFromRoot()
}
#endif
func attachToNearestTabBarRoot() {
if #available(iOS 26, *) {
guard window != nil else { return }
CustomTabbarController.tabBarController.bottomAccessory = .init(contentView: self)
}
}
func detachFromRoot() {
if #available(iOS 26, *) {
guard window != nil else { return }
CustomTabbarController.tabBarController.bottomAccessory = nil
}
}
}