Module Development Guide
In-depth guide for creating DevView modules.
Module Structure
A DevView module consists of: 1. Destinations - Navigation screens 2. Serialisers - For type-safe navigation 3. Content - Composable UI 4. Metadata - Name, icon, section
Use the shared UI kit for headings, grouped rows,
filter bars, empty states and clipboard actions. Built-ins supply readable names and subtitles;
module icon colours default to Color.Unspecified and resolve from section hues and host-theme tones.
Explicit containerColor / contentColor overrides remain supported (theming).
Initialization lifetime
rememberModules calls initDataStore() once before composing initModule(). The latter
remains in composition, so implementations should put ongoing work in keyed
LaunchedEffect or DisposableEffect. Ordinary recomposition preserves those effects;
module removal cancels them and re-entry starts them again. Keep one-shot writes out
of the composable body.
Step-by-Step: Creating a Module
1. Define Destinations
sealed interface MyModuleDestination : NavKey {
@Serializable
data object Main : MyModuleDestination
@Serializable
data class Detail(val id: String) : MyModuleDestination
}
2. Implement the Module Interface
object MyModule : Module {
override val moduleName = "My Module"
override val section = Section.CUSTOM
override val subtitle = "Custom developer tool"
override val destinations: PersistentMap<KClass<out NavKey>, DestinationMetadata> = persistentMapOf(
MyModuleDestination.Main.withTitle("My Module"),
MyModuleDestination.Detail::class.asDestination()
)
override val entryDestination: NavKey = MyModuleDestination.Main
override val registerSerializers: PolymorphicModuleBuilder<NavKey>.() -> Unit = {
subclass(MyModuleDestination.Main::class, MyModuleDestination.Main.serializer())
subclass(MyModuleDestination.Detail::class, MyModuleDestination.Detail.serializer())
}
override fun EntryProviderScope<NavKey>.registerContent(
onNavigateBack: () -> Unit,
onNavigate: (NavKey) -> Unit,
bottomPadding: Dp,
) {
entry<MyModuleDestination.Main> {
MyModuleMainScreen(
onNavigateBack = onNavigateBack,
onDetailClick = { id ->
onNavigate(MyModuleDestination.Detail(id))
}
)
}
entry<MyModuleDestination.Detail> { destination ->
MyModuleDetailScreen(
id = destination.id,
onNavigateBack = onNavigateBack
)
}
}
}
3. Create UI Screens
@Composable
fun MyModuleMainScreen(
onNavigateBack: () -> Unit,
onDetailClick: (String) -> Unit
) {
Scaffold {
Column(modifier = Modifier.padding(it)) {
Text("My Module")
Button(onClick = { onDetailClick("123") }) {
Text("View Details")
}
}
}
}
4. Register Your Module
Architecture Best Practices
- Keep modules focused and single-purpose
- Use proper state management
- Document all public APIs
- Provide preview samples
- Test on both platforms
- Use descriptive names and icons for your module
- Group related screens under a single module
Destination toolbar and insets
DevView supplies each destination with its own title, a labelled Back button, and optional actions. Home has Close DevView. Actions and menus require a label; action callbacks receive the displayed NavKey. See Navigation guide for the DSL and confirmation behavior.
Keep registerContent side-effect-free. Create ViewModels inside entry content, and forward its bottomPadding to scrollable screens. DevView already applies top and horizontal insets.
Troubleshooting
- Module not appearing? Ensure it is registered and implements the required interface.
- Navigation issues? Check destination and serialiser definitions.
- UI not rendering? Verify Compose compatibility and state management.
- Custom colours or icons not displaying? Verify your colour and icon definitions are valid and supported by Compose.
Next Steps
- See Custom Modules for more examples.
- Explore Navigation for advanced navigation patterns.
API Reference
See the Dokka API Reference for full API documentation.