如何同时显示加载屏幕和处理授权?
我可以切换到LoadingView
并返回到AuthView
inAuthController
还是需要将身份验证逻辑移到LoadingController
?
class AuthController : Controller() {
val authView : AuthView by inject()
val loadingView : LoadingView by inject()
fun tryAuth(login: String, password: String) {
runAsync {
login == "admin" && password == "admin"
} ui { successful ->
authView.replaceWith(loadingView, ViewTransition.Fade(0.5.seconds))
if (successful) {
// doesn't work
loadingView.replaceWith(MainView::class, ViewTransition.Metro(0.5.seconds))
} else {
// doesn't work
loadingView.replaceWith(AuthView::class, ViewTransition.Fade(0.5.seconds))
}
}
}
}
要更换AuthView
用LoadingView
,然后LoadingView
与MainView
在相同的脉冲,所以这不会给你想要的东西。通常,您希望LoadingView
在评估身份验证信息之前更改为UI 线程上的 。使用这种方法,您的代码可以工作,但它可能不是您想要的。
class AuthController : Controller() {
val authView : AuthView by inject()
val loadingView : LoadingView by inject()
fun tryAuth(login: String, password: String) {
authView.replaceWith(loadingView, ViewTransition.Fade(0.5.seconds))
runAsync {
// Simulate db access or http call
Thread.sleep(2000)
login == "admin" && password == "admin"
} ui { successful ->
if (successful) {
// doesn't work
loadingView.replaceWith(MainView::class, ViewTransition.Metro(0.5.seconds))
} else {
// doesn't work
loadingView.replaceWith(AuthView::class, ViewTransition.Fade(0.5.seconds))
}
}
}
}
class AuthView : View("Auth") {
val authController: AuthController by inject()
override val root = stackpane {
button(title).action {
authController.tryAuth("admin", "admin")
}
}
}
class LoadingView : View("Loading...") {
override val root = stackpane {
label(title)
}
}
class MainView : View("Main View") {
override val root = stackpane {
label(title)
}
}
您必须记住,替换视图不会调整窗口大小(尽管您可以访问舞台并要求它调整到当前视图的大小),因此最好在单独的窗口中打开每个视图。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句