Skip to content

Commit

Permalink
fix(ui): default disable clickable display text
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashinch committed Jun 28, 2024
1 parent 98fe947 commit f8be59e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
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
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
Expand All @@ -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,
Expand Down
14 changes: 9 additions & 5 deletions app/src/main/java/me/ash/reader/ui/ext/ModifierExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -114,4 +118,4 @@ fun Modifier.combinedFeedbackClickable(
},
)
}
}
}

0 comments on commit f8be59e

Please sign in to comment.