如何在Jetpack Compose中处理导航? [英] How to handle navigation in Jetpack Compose?

查看:434
本文介绍了如何在Jetpack Compose中处理导航?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Jetpack Compose中,应该如何进行导航?所有(而且没有很多)示例(包括来自Google的官方示例)都使用密封类并加载新屏幕,以响应观察当前屏幕的更改.确实可以(但是),但不提供导航后退功能,并且手机的后退按钮完全不知道,只需要关闭应用程序即可,而不是返回上一个屏幕.这是否应该以某种方式与AndroidX的导航组件融合-但它是基于XML的,而Compose就是要摆脱XML?还是出现了一个全新的导航概念,也许类似于SwiftUI(navigationlink等)?这似乎是最大的障碍之一,因为没有导航,您只能拥有一个玩具应用程序.有人知道这里的路线图吗?

In Jetpack Compose, how is navigation supposed to be done? All (and there aren’t many) examples (including the official sample from Google) use sealed classes and loading new screens in reaction to observing the change in the current screen. This does (sort of) work, but provides no navigation backstack, and the phone’s back button is totally unaware, just closes the app instead of going back to the previous screen. Is this supposed to somehow converge with the navigation component from AndroidX - but it’s XML based, and Compose is all about moving away from XML? Or is there a brand new navigation concept coming, perhaps similar to SwiftUI (navigationlink, etc)? This seems to be one of the biggest roadblocks - as without navigation you can only have a toy app. Anyone aware of the roadmap here?

推荐答案

在Jetpack Compose中,这是一种非正式的导航方法.尝试一下,直到您得到Google android开发人员的正式认可为止.

Here is an unofficial approach of navigation in Jetpack Compose. Try it out until you get an official word from the Google android devs.

合成路由器

https://github.com/zsoltk/compose-router

这篇关于如何在Jetpack Compose中处理导航?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