The original address: android-developers.googleblog.com/2020/08/ann…

Original author: twitter.com/karenkayliu

Release Date: August 26, 2020

Today, we are releasing the alpha release of Jetpack Compose, our modern UI toolkit designed to help you quickly and easily build beautiful applications on all Android platforms, with native access to the platform apis. Bring your application to life with less code, interactive tools, and the intuitive Kotlin API.

No matter where you work — whether you’re on your kitchen table or in your office — we know you need a programming language, an IDE, and a powerful UI framework to save you time and reduce the amount of code you need to write. So we created Jetpack Compose to let you (and us!) Compose. More efficient in building UI.

We started with Android Jetpack — taking some of the most difficult and common developer issues on Android and creating a set of libraries to ensure high-quality apps run on all versions of the platform. Today, Jetpack is used by 84% of the top 10,000 apps in the Play Store.

Then we heard how developers love Kotlin, which is now used by more than 70% of the top 1,000 apps and 60% of professional Android developers. The Google Home application reduces the number of lines of code by 80% in some cases by using Kotlin, and NullPointerExceptions are reduced by 33% over similar periods in the past. Duolingo, on average, reduced the number of rows by 30%.

Finally, we heard strong feedback from the community that developers liked the simplicity of building UIs with declarative apis. Jetpack Compose is a combination of the above three. Apis, intuitive languages, and reactive programming models for large-scale, high-quality applications.

Jetpack Compose: Now in Alpha

Jetpack Compose Alpha provides the capabilities you need to build mature Android applications, including powerful tools and interoperability with existing Android views, so you don’t need to rewrite your application. The Compose API was designed and developed in conjunction with a set of canonical sample applications using Material Design that we are pleased to release today! You can import and explore the latest examples directly. You can also import and explore the latest samples directly from Android Studio.

This alpha release includes

  • animation
  • Constraint layout
  • Initial support for A11Y
  • Input and gestures
  • Interoperability with Views (start mixing Composable functionality into your existing applications).
  • A lazy person list
  • Material UI components
  • Performance optimization
  • test
  • Text and editable text
  • Drawing and graphics
  • Window management

We’ve also worked closely with the JetBrains Kotlin team to add a number of new features to Android Studio 4.2 Canary to help you build apps with Compose.

  • Code done
  • Write preview comments
  • Deploy individual composable parts on any device
  • Interactive authoring Preview
  • Kotlin compiler plug-in for code generation
  • Compose’s data API sample

www.youtube.com/watch?v=U5B…

The thought is in Compose

Compose uses a very different programming model than the existing model for building uIs on Android. Historically, Android’s view hierarchy has been represented as a tree of UI widgets. As the state of the application changes, you need to update the UI hierarchy to display the current data. The most common way to update the UI is to walk the tree using functions such as findViewById() and change the nodes by calling the following methods.

button.setText(String) 
Copy the code
container.addView(View) 
Copy the code
img.setImageBitmap(Bitmap) 
Copy the code

These methods change the internal state of the widget. Not only is this tedious, but manually updating a view also increases the likelihood of something going wrong (such as forgetting to update the view). Jetpack Compose is a completely declarative component-based approach, which means that you describe your UI as functions that convert data into UI hierarchies. The Compose framework automatically updates the UI hierarchy for you when the underlying data changes, making it easy and quick to build your UI.

www.youtube.com/watch?v=SMO…

Fully interconnects with the existing Android view

Adopting any new framework is a big change for an existing project and code base, which is why we designed Compose to be as easy to adopt as Kotlin — it’s fully interoperable with existing Android code from day one.

Moving to Compose is up to you and your team. If you’re building a new application, the best option might be to implement the entire UI in Compose. We know that most of you have a large existing code base, so instead of rewriting your application, combine Compose with your existing UI design.

There are two main ways to combine Compose with a view-based UI.

  • You can add the Compose element to your existing UI, either by creating a new Comose-based screen, or by adding the Compose element to an existing fragment or view layout.
  • You can add view-based UI elements to your composable functionality. Doing so allows you to add non-compose components, such as MapView or WebView, to your Compose based design.

We’ve also released a new library, the MDC Compose Theme Adapter, which allows you to reuse existing Material Components themes in the Compose UI.

For more information, try Compose for Existing Apps Codelab or check out these two samples.

  • Tivi and Sunflower are existing applications that are being integrated with Compose.
  • Crane sample application, embedding a MapView in Compose.

www.youtube.com/watch?v=PjQ…

Powerful tool

Jetpack Compose is a powerful tool built in Android Studio designed to help you quickly iterate on the UI you’re developing.

The Compose layout Preview enables you to preview your Compose component without having to deploy your application to a device or emulator. As you develop the application, your preview is updated to help you see your changes more quickly. To create a layout preview, write a composable function that takes no arguments and add it

@Preview annotation 
Copy the code

After you build your application, the UI for the preview feature will appear in the Preview pane of Studio.

Android Studio provides an interactive preview mode. When you are in interactive preview mode, you can click or type your UI elements, and the UI will react just as it would in an installed application.

You can also deploy a single composable feature to your physical device or Android emulator. Android Studio creates a new activity that contains the UI generated by this feature and deploys it to the application on the device. This allows you to try out the user interface on a real device without having to reinstall the entire application or navigate to its location.

Start with Jetpack Compose

To get started with Jetpack Compose, try the Compose tutorial and set it up. Or go directly to the sample applications and browse them in “Compose by Example.”

www.youtube.com/watch?v=DDd…

To find a comprehensive set of Compose resources, including new code LABS and extended documentation, see the Compose path.

Since we opened Jetpack Compose last year, many of you have given us valuable feedback, documented errors, or contributed CL that has made us where we are today. Thank you!

Compose has not yet been recommended for full production, especially as we work towards API stability and performance optimization, but we hope you’ll give it a try and share your feedback. Join us on Kotlin Slack’s # Compose channel. Compose 1.0 is expected to launch in 2021.

Have fun composing!


Translate via www.DeepL.com/Translator (free version)