Multiple BottomSheet in one Screen in Jetpack Compose - android

As from ModalBottomSheetLayout doc we have to provide content. If i want to add multiple BottomSheet to a Screen i can't use multiple ModalBottomSheetLayout as same content have to pass multiple times and it will not work.
After searching i have found many are using multiple sheetContent in a single ModalBottomSheetLayout. Just like below way:
sheetContent = {
when (sheetContentState.value) {
0 -> {
BottomSheetFirstScreen()
}
1 -> {
BottomSheetSecondScreen()
}
}
}
For me it become complex as different Sheet configuration using same code. I want to know is there any other better way to load multiple BottomSheet in a Screen.
How about using ModalBottomSheetLayout and BottomSheetScaffold in a single Screen. How to do that.
Thanks in advance.

Related

How to set a fixed header while using LazyColumn?

I'm trying to have a little icon at the top of a LazyColumn that scrolls like any other item in the list. My googling has yielded no luck and I'm wondering if it's even possible yet. Looking for a resource that could help me implement this. To be clear I know stickyHeader exists and that's not what I'm looking for since it will stay at the top of the screen and not scroll with the items.
You can just add another item in the body of the LazyColumn if it's just like any other row and you want it to scroll.
LazyColumn {
item {
Icon()
}
items(myItemList) {
}
}

Android sticky - footer using jetpack compose: Align footer view to table, until it reaches screen size and then become fixed at the bottom

I want to achieve this using jetpack compose.
A is scrollable list of row items. When A is smaller than screen(or parent) size, B(footer) should be placed bellow the last row. When A + B are bigger than screen size, then B becomes fixed at the bottom and A content is scrollable. I'm wondering if there is easy way to achieve this, using compose ConstraintLayout.
I found solution for it. I had to use Modifier.weight(1f, false) at A.
There are many ways to do this but the most efficient way is to use the bottomBar property of Scaffold View.
For example:
#Composable
fun RenderContent() {
Scaffold(
topBar = { /* Your app bar goes here */ },
bottomBar = { /* Anything you place in here will be stick to the bottom. */ }
) {
// ... Rest of the content
// Benefits: If you make the content scrollable and
// the `bottomBar` composable remain on top of the content
}
}
If I understood you correctly you are trying to add a footer view to a LazyColmn. The LazyColumn in JetpackCompose is behaving like the native ListView. I will give an example of a LazyColumn that has a view(composable) at the bottom that is shown when you scroll at the end of the list:
LazyColumn() {
item {
//If you want the first item to stay always on top as you scroll use stickyHeader for this section.
Text("This is the first item")
}
items(listItems.size) {
Text("This is a normal list item")
}
item {
Text("This item will behave as a footer and display at the end of the list")
}
}
Hope this helps somebody.
Thanks

Create full screen bottomsheets with bottomBar in jetpack compose

I do have a requirement in jetpack compose where I need a bottom bar in my scaffold also a bottom sheet with adjustable height. I can achieve only any one of these.
I had to sacrifice the bottom bar with below code:
BottomSheetScaffold(sheetContent = {//anything here})
{ innerPadding -> Box(){}
}
I have no option to use bottom bar here whereas I have the freedom to adjust the height of the sheet. The second solution is using ModalBottomSheetLayout where I can add scaffold inside it and add bottom bar but won't be able to adjust the height of sheet.
ModalBottomSheetLayout(
sheetState = modalBottomSheetState,
sheetContent = {//anything here}
){
Scaffold(
topBar = {
//
},
bottomBar = {
//
},
){
innerPadding -> Box(){}
}
}
Your problem can be possibly solved with BottomSheetScaffold. You can adjust its height in closed position via sheetPeekHeight. To have a bottombar element when the bottom sheet is collapsed, you should read this article and take a look at the related sample. The principle of this solution is to animate the contents of the bottom sheet to bottom bar when it's collapsed, and to animate to the content you want in your bottom sheet when it's opened.
the article that explains the solution, and the sample.
If that doesn't work for you, then you should probably look at your own composable realisation. The requirements for implementing bottom sheet-like functionality are: nestedScroll, swipeable and offset Modifier extensions. How to deal with them you can find here: article about nested scrolling and bottom sheets.

Animate recomposition (view changes) in Jetpack Compose

Is there a way to automatically animate composition changes in a Jetpack Compose #Composable? For instance, if a previously shown widget is removed in a recomposition, can a fade-out animation be applied automatically? I'm thinking something similar to Android View's animateLayoutChanges.
Yes, you can use:
val visible by remember { mutableStateOf(false) }
AnimatedVisibility(visible = visible) {
// Composables Here
}
Or for the specific animation you asked for, surround the Composable (s) with CrossFade

LazyColumn item position

Is there a way to get the value of the y position while the screen is scrolling?
I have a situation like this:
LazyColumn() {
item {
box()
box()
box()
ScrollableTabRow(){}
}
itemsIndexed {...}
I need to know when the ScrollableTabRow moves past a certain position on y axis (for example lets say 100.dp )
I tried working with .scrollable()
(something like scrollable)
and with scroll gesture filter
(something like gesture
and with dragGestureFilter
but i cannot get it to work, am i doing something wrong, or is it just not possible?
Basically what i need to do is for the scrollable tab row to act as sticky header after it touches top of the screen.
What i wanted to do is, after scrollable row touches the top of the screen, create some sort of mockup for it at the top of the screen, but maybe there is some easier way?
App is written strictly in compose, so i dont have access to any of the libraries that provide such implementation
Use stickyHeader.
LazyColumn {
item { ... }
stickyHeader {
ScrollableTabRow(...) { ... }
}
item { ... }
}

Categories

Resources