BBATabBarController.h 10.4 KB
//
//  BBATabBarController.h
//  BBAPods
//
//  Created by guojin on 16/3/24.
//  Copyright © 2016年 Baidu. All rights reserved.
//
/******************************************************************************/
// 描述: BBATabBarController manages a button bar and transition view, for an application with multiple top-level modes.
//      与UITabBarController不同在于子元素允许非UIViewController对象,Tab中允许自定义View
// 目的:分离业务逻辑与UI Framework逻辑
//      建立容器与子元素间的关系,降低耦合度,避免逻辑堆积在容器实例化处
//      保障UIViewController生命周期方法调用(viewWillAppear:、viewDidAppear等)
/******************************************************************************/
#import <UIKit/UIKit.h>
#import "BBATabBar.h"
#import "BBATabBarItemConfig.h"
/*!
 UITabBarController manages a button bar and transition view, for an application with multiple top-level modes.
 
 To use in your application, add its view to the view hierarchy, then add top-level view controllers in order.
 Most clients will not need to subclass UITabBarController.
 
 If more than five view controllers are added to a tab bar controller, only the first four will display.
 The rest will be accessible under an automatically generated More item.
 
 UITabBarController is rotatable if all of its view controllers are rotatable.
 */
NS_ASSUME_NONNULL_BEGIN
typedef NS_ENUM(NSUInteger, BBATabbarBubbleDestroyedType) {
    BBATabbarBubbledestroyedNone, // 气泡已不存在
    BBATabbarBubbledestroyedDuration, // 时间周期内自动消失
    BBATabbarBubbledestroyedPress, // 点击气泡本身消失
    BBATabbarBubbleDestroyedTypeMutual, //互斥消失
    BBATabbarBubbleDestroyedTypeShowIndexTabClick, //气泡指向的tab被点击消失
};

/// 气泡消失类型
typedef NS_ENUM(NSUInteger, BBATabbarBubbleSizeType) {
    BBABubbleSizeBig, // 标准大小
    BBABubbleSizeSmall, // 小型气泡
};

@interface BBATabBarController : UIViewController//UITabBarController

@property (nullable, nonatomic,copy) NSArray<__kindof NSObject*> *viewControllers;
// If the number of view controllers is greater than the number displayable by a tab bar, a "More" navigation controller will automatically be shown.
// The "More" navigation controller will not be returned by -viewControllers, but it may be returned by -selectedViewController.
//- (void)setViewControllers:(NSArray<__kindof UIViewController *> * __nullable)viewControllers animated:(BOOL)animated;

@property (nullable, nonatomic, assign) __kindof UIViewController *selectedViewController; // This may return the "More" navigation controller if it exists.
@property (nonatomic) NSUInteger selectedIndex;
@property (nonatomic) BOOL displayBadgeDeselected;       //被选中时不显示badge

@property (nullable, nonatomic,strong) UIImage *barBackgroundImage;

@property (nonatomic, copy) void(^didUpdateTabItemData)(UITabBarItem *item);  //更新item(如tabbar AB实验)

@property (nonatomic, copy) void(^viewFirstDidAppear)(void); //启动完成时机控制(back up feed 没有触发完成回掉)

@property(nonatomic, readonly) BBATabBar *tabBar;

/// v11.25.5 新增初始化方法,设置默认选中位
/// @param index 默认选中位
- (instancetype)initWithSelectedIndex:(NSInteger)index;

- (void)setBarTintColor:(UIColor *)color forState:(UIControlState)state;

- (void)setTabClickSound:(NSString*)path;// 设置点击音

- (void)setLoadingItemImage:(UIImage *)image;//设置加载态资源

