Skip to content

Commit c43b984

Browse files
committed
Improve polar/parametric detection
1 parent 661cd30 commit c43b984

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

app/src/main/java/org/nsh07/simplygraph/ui/AppScreen.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import androidx.compose.material3.rememberBottomSheetScaffoldState
4242
import androidx.compose.runtime.Composable
4343
import androidx.compose.runtime.collectAsState
4444
import androidx.compose.runtime.getValue
45+
import androidx.compose.runtime.remember
4546
import androidx.compose.ui.Alignment
4647
import androidx.compose.ui.Modifier
4748
import androidx.compose.ui.draw.clipToBounds
@@ -65,6 +66,12 @@ fun AppScreen(modifier: Modifier = Modifier) {
6566
val graphState by viewModel.graphState.collectAsState()
6667
val functionsState by viewModel.functionsState.collectAsState()
6768

69+
val expandSheet = remember(functionsState.function) {
70+
functionsState.function.matches(
71+
"\\s*r\\s*=\\s*\\S+\\s*|\\s*\\(\\s*\\S+\\s*,\\s*\\S+\\s*\\)\\s*".toRegex()
72+
)
73+
}
74+
6875
val colorScheme = colorScheme
6976
val transformableState = rememberTransformableState { _, offsetChange, _ ->
7077
viewModel.updateOffset(offsetChange)
@@ -79,14 +86,14 @@ fun AppScreen(modifier: Modifier = Modifier) {
7986
val bottomSpacing by animateDpAsState(
8087
if (
8188
scaffoldState.bottomSheetState.targetValue == SheetValue.PartiallyExpanded &&
82-
!functionsState.function.contains("r\\s*=|,".toRegex())
89+
!expandSheet
8390
)
8491
WindowInsets.systemBars.asPaddingValues().calculateBottomPadding() + 16.dp
8592
else 16.dp,
8693
animationSpec = motionScheme.defaultSpatialSpec()
8794
)
8895
val sheetPeekHeight by animateDpAsState(
89-
if (functionsState.function.contains("r\\s*=|,".toRegex())) 164.dp
96+
if (expandSheet) 164.dp
9097
else 64.dp,
9198
animationSpec = motionScheme.defaultSpatialSpec()
9299
)
@@ -109,7 +116,7 @@ fun AppScreen(modifier: Modifier = Modifier) {
109116
shape = shapes.large,
110117
modifier = Modifier.fillMaxWidth()
111118
)
112-
AnimatedVisibility(functionsState.function.contains("r\\s*=|,".toRegex())) {
119+
AnimatedVisibility(expandSheet) {
113120
AnimatedContent(functionsState.function.contains(',')) {
114121
when (it) {
115122
true -> {

0 commit comments

Comments
 (0)