0

I use this code to generate Compose Screen and add route name to Navigation File

fun RecipeExecutor.customScreenRecipe(
    moduleData: ModuleTemplateData,
    screenName:String,
    includeNavigation:Boolean,
    packageName:String,

){

    val (projectData,srcOut) =moduleData

    addAllKotlinDependencies(moduleData)
    save(CustomScreen(moduleData,screenName, packageName) ,to =srcOut.resolve("ui/screen").resolve("${screenName}Screen.kt"))
    if(includeNavigation)
    {
        save(
            NavigationFile(moduleData, screenName, packageName),
            to = srcOut.resolve("ui/navigation").resolve("Navigation.kt")
        )
    }
    open(srcOut.resolve("ui/screen").resolve("${screenName}Screen.kt"))
}

It generates these two files:

package com.example.myapplication.ui.screen

import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview

@Composable
fun HomeScreenRoute() {
    HomeScreen()
}

@Composable
fun HomeScreen() {

}

@Preview
@Composable
fun PreviewHomeScreen() {
    HomeScreen()
}
package com.example.myapplication.ui.navigation

import com.example.myapplication.ui.screen.*
import androidx.annotation.VisibleForTesting
import androidx.navigation.*
import androidx.navigation.compose.composable

const val homeNavigationRoute = "home_navigation_route"

fun NavGraphBuilder.HomeScreen() {
    composable(homeNavigationRoute) {
        HomeScreen()
    }
}

fun NavController.navigateToHome(navOptions: NavOptions? = null) {
    this.navigate(homeNavigationRoute, navOptions)
}

But when I try to create second screen its say WARN - #c.a.t.i.w.t.Template - WARNING: [The following file could not be created since it already exists: ...\MyApplication3\app\src\main\java\com\example\myapplication\ui\navigation\Navigation.kt

I want like this. If a file exist then edit the existing file by adding line break and new code to the existing file.

How can I do this?

LazyOne
  • 158,824
  • 45
  • 388
  • 391
Masum
  • 85
  • 3
  • 8

0 Answers0