android / android-studio-poet

Large Android projects generator
Apache License 2.0
702 stars 85 forks source link

Add referring composable function from outside modules #158

Closed chao2zhang closed 2 years ago

chao2zhang commented 2 years ago

Summary

The existing Activity0.kt in :applicationModule has the following content:

@Composable
public fun Activity0Screen(): Unit {
  val scrollState = rememberScrollState()
  Column(modifier = Modifier.verticalScroll(scrollState)) {
    Text(text = stringResource(R.string.applicationModulestring0), modifier = Modifier.clickable {
        Foo0().foo9() })
    Image(painter = painterResource(R.drawable.applicationmoduleimage0), contentDescription = null)
  }
}

This does not refer layouts from outside modules. This PR fills the gap by adding the equivalent @Composable function reference from the outside modules.

Additionally, add gradle-profiler benchmark scenarios and shell commands. One of the gradle profiler scenario uses the mutator apply-composable-change-to, which is to be added by https://github.com/gradle/gradle-profiler/pull/357.

Test

Generated the compose project. The generated project works and the content of Activity0.kt in :applicationModule now becomes

@Composable
public fun Activity0Screen(): Unit {
  val scrollState = rememberScrollState()
  Column(modifier = Modifier.verticalScroll(scrollState)) {
    Text(text = stringResource(R.string.applicationModulestring0), modifier = Modifier.clickable {
        Foo0().foo9() })
    Image(painter = painterResource(R.drawable.applicationmoduleimage0), contentDescription = null)
  }
  Activity4Screen()
  com.libraryModule5.Activity4Screen()
  com.libraryModule.Activity4Screen()
  com.libraryModule7.Activity4Screen()
  com.libraryModule4.Activity4Screen()
  com.libraryModule2.Activity4Screen()
  com.libraryModule1.Activity4Screen()
  com.libraryModule8.Activity4Screen()
  com.libraryModule3.Activity4Screen()
}

Although the UI looks strange that all texts and images are stacked together (Otherwise, I am hitting java.lang.IllegalStateException: Nesting scrollable in the same direction layouts like LazyColumn and Column(Modifier.verticalScroll()) is not allowed. If you want to add a header before the list of items please take a look on LazyColumn component which has a DSL api which allows to first add a header via item() function and then the list of items via items().).

borisf commented 2 years ago

Can we add more info about "Additionally, add gradle-profiler benchmark scenarios and shell commands. Note: This depends on gradle/gradle-profiler#357."