GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - dropbox/componentbox: Reactive server-driven UI for iOS, Android, and web

This repository was archived by the owner on Mar 6, 2024. It is now read-only.
BranchesTags
Open more actions menu

Latest commit

 

History

205 Commits
205 Commits

Folders and files

NameName
Last commit message
Last commit date
componentbox-gradle-plugin
componentbox-gradle-plugin
 
 
componentbox
componentbox
 
 
gradle
gradle
 
 
model
model
 
 
samples/counter
samples/counter
 
 
zipline
zipline
 
 
.codecov.yml
.codecov.yml
 
 
.gitignore
.gitignore
 
 
CHANGELOG.md
CHANGELOG.md
 
 
CODE_OF_CONDUCT.md
CODE_OF_CONDUCT.md
 
 
LICENSE.txt
LICENSE.txt
 
 
README.md
README.md
 
 
RELEASING.md
RELEASING.md
 
 
build.gradle
build.gradle
 
 
gradle.properties
gradle.properties
 
 
gradlew
gradlew
 
 
gradlew.bat
gradlew.bat
 
 
settings.gradle.kts
settings.gradle.kts
 
 

Repository files navigation

componentbox

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

cashapp Thanks to our friends at Cash App for Zipline

About

Reactive server-driven UI for iOS, Android, and web

dropbox.github.io/componentbox/

Topics

androidcomposeiosjetpackkotlin-multiplatformreactserver-driven-uiswift-ui

Resources

Readme
Apache-2.0 license

Code of conduct

Code of conduct
Activity
Custom properties

Stars

258 stars

Watchers

1 watching

Forks

8 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.