Component Box
262 stars
by Dropbox
A Kotlin multiplatform library for building dynamic server-driven UI
View on GitHubDocumentation
Component Box
[!NOTE]
No longer active!
After internal experimentation and discussion, we've decided to move forward with other options.
Sample
Model (server)
class Counter : ComposableModel<Int, CounterEvent>(0) {
private fun increment() {
withState {
setState(state.value + 1)
}
}
private fun decrement() {
withState {
setState(state.value - 1)
}
}
override fun on(event: CounterEvent) = when (event) {
Increment -> increment()
Decrement -> decrement()
}
}
UI Representation (server)
Static
Tree
@SerializableComponentBox
fun main() = componentBox {
tree {
lazyColumn<CounterEvent>(
verticalArrangement = Arrangement.SpaceEvenly(2.dp),
horizontalAlignment = Alignment.Start
) {
child(header)
child(count)
child(incrementButton)
child(decrementButton)
}
}
}
val header = text(
text = "Component Box Counter",
style = TextStyle(fontWeight = FontWeight.ExtraBold)
)
val count = text(
text = "Count: \${COUNTER_STATE}",
style = TextStyle(color = Color.Hex("#FF0000"))
)
val incrementButton = textButton(
text = "+1",
onClick = semantic { Increment }
)
val decrementButton = textButton(
text = "-1",
onClick = semantic { Decrement }
)
Dynamic
Graph
@Composable
@ComponentBoxExport
fun main() = statefulComponentBoxGraph(init = null) {
Graph(start = CounterOnboardingFlow.value) {
componentBox(CounterLoginScreen.value, LoginScreen())
componentBox(CounterOnboardingFlow.value, OnboardingFlow())
componentBox(CounterScreen.Home.value, HomeScreen())
}
}
Forest
@Composable
fun LoginScreen() = Forest {
tree("heading", Tree { LoginHeading() })
tree("button", Tree { LoginButton() })
}
Trail
@Composable
fun OnboardingFlow() = Trail {
node(WelcomeScreen())
node(FeatureDiscoveryScreen())
node(HomeScreen())
}
Tree
@Composable
fun HomeScreen() = ComponentBox {
Tree {
LazyColumn(
verticalArrangement = Arrangement.SpaceEvenly(2.dp),
horizontalAlignment = Alignment.Start
) {
child(header)
child(Count())
child(IncrementButton())
child(DecrementButton())
}
}
}
@Composable
fun IncrementButton() = StatefulComposable<Counter> {
ContainedButton(onClick = lambda { it.on(Increment) }) {
text(text = "+1")
}
}
@Composable
fun DecrementButton() = StatefulComposable<Counter> {
ContainedButton(onClick = lambda { it.on(Decrement) }) {
text(text = "-1")
}
}
@Composable
fun Count() = StatefulComposable<Counter> {
text(
text = "Count: ${it.state.value}",
style = TextStyle(color = Color.Hex("#FF0000"))
)
}
Binaries (server)
./gradlew componentBoxJs
./gradlew componentBoxJson
Jetpack Compose (Android)
Activity
class ComponentBoxActivity : ComponentActivity() {
private val scope = CoroutineScope(Dispatchers.Default)
private val service = ComponentBoxService(scope)
private val componentBox = service.componentBox
private val render = RenderingEngine()
override fun onStart() {
super.onStart()
service.launch(MANIFEST_URL)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
val root = componentBox.collectAsState()
render {
root.value
}
}
}
}
Composable
@Composable
fun ComponentBoxView(componentBox: StateFlow<Component?>, render: RenderingEngine) {
val root = componentBox.collectAsState()
render {
root.value
}
}
React (web)
export default function ComponentBoxView(props: {manifestUrl: string}) {
const [root, setRoot] = useState<Component | null>(null);
const service = new ComponentBoxService();
const render = new RenderingEngine();
useEffect(() => {
async function launch(manifestUrl: string): Tree {
const componentBox = await service.launch(manifestUrl)
setRoot(componentBox.root)
}
launch(props.manifestUrl)
}, [props.manifestUrl]);
return render(root)
}
SwiftUI (iOS)
struct ComponentBoxView: View {
@StateObject private var service = ComponentBoxService()
@State private var root: Component?
var body: some View {
render {
root
}
.onAppear {
service.launch(from: MANIFEST_URL) { result in
switch result {
case .success(let componentBox):
DispatchQueue.main.async {
self.root = componentBox.root
}
}
}
}
}
Snapshots
Snapshots are available
in Sonatype's snapshots repository.
License
Copyright (c) 2023 Dropbox, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Acknowledgments
| Thanks to our friends at Cash App for Zipline |
|---|
Similar Libraries
Circuit
⚡️ A Compose-driven architecture for Kotlin and Android applications.
Compose MultiplatformKotlin Multiplatform
yakcov
Yet Another Kotlin Compose Validation library
Kotlin MultiplatformValidation
Decompose
Kotlin Multiplatform lifecycle-aware business logic components with routing functionality.
ArchitectureNavigation
Browse by Category

Be the first to discover new Compose libraries
Curated Insights
Digest in 5 minutes or less
Android Analysis
Entertaining takes on happenings
Insider Tips
From top Android developers
Hidden Gems
You won't find elsewhere
"
"I truly love this newsletter ❤️🔥 Spot on content and I know there's a lot of effort that goes behind it. Great work!"
— theapache64
Staff Software Engineer @ Disney+ Hotstar
Join thousands of Android devs who look forward to Dispatch every week
© 2026 All Rights Reserved | Made by Vinay Gaba
