Skip to content

[fix] while tapping on prompt screen 2, 3 times -> fast , #73

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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 @@ -93,6 +93,7 @@ import androidx.compose.material3.ripple
import androidx.compose.material3.toShape
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
Expand Down Expand Up @@ -505,16 +506,23 @@ private fun MainCreationPane(
}

PromptType.TEXT.ordinal -> {
TextPrompt(
textFieldState = uiState.descriptionText,
promptGenerationInProgress = uiState.promptGenerationInProgress,
generatedPrompt = uiState.generatedPrompt,
onPromptGenerationPressed = onPromptGenerationPressed,
modifier = Modifier
.fillMaxSize()
.heightIn(min = 200.dp)
.padding(2.dp),
)

val showTextPrompt by remember {
derivedStateOf { pagerState.currentPage == PromptType.TEXT.ordinal && pagerState.targetPage == pagerState.currentPage }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While using pagerState.targetPage == pagerState.currentPage is a valid way to check if a scroll is not in progress, PagerState provides a more idiomatic and readable property for this: isScrollInProgress.

Using !pagerState.isScrollInProgress makes the intent clearer and is generally the preferred way to check if the pager is idle.

Suggested change
derivedStateOf { pagerState.currentPage == PromptType.TEXT.ordinal && pagerState.targetPage == pagerState.currentPage }
derivedStateOf { !pagerState.isScrollInProgress && pagerState.currentPage == PromptType.TEXT.ordinal }

}

if (showTextPrompt) {
TextPrompt(
textFieldState = uiState.descriptionText,
promptGenerationInProgress = uiState.promptGenerationInProgress,
generatedPrompt = uiState.generatedPrompt,
onPromptGenerationPressed = onPromptGenerationPressed,
modifier = Modifier
.fillMaxSize()
.heightIn(min = 200.dp)
.padding(2.dp),
)
}
}
}
}
Expand Down