- (void)showBubbleAtIndex:(NSInteger)index text:(NSString *)text hyperLinkDictionary:(NSDictionary *)hyperLinkDictionary showSucessBlock:(void (^)(void))sucessBlock bubbleDestroyedBlock:(void (^)(void))destroyedBlock;//在指定位置弹出指定文字的气泡
- (void)showBubbleAtIndex:(NSInteger)index text:(NSString *)text hyperLinkDictionary:(NSDictionary *)hyperLinkDictionary showSucessBlock:(void (^)(void))sucessBlock bubbleDestroyedType:(void (^)(BBATabbarBubbleDestroyedType dismissType))destroyedBlock;//在指定位置弹出指定文字的气泡,返回气泡被销毁的类型

- (void)showBubbleAtIndex:(NSInteger)index
                  yOffset:(CGFloat)yOffset
                 duration:(CGFloat)duration
                     text:(nonnull NSString *)text
          backgroundColor:(nullable UIColor *)backgroundColor
      hyperLinkDictionary:(nullable NSDictionary *)hyperLinkDictionary
          showSucessBlock:(nullable void (^)(void))sucessBlock
      bubbleDestroyedType:(nullable void (^)(BBATabbarBubbleDestroyedType dismissType))destroyedBlock;

/// 在指定位置展示气泡
/// @param index 显示位置
/// @param duration 显示时间
/// @param text 气泡文本
/// @param backgroundColor 气泡背景色
/// @param hyperLinkDictionary 超链点击回调block(key:NSRange, value: block)
/// @param bubbleSizeType   展示气泡尺寸
/// @param sucessBlock 展示成功回调
/// @param destroyedBlock 销毁成功回调
- (void)showBubbleAtIndex:(NSInteger)index
                  yOffset:(CGFloat)yOffset
                 duration:(CGFloat)duration
                     text:(nonnull NSString *)text
          backgroundColor:(nullable UIColor *)backgroundColor
      hyperLinkDictionary:(nullable NSDictionary *)hyperLinkDictionary
           bubbleSizeType:(BBATabbarBubbleSizeType)bubbleSizeType
          showSucessBlock:(nullable void (^)(void))sucessBlock
      bubbleDestroyedType:(nullable void (^)(BBATabbarBubbleDestroyedType dismissType))destroyedBlock;

/// 更新气泡背景色
/// @param backgroundColor 背景色
- (void)updateBubbleBackgroundColor:(UIColor *)backgroundColor;

/// 气泡是否存在
- (BOOL)tabBubbleIsExist;

/// 隐藏气泡
- (void)hideTabBubble;

/// 获取气泡销毁l类型
- (BBATabbarBubbleDestroyedType)getBubbleDestoryedType;

/// 展示运营位置视图,左右与指定tab居中
/// @param index 指定展示的tab
/// @param yOffset y方向位置
/// @param operationView 要展示的运营视图
- (void)showOperationAtIndex:(NSInteger)index
                     yOffset:(CGFloat)yOffset
               operationView:(UIView *)operationView;

/// 运营位置视图消失
- (void)hideTabbarOprationView;

- (void)setTabBarHidden:(BOOL)hidden animated:(BOOL)animated;

- (void)updateTabBar;//设置完TabBarItem标题、图片、字体颜色后执行刷新

/// 重建tabbar,仅为启动快速调起提供使用
- (void)reconstructTabbarOnlyForLaunchWithDefaltIndex:(NSInteger)index;
/**
 *  @brief 根据identify更新tabbar
 
 *  @param identify tab注册的ID
 */
- (void)updateTabBarWithID:(NSString *)identify;

- (void)insertViewBelowTabBar:(UIView *)view;

@end


//建立容器控制器与子控制器/子视图组件(部分组件没有VC)的联系,容器里并非所有的元素都是ViewController;因此此处定义NSObject的类别,允许所有元素
typedef void(^BBATabBarItemClick)(void);
typedef BOOL(^BBATabBarItemShouldClick)(void);
@interface NSObject (BBATabBarControllerItem)
@property (null_resettable, nonatomic, strong) UITabBarItem *bbaTabBarItem; // Automatically created lazily with the view controller's title if it's not set explicitly.只有TabBarItem显示必须的数据,没有视图

