Skip to content

Commit 2a01849

Browse files
author
Larry Tin
committed
Add Router Example
1 parent eb821a1 commit 2a01849

12 files changed

Lines changed: 497 additions & 33 deletions

File tree

Example/GDDataDrivenView.xcodeproj/project.pbxproj

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
6003F5B2195388D20070C39A /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F591195388D20070C39A /* UIKit.framework */; };
2424
6003F5BA195388D20070C39A /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 6003F5B8195388D20070C39A /* InfoPlist.strings */; };
2525
6003F5BC195388D20070C39A /* Tests.m in Sources */ = {isa = PBXBuildFile; fileRef = 6003F5BB195388D20070C39A /* Tests.m */; };
26+
61FBC00A46E2117B6AC5C27C /* GDDMyExamplePresenter.m in Sources */ = {isa = PBXBuildFile; fileRef = 61FBC6AC3FF3B95E90AF102D /* GDDMyExamplePresenter.m */; };
2627
61FBC01F617B5004D55FC52E /* GDDSampleCellPresenter.m in Sources */ = {isa = PBXBuildFile; fileRef = 61FBC772965FCE547C73F336 /* GDDSampleCellPresenter.m */; };
28+
61FBC2B32514CC4B09B837B1 /* GDDMyExampleViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 61FBCD9795DB07787A4EEEC0 /* GDDMyExampleViewController.m */; };
2729
61FBC4B9CACF218A52623DD2 /* GDDSampleCollectionViewCellPresenter.m in Sources */ = {isa = PBXBuildFile; fileRef = 61FBC3C2413FED786CDA470A /* GDDSampleCollectionViewCellPresenter.m */; };
2830
61FBC65B94033B1EBB452073 /* GDDCollectionViewEmbeddedInTableViewCellPresenter.m in Sources */ = {isa = PBXBuildFile; fileRef = 61FBCF5A70B64B4262BE3799 /* GDDCollectionViewEmbeddedInTableViewCellPresenter.m */; };
2931
61FBCA5AED5F2B29978B9653 /* test_data.json in Resources */ = {isa = PBXBuildFile; fileRef = 61FBC87E2BA28B9D962635CE /* test_data.json */; };
@@ -74,14 +76,18 @@
7476
61FBC2CDCB9609C1FB005738 /* GDDSampleCellPresenter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GDDSampleCellPresenter.h; sourceTree = "<group>"; };
7577
61FBC3AEE2259CCB7532DAB1 /* GDDCollectionViewEmbeddedInTableViewCellRender.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GDDCollectionViewEmbeddedInTableViewCellRender.h; sourceTree = "<group>"; };
7678
61FBC3C2413FED786CDA470A /* GDDSampleCollectionViewCellPresenter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GDDSampleCollectionViewCellPresenter.m; sourceTree = "<group>"; };
79+
61FBC4C2FCB7ACD32A9BC839 /* GDDMyExamplePresenter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GDDMyExamplePresenter.h; sourceTree = "<group>"; };
7780
61FBC53B56759D5421F5404E /* GDDSampleCollectionViewCellRender.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GDDSampleCollectionViewCellRender.m; sourceTree = "<group>"; };
81+
61FBC6AC3FF3B95E90AF102D /* GDDMyExamplePresenter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GDDMyExamplePresenter.m; sourceTree = "<group>"; };
7882
61FBC772965FCE547C73F336 /* GDDSampleCellPresenter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GDDSampleCellPresenter.m; sourceTree = "<group>"; };
7983
61FBC87E2BA28B9D962635CE /* test_data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = test_data.json; sourceTree = "<group>"; };
8084
61FBC9077CB4A5E9BA20CC98 /* GDDCollectionViewEmbeddedInTableViewCellPresenter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GDDCollectionViewEmbeddedInTableViewCellPresenter.h; sourceTree = "<group>"; };
8185
61FBC94C720D2FF1B4D449E6 /* GDDSampleCollectionViewCellRender.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GDDSampleCollectionViewCellRender.h; sourceTree = "<group>"; };
8286
61FBCC6D528001DE1CEB4ABB /* GDDSampleCollectionViewCellPresenter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GDDSampleCollectionViewCellPresenter.h; sourceTree = "<group>"; };
87+
61FBCD9795DB07787A4EEEC0 /* GDDMyExampleViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GDDMyExampleViewController.m; sourceTree = "<group>"; };
8388
61FBCF5A70B64B4262BE3799 /* GDDCollectionViewEmbeddedInTableViewCellPresenter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GDDCollectionViewEmbeddedInTableViewCellPresenter.m; sourceTree = "<group>"; };
8489
61FBCF7AFE5EB0DD1905AEA5 /* GDDCollectionViewEmbeddedInTableViewCellRender.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GDDCollectionViewEmbeddedInTableViewCellRender.m; sourceTree = "<group>"; };
90+
61FBCFB8E056FACE01F0E8C2 /* GDDMyExampleViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GDDMyExampleViewController.h; sourceTree = "<group>"; };
8591
664CAFEA054EFF8889C6B45B /* Pods-GDDataDrivenView_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-GDDataDrivenView_Example.release.xcconfig"; path = "Pods/Target Support Files/Pods-GDDataDrivenView_Example/Pods-GDDataDrivenView_Example.release.xcconfig"; sourceTree = "<group>"; };
8692
873B8AEA1B1F5CCA007FD442 /* Main.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Main.storyboard; sourceTree = "<group>"; };
8793
BB40A2142DD937158E07F5B1 /* libPods-GDDataDrivenView_Example.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-GDDataDrivenView_Example.a"; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -175,6 +181,7 @@
175181
61FBC94C720D2FF1B4D449E6 /* GDDSampleCollectionViewCellRender.h */,
176182
61FBC3C2413FED786CDA470A /* GDDSampleCollectionViewCellPresenter.m */,
177183
61FBCC6D528001DE1CEB4ABB /* GDDSampleCollectionViewCellPresenter.h */,
184+
61FBC5D24698FFFC8163C5A3 /* Router */,
178185
);
179186
name = "Example for GDDataDrivenView";
180187
path = GDDataDrivenView;
@@ -219,6 +226,17 @@
219226
name = "Podspec Metadata";
220227
sourceTree = "<group>";
221228
};
229+
61FBC5D24698FFFC8163C5A3 /* Router */ = {
230+
isa = PBXGroup;
231+
children = (
232+
61FBCFB8E056FACE01F0E8C2 /* GDDMyExampleViewController.h */,
233+
61FBCD9795DB07787A4EEEC0 /* GDDMyExampleViewController.m */,
234+
61FBC6AC3FF3B95E90AF102D /* GDDMyExamplePresenter.m */,
235+
61FBC4C2FCB7ACD32A9BC839 /* GDDMyExamplePresenter.h */,
236+
);
237+
path = Router;
238+
sourceTree = "<group>";
239+
};
222240
72F1EA74B4FB396B206919C5 /* Pods */ = {
223241
isa = PBXGroup;
224242
children = (
@@ -342,13 +360,16 @@
342360
files = (
343361
);
344362
inputPaths = (
363+
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
364+
"${PODS_ROOT}/Manifest.lock",
345365
);
346366
name = "[CP] Check Pods Manifest.lock";
347367
outputPaths = (
368+
"$(DERIVED_FILE_DIR)/Pods-GDDataDrivenView_Example-checkManifestLockResult.txt",
348369
);
349370
runOnlyForDeploymentPostprocessing = 0;
350371
shellPath = /bin/sh;
351-
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
372+
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
352373
showEnvVarsInLog = 0;
353374
};
354375
3CA872BAB155D7046AAEA98A /* [CP] Check Pods Manifest.lock */ = {
@@ -357,13 +378,16 @@
357378
files = (
358379
);
359380
inputPaths = (
381+
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
382+
"${PODS_ROOT}/Manifest.lock",
360383
);
361384
name = "[CP] Check Pods Manifest.lock";
362385
outputPaths = (
386+
"$(DERIVED_FILE_DIR)/Pods-GDDataDrivenView_Tests-checkManifestLockResult.txt",
363387
);
364388
runOnlyForDeploymentPostprocessing = 0;
365389
shellPath = /bin/sh;
366-
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
390+
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
367391
showEnvVarsInLog = 0;
368392
};
369393
6DE4DC247489DE34E30E189A /* [CP] Copy Pods Resources */ = {
@@ -372,9 +396,12 @@
372396
files = (
373397
);
374398
inputPaths = (
399+
"${SRCROOT}/Pods/Target Support Files/Pods-GDDataDrivenView_Example/Pods-GDDataDrivenView_Example-resources.sh",
400+
"$PODS_CONFIGURATION_BUILD_DIR/GDChannel/GDChannel.bundle",
375401
);
376402
name = "[CP] Copy Pods Resources";
377403
outputPaths = (
404+
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}",
378405
);
379406
runOnlyForDeploymentPostprocessing = 0;
380407
shellPath = /bin/sh;
@@ -442,6 +469,8 @@
442469
61FBC65B94033B1EBB452073 /* GDDCollectionViewEmbeddedInTableViewCellPresenter.m in Sources */,
443470
61FBCBB85FB28D816D8FA20A /* GDDSampleCollectionViewCellRender.m in Sources */,
444471
61FBC4B9CACF218A52623DD2 /* GDDSampleCollectionViewCellPresenter.m in Sources */,
472+
61FBC2B32514CC4B09B837B1 /* GDDMyExampleViewController.m in Sources */,
473+
61FBC00A46E2117B6AC5C27C /* GDDMyExamplePresenter.m in Sources */,
445474
);
446475
runOnlyForDeploymentPostprocessing = 0;
447476
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// Created by Larry Tin on 1/1/18.
3+
// Copyright (c) 2018 Larry Tin. All rights reserved.
4+
//
5+
6+
#import <Foundation/Foundation.h>
7+
#import "GDDPresenter.h"
8+
9+
/**
10+
* 声明实现 <GDDPresenter> 协议
11+
*/
12+
@interface GDDMyExamplePresenter : NSObject <GDDPresenter>
13+
@end
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
//
2+
// Created by Larry Tin on 1/1/18.
3+
// Copyright (c) 2018 Larry Tin. All rights reserved.
4+
//
5+
6+
#import "GDDMyExamplePresenter.h"
7+
#import "GDDMyExampleViewController.h"
8+
#import "ViewModel.pbobjc.h"
9+
10+
/**
11+
* 在头文件中声明实现 <GDDPresenter> 协议.
12+
*
13+
* GDDMyExampleViewController 对应的 Presenter 默认为 GDDMyExamplePresenter, 使用命名约定以避免额外配置.
14+
*
15+
* 该类的对象一般由框架自动创建, 若实现了 @selector(initWithOwner:), 则会调用该方法完成初始化;
16+
* 否则使用 @selector(init) 初始化
17+
*/
18+
@interface GDDMyExamplePresenter ()
19+
@property (weak) GDDMyExampleViewController *viewController;
20+
@end
21+
22+
@implementation GDDMyExamplePresenter {
23+
24+
}
25+
26+
/**
27+
* 当需要接收 Presenter 对应的 View Controller 对象时, 可实现该可选方法
28+
* @param owner 必须使用弱引用持有 owner
29+
* @return
30+
*/
31+
- (instancetype)initWithOwner:(GDDMyExampleViewController *)owner {
32+
self = [super init];
33+
if (self) {
34+
_viewController = owner;
35+
36+
/**
37+
在这里给 _viewController 挂载事件处理回调, 实现 Presenter 单向依赖 View Controller
38+
39+
[_viewController addPullToRefreshWithActionHandler:^{
40+
41+
}];
42+
43+
**/
44+
}
45+
return self;
46+
}
47+
48+
/**
49+
*
50+
* @param viewController 该 Presenter 对应的 View Controller, 一般和 owner 一样.
51+
* @param viewModel 如果跳转时传递的参数是字典类弱类型, 只要存在类名为 GDDMyExampleViewModel 的强类型,
52+
* 框架会自动将字典转换为该强类型. 否则, 直接传递原始数据对象.
53+
*/
54+
- (void)update:(GDDMyExampleViewController *)viewController withData:(GDDMyExampleViewModel *)viewModel {
55+
// 使用数据模型 viewModel 更新界面 viewController
56+
}
57+
58+
@end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// Created by Larry Tin on 1/1/18.
3+
// Copyright (c) 2018 Larry Tin. All rights reserved.
4+
//
5+
6+
#import <Foundation/Foundation.h>
7+
#import "GDDView.h"
8+
9+
/**
10+
* 声明实现 <GDDView> 协议
11+
*/
12+
@interface GDDMyExampleViewController : UIViewController <GDDView>
13+
@end
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//
2+
// Created by Larry Tin on 1/1/18.
3+
// Copyright (c) 2018 Larry Tin. All rights reserved.
4+
//
5+
6+
#import "GDDMyExampleViewController.h"
7+
#import "UIViewController+GDDataDrivenView.h"
8+
9+
/**
10+
* 在头文件中声明实现 <GDDView> 协议
11+
*/
12+
@implementation GDDMyExampleViewController {
13+
14+
}
15+
16+
/**
17+
* 一般交由框架自动创建 View Controller, 并调用该方法完成初始化
18+
* @return
19+
*/
20+
- (instancetype)init {
21+
if (self = [super init]) {
22+
// 指定默认的视图配置
23+
super.viewOption.setSupportedInterfaceOrientations(UIInterfaceOrientationMaskPortrait)
24+
.setHidesBottomBarWhenPushed(YES);
25+
}
26+
return self;
27+
}
28+
29+
/*
30+
* 当不希望使用约定的命名规则, 或需要自行创建 Presenter 时, 实现 GDDView 的该可选方法.
31+
*
32+
* 一种常见写法是直接返回 self, 并在头文件中声明同时实现 <GDDView, GDDPresenter> 协议,
33+
* 然后实现 -[GDDPresenter update:withData:] 方法以接收数据.
34+
* 这种情况下 View Controller 将兼任 View 和 Presenter 两种角色.
35+
*
36+
- (id <GDDPresenter>)presenter {
37+
return self;
38+
}
39+
*/
40+
41+
@end

Example/GDDataDrivenView/Router/ViewModel.pbobjc.h

Lines changed: 75 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)