Skip to content

Instantly share code, notes, and snippets.

@abhishektiwarijr
Created January 18, 2024 14:14
Show Gist options
  • Save abhishektiwarijr/91d6be50400efdb60d8dcf5fb93aee5c to your computer and use it in GitHub Desktop.
Save abhishektiwarijr/91d6be50400efdb60d8dcf5fb93aee5c to your computer and use it in GitHub Desktop.
Compose Live Templates
<templateSet group="Compose">
<template name="compb-fms" value="import androidx.compose.foundation.layout.fillMaxSize&#10;&#10;@androidx.compose.runtime.Composable&#10;fun $NAME$() {&#10;androidx.compose.foundation.layout.Box(&#10; modifier = androidx.compose.ui.Modifier.fillMaxSize()&#10;) {&#10; $END$ &#10;}&#10;}" description="Composable with a Box Parent with modifier fillMaxSize" toReformat="true" toShortenFQNames="true">
<variable name="NAME" expression="" defaultValue="" alwaysStopAt="true" />
<context>
<option name="KOTLIN" value="true" />
<option name="KOTLIN_COMMENT" value="false" />
</context>
</template>
<template name="compb-fmw" value="import androidx.compose.foundation.layout.fillMaxWidth&#10;&#10;@androidx.compose.runtime.Composable&#10;fun $NAME$() {&#10;androidx.compose.foundation.layout.Box(&#10; modifier = androidx.compose.ui.Modifier.fillMaxWidth()&#10;) {&#10; $END$ &#10;}&#10;}" description="Composable with a Box Parent with modifier fillMaxWidth" toReformat="true" toShortenFQNames="true">
<variable name="NAME" expression="" defaultValue="" alwaysStopAt="true" />
<context>
<option name="KOTLIN" value="true" />
<option name="KOTLIN_COMMENT" value="false" />
</context>
</template>
<template name="compc-fms" value="import androidx.compose.foundation.layout.fillMaxSize&#10;&#10;@androidx.compose.runtime.Composable&#10;fun $NAME$() {&#10;androidx.compose.foundation.layout.Column(&#10; modifier = androidx.compose.ui.Modifier.fillMaxSize()&#10;) {&#10; $END$ &#10;}&#10;}" description="Composable with a Column Parent with modifier fillMaxSize" toReformat="true" toShortenFQNames="true">
<variable name="NAME" expression="" defaultValue="" alwaysStopAt="true" />
<context>
<option name="KOTLIN" value="true" />
<option name="KOTLIN_COMMENT" value="false" />
</context>
</template>
<template name="compc-fmw" value="import androidx.compose.foundation.layout.fillMaxWidth&#10;&#10;@androidx.compose.runtime.Composable&#10;fun $NAME$() {&#10;androidx.compose.foundation.layout.Column(&#10; modifier = androidx.compose.ui.Modifier.fillMaxWidth()&#10;) {&#10; $END$ &#10;}&#10;}" description="Composable with a Column Parent with modifier fillMaxWidth" toReformat="true" toShortenFQNames="true">
<variable name="NAME" expression="" defaultValue="" alwaysStopAt="true" />
<context>
<option name="KOTLIN" value="true" />
<option name="KOTLIN_COMMENT" value="false" />
</context>
</template>
<template name="compr-fms" value="import androidx.compose.foundation.layout.fillMaxSize&#10;&#10;@androidx.compose.runtime.Composable&#10;fun $NAME$() {&#10;androidx.compose.foundation.layout.Row(&#10; modifier = androidx.compose.ui.Modifier.fillMaxSize()&#10;) {&#10; $END$ &#10;}&#10;}" description="Composable with a Row Parent with modifier fillMaxSize" toReformat="true" toShortenFQNames="true">
<variable name="NAME" expression="" defaultValue="" alwaysStopAt="true" />
<context>
<option name="KOTLIN" value="true" />
<option name="KOTLIN_COMMENT" value="false" />
</context>
</template>
<template name="compr-fmw" value="import androidx.compose.foundation.layout.fillMaxWidth&#10;&#10;@androidx.compose.runtime.Composable&#10;fun $NAME$() {&#10;androidx.compose.foundation.layout.Row(&#10; modifier = androidx.compose.ui.Modifier.fillMaxWidth()&#10;) {&#10; $END$ &#10;}&#10;}" description="Composable with a Row Parent with modifier fillMaxWidth" toReformat="true" toShortenFQNames="true">
<variable name="NAME" expression="" defaultValue="" alwaysStopAt="true" />
<context>
<option name="KOTLIN" value="true" />
<option name="KOTLIN_COMMENT" value="false" />
</context>
</template>
<template name="lazyc" value="@androidx.compose.runtime.Composable&#10;fun $NAME$() {&#10; val lazyListState = androidx.compose.foundation.lazy.rememberLazyListState()&#10; androidx.compose.foundation.lazy.LazyColumn(&#10; modifier = androidx.compose.ui.Modifier&#10; .fillMaxWidth()&#10; .wrapContentHeight(),&#10; state = lazyListState&#10; ) {&#10; items($DATA$) {&#10; $END$&#10; }&#10; }&#10;}" description="LazyColumn with fillMaxWidth and wrapContentHeight with Lazy List State" toReformat="true" toShortenFQNames="true">
<variable name="NAME" expression="" defaultValue="" alwaysStopAt="true" />
<variable name="DATA" expression="" defaultValue="" alwaysStopAt="true" />
<context>
<option name="KOTLIN" value="true" />
<option name="KOTLIN_COMMENT" value="false" />
</context>
</template>
<template name="lazyr" value="@androidx.compose.runtime.Composable&#10;fun $NAME$() {&#10; val lazyListState = androidx.compose.foundation.lazy.rememberLazyListState()&#10; androidx.compose.foundation.lazy.LazyRow(&#10; modifier = androidx.compose.ui.Modifier&#10; .fillMaxWidth()&#10; .wrapContentHeight(),&#10; state = lazyListState&#10; ) {&#10; items($DATA$) {&#10; $END$&#10; }&#10; }&#10;}" description="LazyRow with fillMaxWidth and wrapContentHeight with Lazy List State" toReformat="true" toShortenFQNames="true">
<variable name="NAME" expression="" defaultValue="" alwaysStopAt="true" />
<variable name="DATA" expression="" defaultValue="" alwaysStopAt="true" />
<context>
<option name="KOTLIN" value="true" />
<option name="KOTLIN_COMMENT" value="false" />
</context>
</template>
</templateSet>
@abhishektiwarijr
Copy link
Author

abhishektiwarijr commented Jan 18, 2024

  1. Just Download the file above.
  2. Unzip it > Compose.xml > Copy it
  3. Paste it inside templates folder located in

Linux : ~/.config/Google/AndroidStudio
Mac : ~/Library/Application\ Support/Google/AndroidStudio/templates
Windows: C:\Users\YourUserName\AppData\Roaming\Google\AndroidStudio

Example : ~/Library/Application\ Support/Google/AndroidStudio2022.3/templates

Then Just Restart Android Studio.

Note: If you can't see templates folder, create one at the specified location and then paste the file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment