Skip to content

Instantly share code, notes, and snippets.

@rock3r
Created May 23, 2022 15:01
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rock3r/066bc88c376b871bcd1f3402cf27a3a0 to your computer and use it in GitHub Desktop.
Save rock3r/066bc88c376b871bcd1f3402cf27a3a0 to your computer and use it in GitHub Desktop.
rms — live template to insert/surround with "val ... by remember { mutableStateOf(...) }"
<template name="rms" value="val $name$ by androidx.compose.runtime.remember { androidx.compose.runtime.mutableStateOf($SELECTION$$END$) }" description="Remember mutableState" toReformat="false" toShortenFQNames="true">
<variable name="name" expression="kotlinSuggestVariableName()" defaultValue="name" alwaysStopAt="true" />
<context>
<option name="KOTLIN_EXPRESSION" value="true" />
</context>
</template>
@rock3r
Copy link
Author

rock3r commented May 23, 2022

Remember Mutable State

This is an IJ/AS live template to insert/surround with val ... by remember { mutableStateOf(...) }.

Installing on your IDE

  1. Copy the entirety of the template
  2. Open Settings >Editor > Live Templates
  3. Select (or create) the group where to add this. I recommend the "AndroidCompose" group
  4. Paste the template (using ctrl/cmd + V, or the context menu)

Using the live template

You can create a new variable by typing rms in the editor then pressing the expansion key (Tab by default), or surround an existing value with the "Surround with Live Template" action (Ctrl + Alt + J on Windows and Linux, Cmd + Alt + J on macOS)

rms-demo.mp4

License

This live template is freely usable by anyone, although I'd appreciate a shout out if you end up embedding it or using this idea.

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