RQBaseViewModel.h 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //
  2. // RQBaseViewModel.h
  3. // RQCommon
  4. //
  5. // Created by 张嵘 on 2018/11/13.
  6. // Copyright © 2018 张嵘. All rights reserved.
  7. // 所有自定义的视图模型的基类
  8. #import <Foundation/Foundation.h>
  9. #import "RQMacros.h"
  10. /// MVVM View
  11. /// The base map of 'params'
  12. /// The `params` parameter in `-initWithParams:` method.
  13. /// Key-Values's key
  14. /// 传递唯一ID的key:例如:商品id 用户id...
  15. FOUNDATION_EXTERN NSString *const RQViewModelIDKey;
  16. /// 传递导航栏title的key:例如 导航栏的title...
  17. FOUNDATION_EXTERN NSString *const RQViewModelTitleKey;
  18. /// 传递数据模型的key:例如 商品模型的传递 用户模型的传递...
  19. FOUNDATION_EXTERN NSString *const RQViewModelUtilKey;
  20. /// 传递webView Request的key:例如 webView request...
  21. FOUNDATION_EXTERN NSString *const RQViewModelRequestKey;
  22. /// 传递数据的key
  23. FOUNDATION_EXTERN NSString *const RQViewCommonValueKey;
  24. @protocol RQViewModelServices;
  25. @class RACSubject;
  26. @interface RQBaseViewModel : NSObject
  27. /// Initialization method. This is the preferred way to create a new view model.
  28. ///
  29. /// services - The service bus of the `Model` layer.
  30. /// params - The parameters to be passed to view model.
  31. ///
  32. /// Returns a new view model.
  33. - (instancetype)initWithServices:(id<RQViewModelServices>)services params:(NSDictionary *)params;
  34. /// The `services` parameter in `-initWithServices:params:` method.
  35. @property (nonatomic, readonly, strong) id<RQViewModelServices> services;
  36. /// The `params` parameter in `-initWithParams:` method.
  37. /// The `params` Key's `kBaseViewModelParamsKey`
  38. @property (nonatomic, readonly, copy) NSDictionary *params;
  39. /// navItem.title
  40. @property (nonatomic, readwrite, copy) NSString *title;
  41. /// 返回按钮的title,default is nil 。
  42. /// 如果设置了该值,那么当Push到一个新的控制器,则导航栏左侧返回按钮的title为backTitle
  43. @property (nonatomic, readwrite, copy) NSString *backTitle;
  44. /// The callback block. 当Push/Present时,通过block反向传值
  45. @property (nonatomic, readwrite, copy) VoidBlock_id callback;
  46. /// A RACSubject object, which representing all errors occurred in view model.
  47. @property (nonatomic, readonly, strong) RACSubject *errors;
  48. /** should fetch local data when viewModel init . default is YES */
  49. @property (nonatomic, readwrite, assign) BOOL shouldFetchLocalDataOnViewModelInitialize;
  50. /** should request data when viewController videwDidLoad . default is YES*/
  51. /** 是否需要在控制器viewDidLoad */
  52. @property (nonatomic, readwrite, assign) BOOL shouldRequestRemoteDataOnViewDidLoad;
  53. /// will disappear signal
  54. @property (nonatomic, strong, readonly) RACSubject *willDisappearSignal;
  55. /// FDFullscreenPopGesture
  56. /// Whether the interactive pop gesture is disabled when contained in a navigation
  57. /// stack. (是否取消掉左滑pop到上一层的功能(栈底控制器无效),默认为NO,不取消)
  58. @property (nonatomic, readwrite, assign) BOOL interactivePopDisabled;
  59. /// Indicate this view controller prefers its navigation bar hidden or not,
  60. /// checked when view controller based navigation bar's appearance is enabled.
  61. /// Default to NO, bars are more likely to show.
  62. /// 是否隐藏该控制器的导航栏 默认是不隐藏 (NO)
  63. @property (nonatomic, readwrite, assign) BOOL prefersNavigationBarHidden;
  64. /// 是否隐藏该控制器的导航栏底部的分割线 默认不隐藏 (NO)
  65. @property (nonatomic, readwrite, assign) BOOL prefersNavigationBarBottomLineHidden;
  66. /// IQKeyboardManager
  67. /// 是否让IQKeyboardManager的管理键盘的事件 默认是YES(键盘管理)
  68. @property (nonatomic, readwrite, assign) BOOL keyboardEnable;
  69. /// 是否键盘弹起的时候,点击其他局域键盘弹起 默认是 YES
  70. @property (nonatomic, readwrite, assign) BOOL shouldResignOnTouchOutside;
  71. /// To set keyboard distance from textField. can't be less than zero. Default is 10.0.
  72. /// keyboardDistanceFromTextField
  73. @property (nonatomic, readwrite, assign) CGFloat keyboardDistanceFromTextField;
  74. /// An additional method, in which you can initialize data, RACCommand etc.
  75. ///
  76. /// This method will be execute after the execution of `-initWithParams:` method. But
  77. /// the premise is that you need to inherit `BaseViewModel`.
  78. - (void)initialize;
  79. @end