Skip to content

Commit

Permalink
Merge pull request #9 from makeevrserg/fix-modal-bottom-sheet
Browse files Browse the repository at this point in the history
fix modal bottom sheet
  • Loading branch information
makeevrserg committed Jun 20, 2024
2 parents 6f97853 + 4a7732f commit 2a7ae7e
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 159 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ makeevrserg.android.sdk.target=34
# Project
makeevrserg.project.name=ApplicationTemplate
makeevrserg.project.group=com.makeevrserg.applicationtemplate
makeevrserg.project.version.string=1.2.2
makeevrserg.project.version.code=14
makeevrserg.project.version.string=1.2.3
makeevrserg.project.version.code=15
makeevrserg.project.description=Template for KMP applcation
makeevrserg.project.developers=makeevrserg|Makeev Roman|makeevrserg@gmail.com
makeevrserg.project.url=https://github.com/makeevrserg/KMP-Template
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,11 @@ class MainActivity : ComponentActivity() {
val rootBottomSheetComponent = rootComponent.rootBottomSheetComponent
setContent {
ApplicationTheme(rootModule.themeSwitcherModule.themeSwitcherComponent) {
RootBottomSheetContent(rootBottomSheetComponent) {
RootScreenContent(
rootComponent = rootComponent,
modifier = Modifier
)
}
RootBottomSheetContent(rootBottomSheetComponent)
RootScreenContent(
rootComponent = rootComponent,
modifier = Modifier
)
}
}
splashScreen.setKeepOnScreenCondition { false }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.makeevrserg.applicationtemplate.mobile.features.info.ui

import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
Expand All @@ -19,29 +18,19 @@ import com.makeevrserg.applicationtemplate.mobile.core.ui.theme.AdaptThemeFade
import com.makeevrserg.applicationtemplate.mobile.core.ui.theme.AppTheme
import com.makeevrserg.applicationtemplate.mobile.core.ui.util.asComposableString
import com.makeevrserg.applicationtemplate.mobile.features.info.linkbrowser.LinkBrowser
import com.makeevrserg.applicationtemplate.mobile.features.info.ui.components.BottomSheetIndicator
import com.makeevrserg.applicationtemplate.mobile.features.info.ui.components.LinkWidget
import com.makeevrserg.applicationtemplate.mobile.features.info.ui.components.rememberLinkBrowser
import com.makeevrserg.applicationtemplate.mobile.features.info.ui.data.InfoScreenLinks
import com.makeevrserg.applicationtemplate.modules.services.build.konfig.BuildKonfig
import com.makeevrserg.applicationtemplate.modules.services.core.resources.CoreR

@Composable
fun InfoScreen(
isBottomSheet: Boolean
) {
fun InfoScreen() {
val linkBrowser: LinkBrowser = rememberLinkBrowser()
val models = remember { InfoScreenLinks.get() }
LazyColumn(
modifier = Modifier
.navBarsPadding()
.padding(horizontal = AppTheme.dimens.S)
modifier = Modifier.padding(horizontal = AppTheme.dimens.S)
) {
if (isBottomSheet) {
item {
BottomSheetIndicator()
}
}
item {
Text(
text = CoreR.strings.info_more_links.asComposableString(),
Expand All @@ -64,7 +53,7 @@ fun InfoScreen(
)
}
item {
Spacer(modifier = Modifier.height(AppTheme.dimens.M))
Spacer(modifier = Modifier.navBarsPadding())
}
}
}
Expand All @@ -73,6 +62,6 @@ fun InfoScreen(
@Composable
private fun InfoScreenPreview() {
AdaptThemeFade {
InfoScreen(isBottomSheet = false)
InfoScreen()
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,39 +1,26 @@
package com.makeevrserg.applicationtemplate.mobile.features.modal.ui

import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.MaterialTheme
import androidx.compose.material.ModalBottomSheetLayout
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import com.arkivanov.decompose.extensions.compose.subscribeAsState
import com.makeevrserg.applicationtemplate.mobile.core.ui.components.rememberDeclarativeModalBottomSheetState
import com.makeevrserg.applicationtemplate.mobile.core.ui.theme.AppTheme
import com.makeevrserg.applicationtemplate.mobile.core.ui.components.bottomsheet.SlotModalBottomSheet
import com.makeevrserg.applicationtemplate.mobile.features.info.ui.InfoScreen
import com.makeevrserg.applicationtemplate.mobile.features.modal.presentation.RootBottomSheetComponent

@OptIn(ExperimentalMaterialApi::class)
@Composable
fun RootBottomSheetContent(
rootBottomSheetComponent: RootBottomSheetComponent,
content: @Composable () -> Unit
) {
val slot by rootBottomSheetComponent.childSlot.subscribeAsState()
val bottomSheetState = rememberDeclarativeModalBottomSheetState(
child = slot.child,
onDismiss = rootBottomSheetComponent::dismiss
) { child ->
when (val instance = child.instance) {
is RootBottomSheetComponent.Child.Info -> {
InfoScreen(isBottomSheet = true)
SlotModalBottomSheet(
childSlot = slot,
onDismiss = rootBottomSheetComponent::dismiss,
content = { child ->
when (child) {
is RootBottomSheetComponent.Child.Info -> {
InfoScreen()
}
}
}
}
ModalBottomSheetLayout(
sheetState = bottomSheetState.sheetState,
sheetContent = bottomSheetState.sheetContent.value,
sheetShape = RoundedCornerShape(AppTheme.dimens.S),
sheetBackgroundColor = MaterialTheme.colors.primary,
content = content
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.LinearProgressIndicator
import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.scale
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
Expand Down Expand Up @@ -77,6 +79,7 @@ fun SplashScreenComponent(
.width(64.dp)
.wrapContentHeight()
.scale(scale)
.clip(CircleShape)
.clickable { onIconClicked.invoke() }
)
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.makeevrserg.applicationtemplate.mobile.core.ui.components.bottomsheet

import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.rememberModalBottomSheetState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.snapshotFlow
import com.arkivanov.decompose.router.slot.ChildSlot
import com.makeevrserg.applicationtemplate.mobile.core.ui.components.bottomsheet.util.zero
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.drop

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun <T : Any, K : Any> SlotModalBottomSheet(
childSlot: ChildSlot<T, K>,
skipPartiallyExpanded: Boolean = true,
onDismiss: () -> Unit,
content: @Composable ColumnScope.(K) -> Unit
) {
val child = childSlot.child?.instance
val sheetState = rememberModalBottomSheetState(
skipPartiallyExpanded = skipPartiallyExpanded,
confirmValueChange = {
true
}
)

LaunchedEffect(sheetState) {
snapshotFlow { sheetState.isVisible }
.distinctUntilChanged()
.drop(1)
.collect { visible ->
if (!visible) {
onDismiss.invoke()
}
}
}

if (child != null) {
ModalBottomSheet(
onDismissRequest = { onDismiss.invoke() },
sheetState = sheetState,
windowInsets = WindowInsets.zero,
content = {
content.invoke(this, child)
}
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.makeevrserg.applicationtemplate.mobile.core.ui.components.bottomsheet.util

import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.LayoutDirection

internal val WindowInsets.Companion.zero: WindowInsets
get() = object : WindowInsets {
override fun getBottom(density: Density): Int = 0

override fun getLeft(density: Density, layoutDirection: LayoutDirection): Int = 0

override fun getRight(density: Density, layoutDirection: LayoutDirection): Int = 0

override fun getTop(density: Density): Int = 0
}

0 comments on commit 2a7ae7e

Please sign in to comment.