-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from makeevrserg/fix-modal-bottom-sheet
fix modal bottom sheet
- Loading branch information
Showing
9 changed files
with
92 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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|[email protected] | ||
makeevrserg.project.url=https://github.com/makeevrserg/KMP-Template | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 0 additions & 39 deletions
39
...akeevrserg/applicationtemplate/mobile/features/info/ui/components/BottomSheetIndicator.kt
This file was deleted.
Oops, something went wrong.
31 changes: 9 additions & 22 deletions
31
...in/com/makeevrserg/applicationtemplate/mobile/features/modal/ui/RootBottomSheetContent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 0 additions & 75 deletions
75
...om/makeevrserg/applicationtemplate/mobile/core/ui/components/SlotModalBottomSheetState.kt
This file was deleted.
Oops, something went wrong.
53 changes: 53 additions & 0 deletions
53
...evrserg/applicationtemplate/mobile/core/ui/components/bottomsheet/SlotModalBottomSheet.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
) | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...vrserg/applicationtemplate/mobile/core/ui/components/bottomsheet/util/ZeroWindowInsets.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |