Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

163
Vistas
How can you create a reusable modifier in Compose?

Most of my screens(views) start out with a Box composable to contain all the child composables(components).

// background
Box(
        modifier = Modifier
            .fillMaxSize()
            .background(customColor)
    ) 
{
// foreground
Column()

}

Instead of having to create the modifier properties on every screen, how would you create a reusable modifier?

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

In such a simple case, you can do the following (no need to use then):

fun Modifier.myModifier(customColor: Color) =
    this.fillMaxSize()
        .background(customColor)

In case you need to save any state in your modifier using remember or other state builders annotated with @Composable, you can do it with Modifier.composed. For example here's how you can add animation to your modifier:

fun Modifier.myModifier(customColor: Color): Modifier = composed {
    val animatedColor by animateColorAsState(customColor)
    this.fillMaxSize()
        .background(animatedColor)
}

Note, that inside composed you should only use state annotated composables, not views. More details can be found here.

over 4 years ago · Santiago Trujillo Denunciar

0

You can create it like this

fun Modifier.myModifier(customColor: Color) = this.then(
    Modifier.fillMaxSize().background(customColor)
)
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda