From 846b71ab28193b1d9ad48cfc7d3836fe417625ab Mon Sep 17 00:00:00 2001 From: Artem Chepurnyi Date: Sun, 17 Nov 2024 09:20:30 +0200 Subject: [PATCH] fix(Desktop): Hide an unsupported option to Share an item --- .../action/showInLargeTypeActionOrNull.kt | 32 +++++++++++-------- .../keyguard/platform/LePlatformUtil.kt | 6 ++++ 2 files changed, 25 insertions(+), 13 deletions(-) create mode 100644 common/src/commonMain/kotlin/com/artemchep/keyguard/platform/LePlatformUtil.kt diff --git a/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/send/action/showInLargeTypeActionOrNull.kt b/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/send/action/showInLargeTypeActionOrNull.kt index 5a820306..82cf0b40 100644 --- a/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/send/action/showInLargeTypeActionOrNull.kt +++ b/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/send/action/showInLargeTypeActionOrNull.kt @@ -8,6 +8,8 @@ import com.artemchep.keyguard.feature.localization.wrap import com.artemchep.keyguard.feature.navigation.NavigationIntent import com.artemchep.keyguard.feature.navigation.state.TranslatorScope import com.artemchep.keyguard.feature.send.add.SendAddRoute +import com.artemchep.keyguard.platform.CurrentPlatform +import com.artemchep.keyguard.platform.hasShareFeature import com.artemchep.keyguard.res.Res import com.artemchep.keyguard.res.* import com.artemchep.keyguard.ui.FlatItemAction @@ -50,16 +52,20 @@ suspend fun createShareAction( translator: TranslatorScope, text: String, navigate: (NavigationIntent) -> Unit, -) = FlatItemAction( - leading = icon(Icons.Outlined.Share), - trailing = { - ChevronIcon() - }, - title = Res.string.text_action_share_with_title.wrap(), - onClick = { - val intent = NavigationIntent.NavigateToShare( - text = text, - ) - navigate(intent) - }, -) +): FlatItemAction? = if (CurrentPlatform.hasShareFeature()) { + FlatItemAction( + leading = icon(Icons.Outlined.Share), + trailing = { + ChevronIcon() + }, + title = Res.string.text_action_share_with_title.wrap(), + onClick = { + val intent = NavigationIntent.NavigateToShare( + text = text, + ) + navigate(intent) + }, + ) +} else { + null +} diff --git a/common/src/commonMain/kotlin/com/artemchep/keyguard/platform/LePlatformUtil.kt b/common/src/commonMain/kotlin/com/artemchep/keyguard/platform/LePlatformUtil.kt new file mode 100644 index 00000000..72a60fb6 --- /dev/null +++ b/common/src/commonMain/kotlin/com/artemchep/keyguard/platform/LePlatformUtil.kt @@ -0,0 +1,6 @@ +package com.artemchep.keyguard.platform + +fun Platform.hasShareFeature(): Boolean = when (this) { + is Platform.Mobile -> true + is Platform.Desktop -> false +}