介绍 Trio | 第二部分

By: Eli Hart, Ben Schwab, and Yvonne Wong

作者: Eli HartBen Schwab,和Yvonne Wong

In the previous post in this series, we introduced you to Trio, Airbnb’s framework for Jetpack Compose screen architecture in Android. Some of the advantages of Trio include:

在本系列的上一篇文章中,我们向您介绍了 Trio,Airbnb 在 Android 中用于 Jetpack Compose 屏幕架构的框架。Trio 的一些优点包括:

  • Guarantees type safety when communicating across module boundaries in complex apps
  • 在复杂应用程序中跨模块通信时保证类型安全
  • Codifies expectations about how ViewModels are used and shared, and what interfaces look like between screens
  • 对ViewModel的使用和共享以及屏幕之间的接口的期望进行编码
  • Allows for stable screenshot and UI tests and simple navigation testing
  • 允许稳定的截图和UI测试以及简单的导航测试
  • Compatible with Mavericks, Airbnb’s open source state management library for Jetpack (Trio is built on top of Mavericks)
  • 兼容Mavericks,Airbnb的开源状态管理库,用于Jetpack(Trio是在Mavericks之上构建的)

If you need a refresher on Trio or are learning about this framework for the first time, start with Part 1. It provides an overview of why we built Trio when transitioning to Compose from a Fragments-based architecture. Part 1 also explains the core framework concepts like the Trio class and UI class.

如果您对Trio不熟悉,或者是第一次了解这个框架,请从第1部分开始。它提供了一个概述,解释了我们为什么在从基于Fragments的架构转换到Compose时构建了Trio。第1部分还解释了核心框架概念,如Trio类和UI类。

In this post, we’ll build upon what we’ve shared so far and dive into how navigation works in Trio. As you’ll see, we designed Trio to make navigation simpler and easier to test, especially for large, modularized applications.

在本文中,我们将在之前分享的基础上进一步探讨Trio中的导航工作原理。正如您将看到的,我们设计Trio旨在使导航更简单、更易于测试,特别适用于大型模块化应用程序。

Navigating with Trio

使用Trio进行导航

A unique approach in our design is that Trios are stored in the ViewModel’s State, right alongside all other data that a Screen exposes to the UI. For example, a common use case is to store a list of Trios to represent a stack of screens.

我们设计中的一个独特方法是将Trios存储在ViewModel的State中,与屏幕向UI公开的所有其他数据一起。例如,一个常见的用例是存储Trios列表以表示屏幕堆栈。

data class ParentState(
val trioStack: List<Trio>
) : MavericksState

data class ParentState(
val trioStack: List...

开通本站会员,查看完整译文。

Home - Wiki
Copyright © 2011-2024 iteam. Current version is 2.139.0. UTC+08:00, 2024-12-23 00:08
浙ICP备14020137号-1 $Map of visitor$