-
Notifications
You must be signed in to change notification settings - Fork 60
4. Component (组件式开发)
Yizzuide edited this page Dec 26, 2016
·
9 revisions
In this section, we will have much stuff to talk you that include URL Component, URL Route, parameter transmission and mix Controller component together.
组件注册用于使用URL组件跳转方式来做界面跳转(乐高的模块跳转),这是乐高基于当前移动流行的组件开发的一种实现方式,同时也是用来管理解决乐高模块耦合的一种方式,还有一大好处是可以使页面到页面的跳转更清晰,推荐大家使用!
这种方式是:URL + 组件名, 即一个组件名对应一个访问的URL。
// 注意组件名首字母要大写
[XFURLRoute register:@"bdj://indexTab" forComponent:@"IndexTab"];
[XFURLRoute register:@"bdj://indexTab/publish" forComponent:@"Publish"];由于URL路径的最后一个路径就是组件名,所有可以使用快速初始化方式:
[XFURLRoute register:@"bdj://indexTab"];
[XFURLRoute register:@"bdj://indexTab/publish"];更快的初始化URL列表:
// 使用自定义类封装起来
@implementation BDJAppURLRegister
+ (void)urlRegister
{
[XFURLRoute initURLGroup:@[
@"bdj://indexTab", // Tab主UI框架页
@"bdj://indexTab/publish", // 发布作品
@"bdj://friendTrends/friendsRecomment", // 推荐朋友
@"bdj://userCenter/signIn", // 登录
@"bdj://essence/recommendTag", // 推荐标签
@"bdj://essence/post/postPictureBrowse", // 浏览大图
@"bdj://essence/post/postComment", // 帖子评论
@"bdj://me/web"
]];
}
@end当项目完全以乐高VIPER方式编写时,可以启用URL路径检测功能,内部会对乐高模块关系路径检测,用于检测路径名的正确性及路径层级的正确性:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// 可选开启模块追踪log
[XFRoutingLinkManager enableLog];
// 注册APP的所有URL
[BDJAppURLRegister urlRegister];
// 可选开启URL路径验证
[XFURLRoute enableVerifyURLRoute];
// 根据URL显示组件
XF_ShowURLComponent2Window_Fast(@"bdj://indexTab")
return YES;
}
这种情况适用于乐高模块间的跳转,也适用于模块到控制器的跳转,下面Push方式:
@implementation BDJPostRouting
// 组装模块
XF_AutoAssemblyModule_Fast
// 跳转组件
- (void)transition2PostComment
{
XF_PUSH_URLComponent_Fast(@"bdj://essence/post/postComment")
}
@end使用Present方式:
@implementation BDJPostRouting
// 组装模块
XF_AutoAssemblyModule_Fast
// 跳转组件
- (void)transition2PostPictureBrowse
{
XF_Present_URLComponent_Fast(@"bdj://essence/post/postPictureBrowse")
}
@end自定义跳转方式:
@implementation BDJIndexTabRouting
// 组装模块
XF_AutoAssemblyModule_Fast
// 跳转组件
- (void)transition2Publish
{
// 自定义跳转 (Publish组件为控制器)
[self.uiBus openURL:@"bdj://indexTab/publish" withTransitionBlock:^(__kindof UIViewController *thisInterface, __kindof UIViewController *nextInterface, TransitionCompletionBlock completionBlock) {
// 使用不带动画的方式
[thisInterface presentViewController:nextInterface animated:NO completion:completionBlock];
} customCode:nil];
}
@end注意: 例子中的代码来自一个通过乐高框架编写的完整项目:BDJProjectExample