fix(ui): default disable clickable display text

This commit is contained in:
Ash 2024-06-28 17:00:27 +08:00
parent 98fe9470c3
commit f8be59e610
No known key found for this signature in database
2 changed files with 12 additions and 9 deletions

View File

@ -1,9 +1,7 @@
package me.ash.reader.ui.component.base
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
@ -11,13 +9,14 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import me.ash.reader.ui.ext.roundClick
@Composable
fun DisplayText(
modifier: Modifier = Modifier,
text: String,
desc: String,
onTextClick: () -> Unit = {},
onTextClick: (() -> Unit)? = null,
) {
Column(
modifier = modifier
@ -30,7 +29,7 @@ fun DisplayText(
)
) {
Text(
modifier = Modifier.clickable { onTextClick() },
modifier = Modifier.roundClick(enabled = onTextClick != null) { onTextClick?.invoke() },
text = text,
style = MaterialTheme.typography.displaySmall,
color = MaterialTheme.colorScheme.onSurface,

View File

@ -3,11 +3,16 @@ package me.ash.reader.ui.ext
import android.annotation.SuppressLint
import android.view.HapticFeedbackConstants
import android.view.SoundEffectConstants
import androidx.compose.foundation.*
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.LocalIndication
import androidx.compose.foundation.clickable
import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.indication
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.PressInteraction
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.pager.PagerState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
@ -19,7 +24,6 @@ import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.lerp
import androidx.compose.foundation.pager.PagerState
import kotlin.math.absoluteValue
@OptIn(ExperimentalFoundationApi::class)
@ -39,9 +43,9 @@ fun Modifier.pagerAnimate(pagerState: PagerState, page: Int): Modifier {
}
}
fun Modifier.roundClick(onClick: () -> Unit = {}) = this
fun Modifier.roundClick(enabled: Boolean = true, onClick: () -> Unit = {}) = this
.clip(RoundedCornerShape(8.dp))
.clickable(onClick = onClick)
.clickable(enabled = enabled, onClick = onClick)
fun Modifier.paddingFixedHorizontal(top: Dp = 0.dp, bottom: Dp = 0.dp) = this
.padding(horizontal = 10.dp)