Skip to content

Commit 4589c4e

Browse files
author
Larry Tin
committed
增加部分注释
1 parent 18ef563 commit 4589c4e

9 files changed

Lines changed: 47 additions & 24 deletions

File tree

GDDataDrivenView.podspec

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ TODO: Add long description of the pod here.
5252
s.subspec 'ViewControllerPresenter' do |sp|
5353
sp.dependency 'GDDataDrivenView/MVP'
5454
sp.dependency 'GDDataDrivenView/Generated'
55-
sp.dependency 'GDChannel', '~> 0.6'
5655
sp.dependency 'Aspects', '~> 1.4.1'
5756

5857
sp.source_files = 'GDDataDrivenView/Classes/ViewControllerPresenter/**/*'

GDDataDrivenView/Classes/MVP/GDDPresenter.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,22 @@
22
// Created by Larry Tin on 16/9/20.
33
//
44

5-
#import <Foundation/Foundation.h>
5+
#import <UIKit/UIKit.h>
66
@protocol GDDView;
77

88
@protocol GDDPresenter
99

10-
- (void)update:(id <GDDView>)view withData:(id)data;
10+
/**
11+
* @param viewController viewDidLoad 这时已被调用
12+
* @param data
13+
*/
14+
- (void)update:(UIViewController<GDDView> *)viewController withData:(id)data;
1115

1216
@optional
1317
/**
14-
* @param owner 使用弱引用持有, 否则将导致循环引用
15-
* @return
18+
* 必须在 UIViewController 的 init 初始化阶段创建 Presenter
19+
* @param owner 使用弱引用持有 owner, 否则将导致循环引用
1620
*/
1721
- (instancetype)initWithOwner:(id)owner;
1822

19-
@end
23+
@end

GDDataDrivenView/Classes/MVP/GDDView.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
* @return 当不实现该方法时, 默认根据类名约定查找并复用之前已创建的 Presenter 实例, 若不存在则创建新的实例并缓存
1313
*
1414
* XyzViewController -> XyzPresenter
15-
* AbcRender -> AbcPresenter
1615
*
1716
*/
1817
- (id <GDDPresenter>)presenter;

GDDataDrivenView/Classes/MVP/GDDViewPresenter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
@protocol GDDViewPresenter <GDDPresenter>
99

10-
- (void)update:(id)view withData:(id)data;
10+
- (void)update:(UIView<GDDView> *)view withData:(id)data;
1111

1212
@optional
1313
- (UIView *) view;

GDDataDrivenView/Classes/RenderPresenter/GDDRender.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,17 @@
44

55
#import <Foundation/Foundation.h>
66
#import "GDDView.h"
7+
#import "GDDRenderPresenter.h"
78

89
@protocol GDDRender <GDDView>
910

11+
@optional
12+
/**
13+
* @return 当不实现该方法时, 默认根据类名约定查找并复用之前已创建的 RenderPresenter 实例, 若不存在则创建新的实例并缓存
14+
*
15+
* AbcRender -> AbcPresenter
16+
*
17+
*/
18+
- (id <GDDRenderPresenter>)presenter;
19+
1020
@end

GDDataDrivenView/Classes/Renders/GDDUnknownCellRender.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,4 @@
88

99
@interface GDDUnknownCellRender : UITableViewCell <GDDRender, GDDRenderPresenter>
1010

11-
@property (strong, nonatomic) IBOutlet UILabel *descriptionLabel;
12-
1311
@end

GDDataDrivenView/Classes/Renders/GDDUnknownCellRender.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
#import "GDDUnknownCellRender.h"
66
#import "UITableViewCell+GDDRender.h"
77

