Benefit | Summary |
---|---|
Improve the developer experience | Allow your consumers to take advantage of the benefits of Compose by providing an intuitive and declarative API for integrating your library. |
Reduce boilerplate code | Reduce the code your consumers have to write when using your library. Instead of having to use interoperability APIs, your consumers can directly use a declarative API through composable functions you provide. |
Fewer bugs | It can be challenging to switch between Compose's declarative style of thinking and View's imperative style of thinking. As a result, when consumers write interoperability code to interact with your View-based library, they can easily introduce bugs. Adding support for Compose guarantees correct interoperability, as this is not the responsibility of the consumer anymore. |
Future-proof | Compose is the modern recommended UI framework for building Android apps. By supporting Compose, you are preparing your library for a Compose-first fut |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright 2023 Google LLC. | |
// SPDX-License-Identifier: Apache-2.0 | |
@Composable | |
fun EpisodePlayerWithBackground(/* ... */) { | |
// Initialize a FocusRequester object | |
val focusRequester = remember { FocusRequester() } | |
LaunchedEffect(Unit) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright 2023 Google LLC. | |
// SPDX-License-Identifier: Apache-2.0 | |
@Composable | |
private fun HomeContentGrid(/* ... */) { | |
LazyVerticalGrid( | |
// Adapt number of columns wherein each column has at least 362.dp of space | |
columns = GridCells.Adaptive(362.dp), | |
modifier = modifier.fillMaxSize() | |
) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright 2023 Google LLC. | |
// SPDX-License-Identifier: Apache-2.0 | |
class CheckBox(context: Context) : View(context) { | |
override fun performClick(): Boolean { | |
// Refactor: prevent the checkbox from toggling when clicked | |
// toggleCheck() | |
return super.performClick() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright 2023 Google LLC. | |
// SPDX-License-Identifier: Apache-2.0 | |
var checked by remember { mutableStateOf(false)} | |
Checkbox(checked = checked, onCheckedChange = { | |
checked = it | |
}) |
NewerOlder