Skip to content

Commit

Permalink
Merge pull request #648 from DimensionDev/bugfix/misskey_emoji
Browse files Browse the repository at this point in the history
fix misskey emoji does not show up
  • Loading branch information
Tlaster authored Jan 10, 2025
2 parents 71f102e + 0ffb9ce commit 9ce82e0
Show file tree
Hide file tree
Showing 11 changed files with 174 additions and 52 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// Dirty hack for material 3 bottom sheet navigation
// Google just doesn't want to make a Material 3 bottom sheet navigation,
// just like the Material 3 pull-to-refresh before. Only after I urged them
// at the offline Google I/O 2023 Shanghai event did they hastily release a
// version copied from Material 2 code. And even after more than a year,
// there's still no definition of pull-to-refresh in the Material You
// specification.

@file:SuppressLint("RestrictedApi")

package com.ramcosta.composedestinations.bottomsheet.spec

import android.annotation.SuppressLint
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.navigation.NavBackStackEntry
import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavHostController
import com.ramcosta.composedestinations.manualcomposablecalls.DestinationLambda
import com.ramcosta.composedestinations.manualcomposablecalls.ManualComposableCalls
import com.ramcosta.composedestinations.manualcomposablecalls.allDeepLinks
import com.ramcosta.composedestinations.navigation.DependenciesContainerBuilder
import com.ramcosta.composedestinations.scope.BottomSheetDestinationScope
import com.ramcosta.composedestinations.scope.BottomSheetNavGraphBuilderDestinationScope
import com.ramcosta.composedestinations.scope.DestinationScopeImpl
import com.ramcosta.composedestinations.scope.NavGraphBuilderDestinationScopeImpl
import com.ramcosta.composedestinations.spec.DestinationStyle
import com.ramcosta.composedestinations.spec.TypedDestinationSpec
import com.stefanoq21.material3.navigation.bottomSheet

object DestinationStyleBottomSheet : DestinationStyle() {
override fun <T> NavGraphBuilder.addComposable(
destination: TypedDestinationSpec<T>,
navController: NavHostController,
dependenciesContainerBuilder: @Composable DependenciesContainerBuilder<*>.() -> Unit,
manualComposableCalls: ManualComposableCalls,
) {
@Suppress("UNCHECKED_CAST")
val contentWrapper = manualComposableCalls[destination.route] as? DestinationLambda<T>?

bottomSheet(
route = destination.route,
arguments = destination.arguments,
deepLinks = destination.allDeepLinks(manualComposableCalls),
) { navBackStackEntry ->
CallComposable(
destination,
navController,
navBackStackEntry,
dependenciesContainerBuilder,
contentWrapper,
)
}
}
}

@Composable
private fun <T> ColumnScope.CallComposable(
destination: TypedDestinationSpec<T>,
navController: NavHostController,
navBackStackEntry: NavBackStackEntry,
dependenciesContainerBuilder: @Composable DependenciesContainerBuilder<*>.() -> Unit,
contentWrapper: DestinationLambda<T>?,
) {
val scope =
remember(destination, navBackStackEntry, navController, this, dependenciesContainerBuilder) {
BottomSheetDestinationScopeImpl(
destination,
navBackStackEntry,
navController,
this,
dependenciesContainerBuilder,
)
}

if (contentWrapper == null) {
with(destination) { scope.Content() }
} else {
contentWrapper(scope)
}
}

internal class BottomSheetDestinationScopeImpl<T>(
override val destination: TypedDestinationSpec<T>,
override val navBackStackEntry: NavBackStackEntry,
override val navController: NavController,
columnScope: ColumnScope,
override val dependenciesContainerBuilder: @Composable DependenciesContainerBuilder<*>.() -> Unit,
) : DestinationScopeImpl<T>(),
BottomSheetDestinationScope<T>,
ColumnScope by columnScope

