Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

123
Views
Ámbito de componentes componibles a un componente componible principal

Estoy haciendo una implementación de PreferencesScreen en Compose y he hecho todos los componentes como PreferencesSwitch , CheckBox , etc.
Ahora me pregunto si hay alguna manera de hacer que todos los componentes solo se puedan usar dentro del alcance de la función PreferencesScreen y no se puedan usar fuera de ella.
Como por ejemplo, en LazyColumn , los items solo se pueden usar dentro LazyColumnScope . Observé su implementación, pero usó la anotación @LazyScopeMarker , así que supongo que hay diferentes marcadores para diferentes ámbitos.

Comportamiento esperado:

 PreferencesScreen{ PreferencesCheckBox(...){ ... } }

es posible pero,

 PreferencesCheckBox(...){ ... }

solo no es posible.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Puede declarar algún alcance igual que lo hace LazyColumn :

 interface PreferencesScreenScope { @Composable fun PreferencesCheckBox() } private class PreferencesScreenScopeImpl: PreferencesScreenScope { @Composable override fun PreferencesCheckBox() { } }

interface / class ...Impl se usa aquí para asegurarse de que ninguna otra pantalla pueda reutilizar PreferencesScreenScopeImpl , también agrega la posibilidad de prueba.

Úselo en PreferencesScreen :

 @Composable fun PreferencesScreen(content: @Composable PreferencesScreenScope.() -> Unit ) { PreferencesScreenScopeImpl().content() }

Use PreferencesScreen así:

 PreferencesScreen { PreferencesCheckBox() }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!