Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import androidx.compose.runtime.mutableFloatStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
Expand Down Expand Up @@ -315,9 +316,10 @@ private fun SwipeToRevealItem(
}
}

val currentOnDelete by rememberUpdatedState(onDelete)
LaunchedEffect(state.currentValue) {
if (state.currentValue == RevealValue.Dismissed) {
onDelete()
currentOnDelete()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fun ContactPermissionScreen(fromOnboarding: Boolean) {
}
}

LaunchedEffect(Unit) {
LaunchedEffect(permissionState.status) {
when (permissionState.status) {
PermissionResult.Granted -> navigator.navigate(
route = AppRoute.Main.Scanner,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fun NotificationPermissionScreen(fromOnboarding: Boolean = false) {
}
}

LaunchedEffect(Unit) {
LaunchedEffect(permissionState.status) {
when (permissionState.status) {
PermissionResult.Granted -> navigator.navigate(
route = AppRoute.Main.Scanner,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.runtime.setValue
import androidx.compose.runtime.snapshotFlow
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
Expand All @@ -63,6 +64,7 @@ import com.getcode.theme.White50
import com.getcode.ui.theme.CodeCircularProgressIndicator
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.launch
import java.util.Timer
import java.util.TimerTask
Expand Down Expand Up @@ -190,26 +192,32 @@ fun SlideToConfirm(
}
}

LaunchedEffect(swipeFraction, enabled) {
when {
!enabled -> hintState.cancelTimer()
swipeFraction == 0f -> hintState.startTimer()
swipeFraction in 0.1f .. 0.99f -> hintState.cancelTimer()
LaunchedEffect(enabled) {
if (!enabled) {
hintState.cancelTimer()
return@LaunchedEffect
}
snapshotFlow { swipeFraction }
.collect { fraction ->
when {
fraction == 0f -> hintState.startTimer()
fraction in 0.1f .. 0.99f -> hintState.cancelTimer()
}
}
}
LaunchedEffect(swipeFraction) {
if (swipeFraction == 1f) {
hapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress)
onConfirm()
// Give the caller a moment to set isLoading = true.
// If they don't, the confirmation was rejected — reset.
// Launch in composeScope so the animation isn't cancelled when
// swipeFraction changes (which would cancel this LaunchedEffect).
delay(200)
if (!currentIsLoading) {
composeScope.launch { swipeState.animateTo(Anchor.Start) }
LaunchedEffect(Unit) {
snapshotFlow { swipeFraction }
.filter { it == 1f }
.collect {
hapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress)
onConfirm()
// Give the caller a moment to set isLoading = true.
// If they don't, the confirmation was rejected — reset.
delay(200)
if (!currentIsLoading) {
composeScope.launch { swipeState.animateTo(Anchor.Start) }
}
}
}
}

// Handle the loading → idle transition (e.g. after a network call completes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.runtime.setValue
import androidx.compose.runtime.snapshotFlow
import androidx.compose.ui.Alignment
Expand Down Expand Up @@ -141,9 +142,10 @@ fun TextInput(
)
}

val currentOnStateChanged by rememberUpdatedState(onStateChanged)
LaunchedEffect(Unit) {
snapshotFlow { state.text }
.onEach { onStateChanged() }
.onEach { currentOnStateChanged() }
.launchIn(this)
}

Expand Down
Loading