Skip to content
Open
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
210 changes: 0 additions & 210 deletions app/src/androidTest/java/dev/simonas/quies/card/CardScreenTest.kt

This file was deleted.

22 changes: 19 additions & 3 deletions app/src/main/java/dev/simonas/quies/UISizing.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,21 @@ fun uiGuide(
spaceHeight: Float,
spaceWidth: Float,
): UiGuide {
val maxCardWidth = 428.77.dp.toPx()
val maxCardHeight = 265.dp.toPx()
// Shrink the card to fit small windows (multi-window, foldables) preserving its aspect
// ratio; a no-op on typical landscape phone displays.
val fitScale = when {
spaceWidth <= 0f || spaceHeight <= 0f -> 1f
else -> minOf(
1f,
(spaceWidth * CARD_MAX_WIDTH_FRAC) / maxCardWidth,
(spaceHeight * CARD_MAX_HEIGHT_FRAC) / maxCardHeight,
)
}
val card = Float2(
x = 428.77.dp.toPx(),
y = 265.dp.toPx(),
x = maxCardWidth * fitScale,
y = maxCardHeight * fitScale,
)
val smallSpace = smallSpacing(
screenHeight = spaceHeight,
Expand All @@ -36,7 +48,9 @@ fun uiGuide(
val minWidthReq = bigSpace + (card.x / 2f) + (card.x / 5f)
if (minWidthReq > (spaceWidth / 2f)) {
val offset = minWidthReq - (spaceWidth / 2f)
bigSpace -= offset
// Never go negative: that would pull "off-screen" cards toward the center and push
// the menu above the top edge.
bigSpace = (bigSpace - offset).coerceAtLeast(0f)
}
return UiGuide(
card = card,
Expand All @@ -48,6 +62,8 @@ fun uiGuide(
}

private const val GOLDEN_RATIO = 1.61803f
private const val CARD_MAX_WIDTH_FRAC = 0.9f
private const val CARD_MAX_HEIGHT_FRAC = 0.85f

private fun bigSpacing(screenHeight: Float, cardHeight: Float): Float {
val freeSpace = screenHeight - cardHeight
Expand Down
50 changes: 21 additions & 29 deletions app/src/main/java/dev/simonas/quies/card/Card.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.tween
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.gestures.awaitEachGesture
import androidx.compose.foundation.gestures.awaitFirstDown
import androidx.compose.foundation.gestures.detectDragGestures
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxHeight
Expand All @@ -19,6 +20,7 @@ import androidx.compose.runtime.Composable
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.ui.Alignment
import androidx.compose.ui.Modifier
Expand All @@ -27,10 +29,6 @@ import androidx.compose.ui.draw.scale
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.input.pointer.PointerEventType.Companion.Exit
import androidx.compose.ui.input.pointer.PointerEventType.Companion.Move
import androidx.compose.ui.input.pointer.PointerEventType.Companion.Press
import androidx.compose.ui.input.pointer.PointerEventType.Companion.Release
import androidx.compose.ui.input.pointer.PointerInputChange
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.platform.testTag
Expand All @@ -41,6 +39,7 @@ import androidx.compose.ui.unit.dp
import dev.simonas.quies.AppTheme
import dev.simonas.quies.LocalUiGuide
import dev.simonas.quies.card.Card.TAG_CENTER_TEXT
import dev.simonas.quies.card.Card.TAG_DESC_TEXT
import dev.simonas.quies.card.Card.TAG_SIDE_TEXT
import dev.simonas.quies.uiglitter.revealingAnnotatedText
import dev.simonas.quies.uiglitter.revealingTextState
Expand All @@ -55,6 +54,7 @@ import dev.simonas.quies.utils.vertical
internal object Card {
const val TAG_CENTER_TEXT = "text_center"
const val TAG_SIDE_TEXT = "text_side"
const val TAG_DESC_TEXT = "text_desc"
}

interface DragListener {
Expand All @@ -73,14 +73,15 @@ internal fun Card(
centerVerticalText: String? = null,
centerVerticalTextAlpha: Float = 1f,
textAlpha: Float = 1f,
isCenterTextVisible: Boolean = textAlpha != 0f,
isCenterTextVisible: Boolean = textAlpha > 0f,
sideTextAlpha: Float = 1f,
color: Color = AppTheme.Color.dating,
onClick: (() -> Unit)? = null,
pointerInputKey: Any = Unit,
dragListener: DragListener? = null,
isTouchScalingEnabled: Boolean = true,
) {
val currentDragListener by rememberUpdatedState(dragListener)
var isTouching: Boolean by remember { mutableStateOf(false) }
val scale: Float by animateFloatAsState(
animationSpec = tween(
Expand Down Expand Up @@ -131,36 +132,27 @@ internal fun Card(
this.shape = shape
this.shadowElevation = shadowElevation.toPx()
}
.pointerInput(Unit) {
.pointerInput(pointerInputKey, dragListener != null) {
if (dragListener != null) {
detectDragGestures(
onDragEnd = dragListener::onStop,
onDragCancel = dragListener::onStop,
onDrag = dragListener::onDrag,
onDragEnd = { currentDragListener?.onStop() },
onDragCancel = { currentDragListener?.onStop() },
onDrag = { change, dragAmount ->
currentDragListener?.onDrag(change, dragAmount)
},
)
}
}
.pointerInput(Unit) {
awaitEachGesture {
while (true) {
val event = awaitPointerEvent()
when (event.type) {
Press -> {
isTouching = true
}

Release -> {
isTouching = false
}

Exit -> {
isTouching = false
}

Move -> {
event.changes
}
awaitFirstDown(requireUnconsumed = false)
isTouching = true
try {
while (awaitPointerEvent().changes.any { it.pressed }) {
// track until every pointer is lifted or the gesture is cancelled
}
} finally {
isTouching = false
}
}
}
Expand All @@ -176,7 +168,7 @@ internal fun Card(
.mutColor(colorTextActivenessMut)
val revealingText = revealingTextState(
text = centerText,
isVisible = textAlpha > 0f,
isVisible = isCenterTextVisible,
)
Text(
modifier = Modifier
Expand Down Expand Up @@ -204,7 +196,7 @@ internal fun Card(
.graphicsLayer {
alpha = centerVerticalTextAlpha
}
.testTag(TAG_SIDE_TEXT),
.testTag(TAG_DESC_TEXT),
style = AppTheme.Text.secondaryDemiBold
.mutColor(colorTextActivenessMut),
text = centerVerticalText,
Expand Down
Loading
Loading