-
Notifications
You must be signed in to change notification settings - Fork 207
页面跳转
xuwhale6 edited this page Aug 27, 2020
·
5 revisions
- 语法
- 页面注册
---
--- 为页面设置别名key,之后跳转页面link方法可传入该页面key。该方法可以不实现。
---
---@param key 别名
---@param class_name 要加载文件的绝对路径
Link.register(string key, string class_name)
- 页面跳转
---
--- 页面跳转
---
---@param class_name 要加载文件的别名key或绝对路径
---@param params 页面跳转携带的参数,可不传
---@param animType 页面跳转动画效果,可不传,不传时为从右向左进入页面。目前mmpaas模拟器暂不支持
---@param function 跳转的页面销毁时回调 ,可不传
Link.link(string class_name, Map params, AnimType animType, function(boolen result, Map map)
end)
- 关闭当前页面
---
--- 关闭当前页面
---
---@param animType 页面关闭动画效果,可不传
---@param params 关闭时回传上个页面的数据,可不传
Link.close(AnimType animType, Map params)
- 获取上个页面传递到该页面的参数
---上个界面传递过来的参数
Link.getParams()
- 示例demo如下:
--pageA
ui {
--- layout views
Label("当前A,跳转B")
.crossSelf(CrossAxis.CENTER)
.top(20)
.padding(20, 20, 20, 20)
.bgColor(Color(200, 200, 0, 1))
.onClick(function()
Link.link("B",
{ from = "A", to = "B" },
AnimType.BottomToTop, function(result, map)
print(tostring(result), tostring(map.info))
end)
end)
}
---
--- preview
local function preview()
Link.register("B", "/Users/momo/github_mln/MLNUIDemoTest/src/.preview/preview_pageB.lua")
end
--pageB
ui {
--- layout views
VStack()
.widthPercent(100)
.mainAxis(MainAxis.CENTER)
.subs(
Label("当前B页面,返回上一页")
.crossSelf(CrossAxis.CENTER)
.top(20)
.padding(20, 20, 20, 20)
.bgColor(Color(200, 200, 0, 1))
.onClick(function()
--关闭当前页面,
Link.close(AnimType.BottomToTop, { info = "B_close" })
end)
)
}
---
--- preview
local function preview()
print("A->B:params = ", tostring(Link.getParams()))
end
- Android配置
--在Application的onCreate中注册被跳转页面pageB的Activity。
ArgoEngine.registerActivity(
new ArgoEngine.LinkHolder("B", BActivity.class));
- iOS配置
- 注册映射关系 iOS 中需要注册 lua 中的类名和原生中的类名对应的映射关系。在尽可能比较早的时机注册,比如:ApplicationDidFinishLaunching。
[MLNUILink registerName:@"B" linkClass:[BViewController class]];
- 被跳转的页面需要实现 MLNUILinkProtocol 协议
从A页面跳转到B页面,则iOS要在B viewController中实现 MLNUILinkProtocol 协议
//BViewController
#pragma mark - MLNLinkProtocol
@interface BViewController ()<MLNUILinkProtocol>
//页面关闭时回调给lua
@property (nonatomic, strong) MLNUILinkCloseCallback callback;
@end
+ (UIViewController *)mlnLinkCreateController:(NSDictionary *)params closeCallback:(MLNUILinkCloseCallback)callback {
BViewController *vc = [[BViewController alloc] init];
vc.callback = callback;
return vc;
}
- (void)dealloc {
if (self.callback) {
self.callback(@{@"code":@(200), @"message":@"ok"});
}
}