@property (nullable, nonatomic, readonly, strong) BBATabBarController *bbaTabBarController; // If the view controller has a tab bar controller as its ancestor, return it. Returns nil otherwise.

@property (nonatomic, copy) BBATabBarItemClick bbaBarItemClick;
@property (nonatomic, copy) BBATabBarItemClick bbaBarItemReqpeatClick;
@property (nonatomic, copy) BBATabBarItemClick bbaBarItemDeselect;

- (UITabBarItem *_Nonnull)bbaTabBarItem:(nullable NSString*)title image:(nullable UIImage *)image selectedImage:(nullable UIImage *)selectedImage;
- (void)registerIdenfityForTabBarItem:(NSString *)identify;
@end


typedef UIViewController * _Nonnull (^BBATabBarRedirect)(void);
@interface UITabBarItem (BBATabBarItemProperty)
@property (nonatomic, assign) CGFloat bbaWidthRatio;            //与标准BarItem的宽度比;左右边距空白 //TODO: liuchengqing 待废弃
@property (nonatomic, strong, nullable) UIView *bbaCustomView;  //如果存在CustomView,则高亮及点击事件都有CustomView处理
@property (nonatomic, assign) CGSize bbaCustomResponseSize;     //自定义frame 响应区域
@property (nonatomic, assign) CGSize bbaCustomIconSize;         //自定义icon size,对齐icon布局使用,保证icon间等间隔
@property (nonatomic, copy, nullable) NSString *bbaBadgeValue;  //飘文字 如bbaBadgeValue > bbaBadgeNumber > bbaBadgeDot
@property (nonatomic, assign) NSInteger bbaBadgeNumber;         //飘数字
@property (nonatomic, assign) BOOL bbaBadgeDot;                 //飘点
@property (nonatomic, assign) BOOL bbaBadgeSilent;              //静音模式 不展示bbaBadgeValue / bbaBadgeNumber / bbaBadgeDot
@property (nonatomic, readonly) CGRect bbaFrame;                //VC对应TabFrame
@property (nonatomic, assign) BOOL bbaSkipSeletedAnimation;     //跳过选中动画 默认: NO
@property (nonatomic, assign) BOOL bbaLoading;                  //加载中 默认: NO
@property (nonatomic, assign) BOOL bbaHighlightEnable;          //可否高亮 默认: NO
@property (nonatomic, assign) BOOL bbaDisableStatistics;        //是否禁用数据统计 默认: NO
@property (nonatomic, copy, nonnull) NSString *bbaIdentify;              //VC对应ID
@property (nonatomic, copy, nullable) BOOL(^bbaShouldSelected)(void);     //TabBar更新Item, 是否展示title
@property (nonatomic, copy, nullable) void(^bbaBarItemShouldUdpdate)(BOOL showTitle);  //TabBar更新Item, 是否展示title
@property (nonatomic, copy, nullable) BBATabBarRedirect bbaBarItemRedirectBlock;       //重定向Tab VC
/// barItem 常态文字颜色,nil 使用默认、(暂运营皮肤使用)
@property (nonatomic, strong, nullable) UIColor *bbaTextNormalColor;
/// barItem 选中态文字颜色,nil 使用默认、(暂运营皮肤使用)
@property (nonatomic, strong, nullable) UIColor *bbaTextSelectedColor;
/// barItem 高亮态文字颜色,nil 使用默认、(暂运营皮肤使用)
@property (nonatomic, strong, nullable) UIColor *bbaTextHighlightColor;
/// 在TabBar上展示的view,只读属性,外部无需设置
@property (nonatomic, weak) UIView *bbaItemView;

@end

//TODO: liuchengqing 待废弃
@interface UIViewController (BBALazyLoadViewController)
typedef UIViewController* _Nullable (^BBALasyLoadController)(void);
@property (nullable, nonatomic, strong)BBALasyLoadController bbaLazyLoadBlock;
@end
NS_ASSUME_NONNULL_END