8+
@interface GDDUnknownCellRender ()
9+
@property (strong, nonatomic) UILabel *descriptionLabel;
10+
@end
11+
812
@implementation GDDUnknownCellRender {
913
// BOOL _didSetupConstraints;
1014
NSLayoutConstraint *_heightConstraint;

GDDataDrivenView/Classes/ViewControllerPresenter/GDDViewControllerTransition.h

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,18 @@ enum GDDViewControllerTransitionStackMode {
1313
PUSH, PRESENT, PRESENT_THEN_PUSH
1414
};
1515

16+
/**
17+
* 当不存在于历史堆栈中时, 使用该模式进行显示
18+
*/
1619
- (void (^)(enum GDDViewControllerTransitionStackMode stackMode))by;
20+
/**
21+
* 作为 UIWindow 的 rootViewController
22+
*/
1723
- (void (^)())asRoot;
1824

25+
/**
26+
* 适用于 ViewController 已存在于历史堆栈中的情况
27+
*/
1928
- (void (^)(BOOL bringToFront))refresh;
2029

2130
@end
@@ -26,8 +35,17 @@ NS_ASSUME_NONNULL_BEGIN
2635
- (GDDViewControllerTransition *(^)(id data))data;
2736
- (GDDViewControllerTransition *(^)(GDDPBViewOption *viewOption))viewOption;
2837

38+
/**
39+
* 总是创建新的 ViewController 实例, 并显示
40+
*/
2941
- (id<GDDTransitionBuilder> (^)(Class viewControllerClass))to;
42+
/**
43+
* 先检查历史堆栈中是否存在该类型的 ViewController, 若存在则回退至可见; 若不存在则先创建再显示
44+
*/
3045
- (id<GDDTransitionBuilder> (^)(Class viewControllerClass))toSingleton;
46+
/**
47+
* 先检查历史堆栈中是否存在该 ViewController, 若存在则回退至可见; 若不存在则先创建再显示
48+
*/
3149
- (id<GDDTransitionBuilder> (^)(UIViewController *viewController))toInstance;
3250

3351
/**
@@ -40,8 +58,7 @@ NS_ASSUME_NONNULL_BEGIN
4058
- (void (^)())toCurrent;
4159

4260
/**
43-
* 返回当前可见的 View Controller
44-
* @return
61+
* @return 当前可见的 ViewController
4562
*/
4663
+ (UIViewController *)topViewController;
4764

GDDataDrivenView/Classes/ViewControllerPresenter/GDDViewControllerTransition.m

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
#import "GDDViewControllerTransition.h"
66
#import <objc/runtime.h>
7-
#import "GDCMessageHandler.h"
87

98
// The address of this variable is used as a key for obj_getAssociatedObject.
109
static const char kPresenterKey = 0;
@@ -36,7 +35,7 @@ @implementation GDDViewControllerTransition {
3635

3736
- (id <GDDTransitionBuilder> (^)(Class viewControllerClass))to {
3837
return ^id <GDDTransitionBuilder>(Class viewControllerClass) {
39-
_viewController = [viewControllerClass instancesRespondToSelector:@selector(initWithPayload:)] ? [[viewControllerClass alloc] initWithPayload:_data] : [[viewControllerClass alloc] init];
38+
_viewController = [[viewControllerClass alloc] init];
4039
return self;
4140
};
4241
}
@@ -152,10 +151,6 @@ - (void)displayAndRefresh {
152151

153152
if (!shouldPush) {
154153
// 动画: 仅在 present 时有效
155-
// if (viewOptions.transition) {
156-
// controller.transitioningDelegate = viewOptions.transition;
157-
// controller.modalPresentationStyle = UIModalPresentationCustom;
158-
// }
159154
controller.modalTransitionStyle = _viewOption.modalTransitionStyle;
160155
controller.modalPresentationStyle = _viewOption.modalPresentationStyle;
161156
}
@@ -168,14 +163,14 @@ - (void)displayAndRefresh {
168163
if (!controller.isViewLoaded) {
169164
[controller view]; // force viewDidLoad to be called
170165
}
171-
[presenter update:(id <GDDView>) controller withData:_data];
166+
[presenter update:controller withData:_data];
172167
});
173168
return;
174169
}
175170

176171
[self config:YES]; // 某些 ViewOption 需要在 present 之前设置才会生效
177172
[top presentViewController:_stackMode == PRESENT ? controller : [[UINavigationController alloc] initWithRootViewController:controller] animated:YES completion:^{
178-
[presenter update:(id <GDDView>) controller withData:_data];
173+
[presenter update:controller withData:_data];
179174
}];
180175
[self config:NO];
181176
}
@@ -209,9 +204,6 @@ - (void)config:(BOOL)eagerly {
209204
if (toolBar != GDPBBool_Default && GDPBBool_IsValidValue(toolBar)) {
210205
[controller.navigationController setToolbarHidden:toolBar == GDPBBool_False animated:NO];
211206
}
212-
// if (options[optionStatusBarOrientation]) {
213-
// [[UIApplication sharedApplication] setStatusBarOrientation:(UIInterfaceOrientation) [options[optionStatusBarOrientation] integerValue]];
214-
// }
215207
if (viewOption.deviceOrientation) {
216208
viewOption.deviceOrientation = UIDeviceOrientationUnknown;
217209
[[UIDevice currentDevice] setValue:@(viewOption.deviceOrientation) forKey:@"orientation"];
@@ -251,7 +243,7 @@ + (void)replaceRootViewController:(UIViewController *)controller {
251243
if (rootViewController.presentedViewController) { // 避免内存泄漏, 以释放 rootViewController 和 rootViewController.presentedViewController
252244
[rootViewController dismissViewControllerAnimated:YES completion:nil];
253245
}
254-
UIApplication.sharedApplication.keyWindow.rootViewController = controller;
246+
UIApplication.sharedApplication.delegate.window.rootViewController = controller; // keyWindow 在 makeKeyAndVisible 执行前为nil
255247
}
256248

257249
+ (UIViewController *)findViewController:(Class)viewControllerClass {

0 commit comments

Comments
 (0)