Reputation: 1
Each time, I need to create a composable function, I do:
Right click on a package -> New -> Kotlin Class/File
And I end up with this:
class MyClass {}
Now I have to do three changes manually:
@Composable
annotationclass
with fun
constructor
And this is really annoying. But this is the result:
@Composable
fun MyClass(
//Add arguments
) {
//Add logic
}
How can I do this operation quicker? Is there any shortcut in Android Studio? I couldn't find anything in the menu.
Upvotes: 9
Views: 1816
Reputation: 11
below template would suffice
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME}
#end #parse("File Header.java")
import androidx.compose.runtime.Composable
@Composable #set($capitalizedFilename = $NAME.substring(0,1).toUpperCase() + $NAME.substring(1)) fun $capitalizedFilename() {
}
Upvotes: 1
Reputation: 3682
You can define you own template for this:
+
icon to add a new templateMy Composable template
or whatever you likekt
Then, instead of New > Kotlin Class you can click New > My Composable template (or whatever you named it), and you start without the extra manual steps.
Upvotes: 9