internal class BottomSheetNavGraphBuilderDestinationScopeImpl<T>(
override val destination: TypedDestinationSpec<T>,
override val navBackStackEntry: NavBackStackEntry,
columnScope: ColumnScope,
) : NavGraphBuilderDestinationScopeImpl<T>(),
BottomSheetNavGraphBuilderDestinationScope<T>,
ColumnScope by columnScope
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,14 @@ private fun StatusReactionComponent(
reaction.onClicked.invoke()
}.padding(horizontal = 8.dp, vertical = 4.dp),
) {
EmojiImage(
uri = reaction.url,
modifier = Modifier.height(16.dp),
)
if (reaction.isUnicode) {
Text(reaction.name)
} else {
EmojiImage(
uri = reaction.url,
modifier = Modifier.height(16.dp),
)
}
Spacer(modifier = Modifier.width(4.dp))
Text(
text = reaction.humanizedCount,
Expand Down
25 changes: 16 additions & 9 deletions app/src/main/java/dev/dimension/flare/ui/screen/home/HomeScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,10 @@ internal fun Router(
modifier: Modifier = Modifier,
dependenciesContainerBuilder: @Composable DependenciesContainerBuilder<*>.() -> Unit = {},
) {
val innerNavController = rememberNavController()
val bottomSheetNavigator =
com.stefanoq21.material3.navigation
.rememberBottomSheetNavigator()
val innerNavController = rememberNavController(bottomSheetNavigator)
val uriHandler = LocalUriHandler.current
CompositionLocalProvider(
LocalUriHandler provides
Expand All @@ -672,14 +675,18 @@ internal fun Router(
)
},
) {
DestinationsNavHost(
modifier = modifier,
navController = innerNavController,
navGraph = navGraph,
defaultTransitions = rememberNavAnimX(),
start = direction,
dependenciesContainerBuilder = dependenciesContainerBuilder,
)
com.stefanoq21.material3.navigation.ModalBottomSheetLayout(
bottomSheetNavigator = bottomSheetNavigator,
) {
DestinationsNavHost(
modifier = modifier,
navController = innerNavController,
navGraph = navGraph,
defaultTransitions = rememberNavAnimX(),
start = direction,
dependenciesContainerBuilder = dependenciesContainerBuilder,
)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,18 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.material3.Card
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.annotation.RootGraph
import com.ramcosta.composedestinations.annotation.parameters.DeepLink
import com.ramcosta.composedestinations.annotation.parameters.FULL_ROUTE_PLACEHOLDER
import com.ramcosta.composedestinations.bottomsheet.spec.DestinationStyleBottomSheet
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
import com.ramcosta.composedestinations.spec.DestinationStyle
import dev.dimension.flare.common.AppDeepLink
import dev.dimension.flare.model.AccountType
import dev.dimension.flare.model.MicroBlogKey
Expand All @@ -30,7 +28,7 @@ import dev.dimension.flare.ui.presenter.status.action.MisskeyReactionPresenter
import moe.tlaster.precompose.molecule.producePresenter

@Destination<RootGraph>(
style = DestinationStyle.Dialog::class,
style = DestinationStyleBottomSheet::class,
deepLinks = [
DeepLink(
uriPattern = "flare://$FULL_ROUTE_PLACEHOLDER",
Expand All @@ -47,15 +45,11 @@ internal fun MisskeyReactionRoute(
accountKey: MicroBlogKey,
navigator: DestinationsNavigator,
) {
Dialog(onDismissRequest = navigator::navigateUp) {
Card {
MisskeyReactionSheet(
statusKey = statusKey,
onBack = navigator::navigateUp,
accountType = AccountType.Specific(accountKey),
)
}
}
MisskeyReactionSheet(
statusKey = statusKey,
onBack = navigator::navigateUp,
accountType = AccountType.Specific(accountKey),
)
}

@Composable
Expand Down
4 changes: 3 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ accompanist-permissions = { group = "com.google.accompanist", name = "accompanis
accompanist-drawablepainter = { group = "com.google.accompanist", name = "accompanist-drawablepainter", version.ref = "accompanist" }

compose-destinations = { group = "io.github.raamcosta.compose-destinations", name = "core", version.ref = "compose-destinations" }
compose-destinations-bottom-sheet = { group = "io.github.raamcosta.compose-destinations", name = "bottom-sheet", version.ref = "compose-destinations" }
compose-destinations-ksp = { group = "io.github.raamcosta.compose-destinations", name = "ksp", version.ref = "compose-destinations" }
material3-navigation = { group = "io.github.stefanoq21", name = "material3-navigation", version = "0.0.12" }

compose-lint-checks = { group = "com.slack.lint.compose", name = "compose-lint-checks", version.ref = "compose-lint-checks" }

Expand Down Expand Up @@ -177,7 +179,7 @@ ktor = ["ktor-client-content-negotiation", "ktor-serialization-kotlinx-json", "k
coil3 = ["coil3-compose", "coil3-svg", "coil3-ktor3"]
coil3-extensions = ["apng", "awebp", "vectordrawable-animated", "zoomable-image", "coil3-gif"]
accompanist = ["accompanist-permissions", "accompanist-drawablepainter"]
compose-destinations = ["compose-destinations"]
compose-destinations = ["compose-destinations", "material3-navigation"]
media3 = ["media3-exoplayer", "media3-ui", "media3-hls"]
firebase = ["firebase-analytics-ktx", "firebase-crashlytics-ktx"]
ktorfit = ["ktorfit-lib", "ktorfit-converters-response", "ktorfit-converters-flow", "ktorfit-converters-call"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,5 @@ internal data class Note(
@SerialName(value = "uri") val uri: kotlin.String? = null,
@SerialName(value = "url") val url: kotlin.String? = null,
@SerialName(value = "myReaction") val myReaction: kotlin.String? = null,
@SerialName(value = "emojis") val emojis: Map<kotlin.String, kotlin.String> = emptyMap(),
)
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ internal data class User(
@SerialName(value = "email") val email: kotlin.String? = null,
@SerialName(value = "emailVerified") val emailVerified: kotlin.Boolean? = null,
@SerialName(value = "securityKeysList") val securityKeysList: kotlin.collections.List<kotlin.String>? = null,
@SerialName(value = "emojis") val emojis: Map<kotlin.String, kotlin.String> = emptyMap(),
) {
/**
* *
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ internal data class UserLite(
@SerialName(value = "isModerator") val isModerator: kotlin.Boolean? = false,
@SerialName(value = "isBot") val isBot: kotlin.Boolean? = null,
@SerialName(value = "isCat") val isCat: kotlin.Boolean? = null,
@SerialName(value = "emojis") val emojis: Map<kotlin.String, kotlin.String> = emptyMap(),
) {
/**
* *
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ public data class UiTimeline internal constructor(
val url: String,
val count: Long,
val onClicked: () -> Unit,
// TODO: make EmojiReaction a sealed interface
val isUnicode: Boolean,
) {
val humanizedCount: String by lazy {
count.humanize()
Expand Down
Loading

0 comments on commit 9ce82e0

Please sign in to comment.