Skip to content

Instantly share code, notes, and snippets.

@jershell
Created October 23, 2023 13:17
Show Gist options
  • Save jershell/991bf5ee498ebee2b234afca457d2bbe to your computer and use it in GitHub Desktop.
Save jershell/991bf5ee498ebee2b234afca457d2bbe to your computer and use it in GitHub Desktop.
Cargo11.kt
package cargo
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
// Exception in thread "main" java.lang.NullPointerException: Parameter specified as non-null is null:
// method cargo.ComponentScopeImpl.Child, parameter modifier
@Composable
fun Cargo11() {
RootComponent() {
Child(item = "aaa")
Child(item = "bbb")
Child(item = "ccc")
}
}
abstract class ComponentScope() {
@Composable
open fun Child(modifier: Modifier = Modifier.fillMaxWidth(), item: String) {}
}
private object ComponentScopeImpl : ComponentScope() {
@Composable
override fun Child(modifier: Modifier, item: String) {
Column(modifier) {
Text(item)
}
}
}
@Composable
fun RootComponent(content: @Composable ComponentScope.() -> Unit) {
ComponentScopeImpl.content()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment