Updated on 2026-08-14
This commit is contained in:
parent
1a5401519e
commit
e881eaa3de
17 changed files with 75 additions and 110 deletions
|
|
@ -3,29 +3,52 @@ package com.tangem.core.ui.components.bottomsheets
|
|||
import androidx.compose.foundation.layout.ColumnScope
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.ModalBottomSheet
|
||||
import androidx.compose.material3.SheetState
|
||||
import androidx.compose.material3.rememberModalBottomSheetState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.*
|
||||
import com.tangem.core.ui.res.TangemTheme
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
/**
|
||||
* Tangem bottom sheet with custom draggable header and config
|
||||
*
|
||||
* @param config data model containing logic and ui models
|
||||
* @param config data model containing logic and ui models
|
||||
* @param content custom bottom sheet content
|
||||
*/
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun TangemBottomSheet(
|
||||
inline fun <reified T : TangemBottomSheetConfigContent> TangemBottomSheet(
|
||||
config: TangemBottomSheetConfig,
|
||||
content: @Composable ColumnScope.(TangemBottomSheetConfigContent) -> Unit,
|
||||
crossinline content: @Composable ColumnScope.(T) -> Unit,
|
||||
) {
|
||||
ModalBottomSheet(
|
||||
onDismissRequest = config.onDismissRequest,
|
||||
sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true),
|
||||
containerColor = TangemTheme.colors.background.primary,
|
||||
shape = TangemTheme.shapes.bottomSheetLarge,
|
||||
dragHandle = { TangemBottomSheetDraggableHeader() },
|
||||
) {
|
||||
content(config.content)
|
||||
var isVisible by remember { mutableStateOf(value = config.isShow) }
|
||||
|
||||
val sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)
|
||||
if (isVisible && config.content is T) {
|
||||
ModalBottomSheet(
|
||||
onDismissRequest = config.onDismissRequest,
|
||||
sheetState = sheetState,
|
||||
containerColor = TangemTheme.colors.background.primary,
|
||||
shape = TangemTheme.shapes.bottomSheetLarge,
|
||||
dragHandle = { TangemBottomSheetDraggableHeader() },
|
||||
) {
|
||||
content(config.content)
|
||||
}
|
||||
}
|
||||
|
||||
LaunchedEffect(key1 = config.isShow) {
|
||||
if (config.isShow) {
|
||||
isVisible = true
|
||||
} else {
|
||||
sheetState.collapse { isVisible = false }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
suspend fun SheetState.collapse(onCollapsed: () -> Unit) {
|
||||
coroutineScope {
|
||||
launch { hide() }.invokeOnCompletion { onCollapsed() }
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,9 @@
|
|||
package com.tangem.core.ui.components.bottomsheets
|
||||
|
||||
import androidx.compose.runtime.Immutable
|
||||
|
||||
/**
|
||||
* General interface for bottom sheet config model
|
||||
*/
|
||||
@Immutable
|
||||
interface TangemBottomSheetConfigContent
|
||||
|
|
@ -12,12 +12,8 @@ import com.tangem.core.ui.res.TangemTheme
|
|||
|
||||
@Composable
|
||||
fun ChooseAddressBottomSheet(config: TangemBottomSheetConfig) {
|
||||
if (config.content is ChooseAddressBottomSheetConfig && config.isShow) {
|
||||
TangemBottomSheet(config) { content ->
|
||||
ChooseAddressBottomSheetContent(
|
||||
content = content as ChooseAddressBottomSheetConfig,
|
||||
)
|
||||
}
|
||||
TangemBottomSheet(config) { content: ChooseAddressBottomSheetConfig ->
|
||||
ChooseAddressBottomSheetContent(content = content)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,9 @@ package com.tangem.core.ui.components.bottomsheets.chooseaddress
|
|||
|
||||
import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfigContent
|
||||
import com.tangem.core.ui.components.bottomsheets.tokenreceive.AddressModel
|
||||
import kotlinx.collections.immutable.ImmutableList
|
||||
|
||||
class ChooseAddressBottomSheetConfig(
|
||||
val addressModels: List<AddressModel>,
|
||||
val addressModels: ImmutableList<AddressModel>,
|
||||
val onClick: (AddressModel) -> Unit,
|
||||
) : TangemBottomSheetConfigContent
|
||||
|
|
@ -33,12 +33,8 @@ import com.tangem.core.ui.res.TangemTheme
|
|||
|
||||
@Composable
|
||||
fun TokenReceiveBottomSheet(config: TangemBottomSheetConfig) {
|
||||
if (config.content is TokenReceiveBottomSheetConfig && config.isShow) {
|
||||
TangemBottomSheet(config) { content ->
|
||||
TokenReceiveBottomSheetContent(
|
||||
content = content as TokenReceiveBottomSheetConfig,
|
||||
)
|
||||
}
|
||||
TangemBottomSheet(config) { content: TokenReceiveBottomSheetConfig ->
|
||||
TokenReceiveBottomSheetContent(content = content)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue