fix: click input in post title and body (#67)

This commit is contained in:
Diego Beraldin 2023-10-25 00:00:11 +02:00 committed by GitHub
parent 9b62258b03
commit 86ff95eff9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 131 additions and 104 deletions

View File

@ -399,19 +399,29 @@ class CommunityDetailScreen(
)
},
content = {
PostCard(modifier = Modifier.onClick {
model.reduce(
CommunityDetailMviModel.Intent.MarkAsRead(
idx
PostCard(
post = post,
postLayout = uiState.postLayout,
fullHeightImage = uiState.fullHeightImages,
separateUpAndDownVotes = uiState.separateUpAndDownVotes,
autoLoadImages = uiState.autoLoadImages,
blurNsfw = when {
stateCommunity.nsfw -> false
else -> uiState.blurNsfw
},
onClick = {
model.reduce(
CommunityDetailMviModel.Intent.MarkAsRead(
idx
)
)
)
navigator?.push(
PostDetailScreen(
post = post,
otherInstance = otherInstance,
),
)
},
navigator?.push(
PostDetailScreen(
post = post,
otherInstance = otherInstance,
),
)
},
onOpenCreator = { user ->
navigator?.push(
UserDetailScreen(
@ -420,24 +430,6 @@ class CommunityDetailScreen(
),
)
},
post = post,
postLayout = uiState.postLayout,
fullHeightImage = uiState.fullHeightImages,
separateUpAndDownVotes = uiState.separateUpAndDownVotes,
autoLoadImages = uiState.autoLoadImages,
options = buildList {
add(stringResource(MR.strings.post_action_share))
add(stringResource(MR.strings.post_action_hide))
add(stringResource(MR.strings.post_action_report))
if (post.creator?.id == uiState.currentUserId && !isOnOtherInstance) {
add(stringResource(MR.strings.post_action_edit))
add(stringResource(MR.strings.comment_action_delete))
}
},
blurNsfw = when {
stateCommunity.nsfw -> false
else -> uiState.blurNsfw
},
onUpVote = {
if (!isOnOtherInstance) {
model.reduce(
@ -493,6 +485,15 @@ class CommunityDetailScreen(
ZoomableImageScreen(url),
)
},
options = buildList {
add(stringResource(MR.strings.post_action_share))
add(stringResource(MR.strings.post_action_hide))
add(stringResource(MR.strings.post_action_report))
if (post.creator?.id == uiState.currentUserId && !isOnOtherInstance) {
add(stringResource(MR.strings.post_action_edit))
add(stringResource(MR.strings.comment_action_delete))
}
},
onOptionSelected = { optionIdx ->
when (optionIdx) {
4 -> model.reduce(

View File

@ -68,6 +68,9 @@ fun InboxCard(
),
text = mention.comment.text,
autoLoadImages = autoLoadImages,
onClick = {
onOpenPost(mention.post)
}
)
}
InboxReplySubtitle(

View File

@ -32,6 +32,7 @@ import androidx.compose.ui.unit.toSize
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.data.PostLayout
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.CornerSize
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
import com.github.diegoberaldin.raccoonforlemmy.core.utils.onClick
import com.github.diegoberaldin.raccoonforlemmy.core.utils.toLocalPixel
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.CommunityModel
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.PostModel
@ -58,6 +59,7 @@ fun PostCard(
onReply: (() -> Unit)? = null,
onImageClick: ((String) -> Unit)? = null,
onOptionSelected: ((Int) -> Unit)? = null,
onClick: (() -> Unit)? = null,
) {
Box(
modifier = modifier.let {
@ -69,7 +71,7 @@ fun PostCard(
} else {
it
}
},
}.onClick { onClick?.invoke() },
) {
if (postLayout != PostLayout.Compact) {
ExtendedPost(
@ -95,6 +97,7 @@ fun PostCard(
onReply = onReply,
onImageClick = onImageClick,
onOptionSelected = onOptionSelected,
onClick = onClick,
)
} else {
CompactPost(
@ -112,6 +115,7 @@ fun PostCard(
onReply = onReply,
onImageClick = onImageClick,
onOptionSelected = onOptionSelected,
onClick = onClick,
)
}
}
@ -134,6 +138,7 @@ private fun CompactPost(
onReply: (() -> Unit)? = null,
onImageClick: ((String) -> Unit)? = null,
onOptionSelected: ((Int) -> Unit)? = null,
onClick: (() -> Unit)? = null,
) {
Column(
modifier = modifier.background(MaterialTheme.colorScheme.background),
@ -156,6 +161,7 @@ private fun CompactPost(
modifier = Modifier.weight(0.75f),
text = post.title,
autoLoadImages = autoLoadImages,
onClick = onClick,
)
}
PostCardImage(
@ -215,6 +221,7 @@ private fun ExtendedPost(
onReply: (() -> Unit)? = null,
onImageClick: ((String) -> Unit)? = null,
onOptionSelected: ((Int) -> Unit)? = null,
onClick: (() -> Unit)? = null,
) {
Column(
modifier = modifier.background(backgroundColor),
@ -236,6 +243,7 @@ private fun ExtendedPost(
),
text = post.title,
autoLoadImages = autoLoadImages,
onClick = onClick,
)
}
@ -276,6 +284,7 @@ private fun ExtendedPost(
},
text = post.text,
autoLoadImages = autoLoadImages,
onClick = onClick,
)
if (limitBodyHeight && textHeightPx >= maxHeightPx) {
Box(

View File

@ -14,6 +14,7 @@ fun PostCardBody(
modifier: Modifier = Modifier,
text: String,
autoLoadImages: Boolean = true,
onClick: (() -> Unit)? = null,
) {
val uriHandler = LocalUriHandler.current
val navigator = remember { getNavigationCoordinator().getRootNavigator() }
@ -36,6 +37,7 @@ fun PostCardBody(
onOpenImage = { url ->
navigator?.push(ZoomableImageScreen(url))
},
onClick = onClick,
)
}
}

View File

@ -13,6 +13,7 @@ fun PostCardTitle(
text: String,
autoLoadImages: Boolean = true,
modifier: Modifier = Modifier,
onClick: (() -> Unit)? = null,
) {
val uriHandler = LocalUriHandler.current
val navigator = remember { getNavigationCoordinator().getRootNavigator() }
@ -29,6 +30,7 @@ fun PostCardTitle(
uriHandler = uriHandler,
navigator = navigator
)
}
},
onClick = onClick,
)
}

View File

@ -307,14 +307,6 @@ class PostDetailScreen(
UserDetailScreen(user = user)
)
},
options = buildList {
add(stringResource(MR.strings.post_action_share))
add(stringResource(MR.strings.post_action_report))
if (statePost.creator?.id == uiState.currentUserId && !isOnOtherInstance) {
add(stringResource(MR.strings.post_action_edit))
add(stringResource(MR.strings.comment_action_delete))
}
},
onUpVote = {
if (!isOnOtherInstance) {
model.reduce(
@ -353,6 +345,14 @@ class PostDetailScreen(
bottomSheetNavigator.show(screen)
}
},
options = buildList {
add(stringResource(MR.strings.post_action_share))
add(stringResource(MR.strings.post_action_report))
if (statePost.creator?.id == uiState.currentUserId && !isOnOtherInstance) {
add(stringResource(MR.strings.post_action_edit))
add(stringResource(MR.strings.comment_action_delete))
}
},
onOptionSelected = { idx ->
when (idx) {
3 -> model.reduce(PostDetailMviModel.Intent.DeletePost)
@ -513,13 +513,6 @@ class PostDetailScreen(
comment = comment,
separateUpAndDownVotes = uiState.separateUpAndDownVotes,
autoLoadImages = uiState.autoLoadImages,
options = buildList {
add(stringResource(MR.strings.post_action_report))
if (comment.creator?.id == uiState.currentUserId) {
add(stringResource(MR.strings.post_action_edit))
add(stringResource(MR.strings.comment_action_delete))
}
},
onUpVote = {
if (!isOnOtherInstance) {
model.reduce(
@ -589,6 +582,13 @@ class PostDetailScreen(
)
}
},
options = buildList {
add(stringResource(MR.strings.post_action_report))
if (comment.creator?.id == uiState.currentUserId) {
add(stringResource(MR.strings.post_action_edit))
add(stringResource(MR.strings.comment_action_delete))
}
},
onOptionSelected = { optionId ->
when (optionId) {
2 -> model.reduce(

View File

@ -223,17 +223,17 @@ class SavedItemsScreen : Screen {
if (uiState.section == SavedItemsSection.Posts) {
itemsIndexed(uiState.posts) { idx, post ->
PostCard(
modifier = Modifier.onClick {
navigator?.push(
PostDetailScreen(post),
)
},
post = post,
postLayout = uiState.postLayout,
fullHeightImage = uiState.fullHeightImages,
separateUpAndDownVotes = uiState.separateUpAndDownVotes,
autoLoadImages = uiState.autoLoadImages,
blurNsfw = uiState.blurNsfw,
onClick = {
navigator?.push(
PostDetailScreen(post),
)
},
onOpenCommunity = { community ->
navigator?.push(
CommunityDetailScreen(community),

View File

@ -379,9 +379,6 @@ class UserDetailScreen(
},
content = {
PostCard(
modifier = Modifier.onClick {
navigator?.push(PostDetailScreen(post = post))
},
post = post,
hideAuthor = true,
postLayout = uiState.postLayout,
@ -389,9 +386,8 @@ class UserDetailScreen(
blurNsfw = uiState.blurNsfw,
separateUpAndDownVotes = uiState.separateUpAndDownVotes,
autoLoadImages = uiState.autoLoadImages,
options = buildList {
add(stringResource(MR.strings.post_action_share))
add(stringResource(MR.strings.post_action_report))
onClick = {
navigator?.push(PostDetailScreen(post = post))
},
onUpVote = if (isOnOtherInstance) {
null
@ -454,6 +450,10 @@ class UserDetailScreen(
ZoomableImageScreen(url),
)
},
options = buildList {
add(stringResource(MR.strings.post_action_share))
add(stringResource(MR.strings.post_action_report))
},
onOptionSelected = { optionIdx ->
when (optionIdx) {
1 -> {

View File

@ -6,6 +6,7 @@ import android.util.TypedValue
import android.view.View
import android.widget.TextView
import androidx.annotation.IdRes
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
@ -47,6 +48,7 @@ actual fun CustomMarkdown(
inlineImages: Boolean,
autoLoadImages: Boolean,
onOpenImage: ((String) -> Unit)?,
onClick: (() -> Unit)?,
) {
CompositionLocalProvider(
LocalReferenceLinkHandler provides ReferenceLinkHandlerImpl(),
@ -58,7 +60,9 @@ actual fun CustomMarkdown(
onOpenUrl = onOpenUrl,
onOpenImage = onOpenImage,
)
BoxWithConstraints {
BoxWithConstraints(
modifier = modifier.clickable { onClick?.invoke() }
) {
val style = LocalMarkdownTypography.current.text
val fontScale = LocalDensity.current.fontScale * 1.25f
val canvasWidthMaybe = with(LocalDensity.current) { maxWidth.toPx() }.toInt()
@ -82,7 +86,11 @@ actual fun CustomMarkdown(
style = style,
typeface = typeface,
fontSize = style.fontSize * fontScale,
)
).apply {
setOnClickListener {
onClick?.invoke()
}
}
},
update = { textView ->
val md = markwonProvider.markwon.toMarkdown(content)
@ -91,7 +99,6 @@ actual fun CustomMarkdown(
}
markwonProvider.markwon.setParsedMarkdown(textView, md)
},
modifier = modifier,
)
}
}

View File

@ -38,6 +38,7 @@ class DefaultMarkwonProvider(
}
}
}
).build()
)
.build()
}
}

View File

@ -37,4 +37,5 @@ expect fun CustomMarkdown(
inlineImages: Boolean = true,
autoLoadImages: Boolean = true,
onOpenImage: ((String) -> Unit)? = null,
onClick: (() -> Unit)? = null,
)

View File

@ -1,5 +1,6 @@
package com.github.diegoberaldin.raccoonforlemmy.core.markdown.compose
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
@ -58,6 +59,7 @@ actual fun CustomMarkdown(
inlineImages: Boolean,
autoLoadImages: Boolean,
onOpenImage: ((String) -> Unit)?,
onClick: (() -> Unit)?,
) {
val matches = Regex("::: spoiler (?<title>.*?)\\n(?<content>.*?)\\n:::\\n").findAll(content)
val mangledContent = buildString {
@ -93,7 +95,7 @@ actual fun CustomMarkdown(
LocalMarkdownColors provides colors,
LocalMarkdownTypography provides typography,
) {
Column(modifier) {
Column(modifier.clickable { onClick?.invoke() }) {
val parsedTree = MarkdownParser(flavour).buildMarkdownTreeFromString(mangledContent)
parsedTree.children.forEach { node ->
if (!node.handleElement(

View File

@ -75,7 +75,6 @@ import com.github.diegoberaldin.raccoonforlemmy.core.commonui.report.CreateRepor
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.userdetail.UserDetailScreen
import com.github.diegoberaldin.raccoonforlemmy.core.notifications.NotificationCenterContractKeys
import com.github.diegoberaldin.raccoonforlemmy.core.notifications.di.getNotificationCenter
import com.github.diegoberaldin.raccoonforlemmy.core.utils.onClick
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.ListingType
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.SortType
import com.github.diegoberaldin.raccoonforlemmy.feature.home.di.getHomeScreenModel
@ -293,27 +292,18 @@ class PostListScreen : Screen {
},
content = {
PostCard(
modifier = Modifier.onClick {
model.reduce(PostListMviModel.Intent.MarkAsRead(idx))
navigator?.push(
PostDetailScreen(post),
)
},
post = post,
postLayout = uiState.postLayout,
fullHeightImage = uiState.fullHeightImages,
separateUpAndDownVotes = uiState.separateUpAndDownVotes,
autoLoadImages = uiState.autoLoadImages,
options = buildList {
add(stringResource(MR.strings.post_action_share))
add(stringResource(MR.strings.post_action_hide))
add(stringResource(MR.strings.post_action_report))
if (post.creator?.id == uiState.currentUserId) {
add(stringResource(MR.strings.post_action_edit))
add(stringResource(MR.strings.comment_action_delete))
}
},
blurNsfw = uiState.blurNsfw,
onClick = {
model.reduce(PostListMviModel.Intent.MarkAsRead(idx))
navigator?.push(
PostDetailScreen(post),
)
},
onOpenCommunity = { community ->
navigator?.push(
CommunityDetailScreen(community),
@ -367,6 +357,15 @@ class PostListScreen : Screen {
ZoomableImageScreen(url),
)
},
options = buildList {
add(stringResource(MR.strings.post_action_share))
add(stringResource(MR.strings.post_action_hide))
add(stringResource(MR.strings.post_action_report))
if (post.creator?.id == uiState.currentUserId) {
add(stringResource(MR.strings.post_action_edit))
add(stringResource(MR.strings.comment_action_delete))
}
},
onOptionSelected = { optionIdx ->
when (optionIdx) {
4 -> model.reduce(

View File

@ -157,11 +157,6 @@ internal object ProfileLoggedScreen : Tab {
}
itemsIndexed(uiState.posts) { idx, post ->
PostCard(
modifier = Modifier.onClick {
navigator?.push(
PostDetailScreen(post),
)
},
post = post,
postLayout = uiState.postLayout,
fullHeightImage = uiState.fullHeightImages,
@ -169,10 +164,10 @@ internal object ProfileLoggedScreen : Tab {
autoLoadImages = uiState.autoLoadImages,
hideAuthor = true,
blurNsfw = false,
options = buildList {
add(stringResource(MR.strings.post_action_share))
add(stringResource(MR.strings.post_action_edit))
add(stringResource(MR.strings.comment_action_delete))
onClick = {
navigator?.push(
PostDetailScreen(post),
)
},
onOpenCommunity = { community ->
navigator?.push(
@ -208,6 +203,11 @@ internal object ProfileLoggedScreen : Tab {
)
)
},
options = buildList {
add(stringResource(MR.strings.post_action_share))
add(stringResource(MR.strings.post_action_edit))
add(stringResource(MR.strings.comment_action_delete))
},
onOptionSelected = { optionIdx ->
when (optionIdx) {
1 -> {

View File

@ -293,17 +293,17 @@ class ExploreScreen : Screen {
is PostModel -> {
PostCard(
modifier = Modifier.onClick {
navigator?.push(
PostDetailScreen(result),
)
},
post = result,
postLayout = uiState.postLayout,
fullHeightImage = uiState.fullHeightImages,
separateUpAndDownVotes = uiState.separateUpAndDownVotes,
autoLoadImages = uiState.autoLoadImages,
blurNsfw = uiState.blurNsfw,
onClick = {
navigator?.push(
PostDetailScreen(result),
)
},
onOpenCommunity = { community ->
navigator?.push(
CommunityDetailScreen(community),

View File

@ -304,23 +304,18 @@ class MultiCommunityScreen(
},
content = {
PostCard(
modifier = Modifier.onClick {
model.reduce(MultiCommunityMviModel.Intent.MarkAsRead(idx))
navigator?.push(
PostDetailScreen(post),
)
},
post = post,
postLayout = uiState.postLayout,
fullHeightImage = uiState.fullHeightImages,
separateUpAndDownVotes = uiState.separateUpAndDownVotes,
autoLoadImages = uiState.autoLoadImages,
options = buildList {
add(stringResource(MR.strings.post_action_share))
add(stringResource(MR.strings.post_action_hide))
add(stringResource(MR.strings.post_action_report))
},
blurNsfw = uiState.blurNsfw,
onClick = {
model.reduce(MultiCommunityMviModel.Intent.MarkAsRead(idx))
navigator?.push(
PostDetailScreen(post),
)
},
onOpenCommunity = { community ->
navigator?.push(
CommunityDetailScreen(community),
@ -374,6 +369,11 @@ class MultiCommunityScreen(
ZoomableImageScreen(url),
)
},
options = buildList {
add(stringResource(MR.strings.post_action_share))
add(stringResource(MR.strings.post_action_hide))
add(stringResource(MR.strings.post_action_report))
},
onOptionSelected = { optionIdx ->
when (optionIdx) {
2 -> {