Skip to content

Commit

Permalink
refactor: Rename rememberSaveableWithVolatileInitialValue to remember…
Browse files Browse the repository at this point in the history
…VolatileSaveable

Renamed the `rememberSaveableWithVolatileInitialValue` function to `rememberVolatileSaveable` for better clarity and conciseness.
Updated usage of the function in `PreConfiguredOutlinedTextField` and `SpMetadataBsDetails` composables.
  • Loading branch information
BobbyESP committed Nov 27, 2024
1 parent c19b674 commit e33cab2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import com.bobbyesp.metadator.presentation.pages.utilities.tageditor.spotify.Met
import com.bobbyesp.ui.components.button.BackButton
import com.bobbyesp.ui.components.others.SelectableSurface
import com.bobbyesp.ui.components.text.MarqueeText
import com.bobbyesp.ui.util.rememberSaveableWithVolatileInitialValue
import com.bobbyesp.ui.util.rememberVolatileSaveable

@Composable
fun SpMetadataBsDetails(
Expand Down Expand Up @@ -225,7 +225,7 @@ private fun SelectableMetadataField(
onSelectMetadata: (title: String, value: String) -> Unit,
onDeleteMetadata: (title: String) -> Unit
) {
var isSelected by rememberSaveableWithVolatileInitialValue(initialValue = false)
var isSelected by rememberVolatileSaveable(initialValue = false)
SelectableSurface(
modifier = modifier,
isSelected = isSelected,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow
import com.bobbyesp.ui.R
import com.bobbyesp.ui.util.rememberSaveableWithVolatileInitialValue
import com.bobbyesp.ui.util.rememberVolatileSaveable

@Composable
fun PreConfiguredOutlinedTextField(
Expand All @@ -35,7 +35,7 @@ fun PreConfiguredOutlinedTextField(
minLines: Int = 1,
returnModifiedValue: (String) -> Unit = {}
) {
val (text, setText) = rememberSaveableWithVolatileInitialValue(value ?: "")
val (text, setText) = rememberVolatileSaveable(value ?: "")
val originalValue = remember { value ?: "" }

OutlinedTextField(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import androidx.compose.runtime.saveable.rememberSaveable
* Allows to create a saveable with an initial value where updating the initial value will lead to updating the
* state *even if* the composable gets restored from saveable later on.
*
* rememberSaveableWithInitialValue should be used in a composable, when you want to initialize a mutable state
* rememberVolatileSaveable should be used in a composable, when you want to initialize a mutable state
* (e.g. for holding the value of a textinput field) with an initial value AND need the user input to survive
* configuration changes AND want to allow changes to the initial value while being on a later screen
* (i.e. while this composable is not active).
*/
@Composable
fun <T : Any?> rememberSaveableWithVolatileInitialValue(
fun <T : Any?> rememberVolatileSaveable(
initialValue: T?,
saver: Saver<T?, out Any> = autoSaver()
): MutableState<T?> {
Expand All @@ -33,14 +33,14 @@ fun <T : Any?> rememberSaveableWithVolatileInitialValue(
* Allows to create a saveable with an initial value where updating the initial value will lead to updating the
* state *even if* the composable gets restored from saveable later on.
*
* rememberSaveableWithInitialValue should be used in a composable, when you want to initialize a mutable state
* rememberVolatileSaveable should be used in a composable, when you want to initialize a mutable state
* (e.g. for holding the value of a textinput field) with an initial value AND need the user input to survive
* configuration changes AND want to allow changes to the initial value while being on a later screen
* (i.e. while this composable is not active).
*/
@JvmName("rememberSaveableWithVolatileInitialValueNotNull")
@Composable
fun <T : Any> rememberSaveableWithVolatileInitialValue(
fun <T : Any> rememberVolatileSaveable(
initialValue: T,
saver: Saver<T, out Any> = autoSaver()
): MutableState<T> {
Expand Down

0 comments on commit e33cab2

Please sign in to comment.