1
1
package com.guru.composecookbook.ui.home.dialogs
2
2
3
3
4
+ import androidx.compose.foundation.Image
4
5
import androidx.compose.foundation.background
5
6
import androidx.compose.foundation.clickable
7
+ import androidx.compose.foundation.isSystemInDarkTheme
6
8
import androidx.compose.foundation.layout.*
7
9
import androidx.compose.foundation.shape.RoundedCornerShape
8
10
import androidx.compose.material.*
9
11
import androidx.compose.material.icons.Icons
12
+ import androidx.compose.material.icons.filled.FavoriteBorder
10
13
import androidx.compose.material.icons.filled.List
14
+ import androidx.compose.material.icons.filled.PlayArrow
11
15
import androidx.compose.runtime.*
16
+ import androidx.compose.ui.Alignment
12
17
import androidx.compose.ui.Modifier
13
18
import androidx.compose.ui.graphics.Color
19
+ import androidx.compose.ui.layout.ContentScale
20
+ import androidx.compose.ui.res.painterResource
14
21
import androidx.compose.ui.semantics.semantics
15
22
import androidx.compose.ui.semantics.testTag
16
23
import androidx.compose.ui.text.style.TextAlign
17
24
import androidx.compose.ui.tooling.preview.Preview
18
25
import androidx.compose.ui.unit.dp
26
+ import androidx.compose.ui.unit.sp
27
+ import com.guru.composecookbook.spotify.R
28
+ import com.guru.composecookbook.theme.graySurface
29
+ import com.guru.composecookbook.theme.typography
19
30
import com.guru.composecookbook.ui.home.lists.VerticalListView
20
31
import kotlinx.coroutines.CoroutineScope
21
32
import kotlinx.coroutines.launch
@@ -32,26 +43,22 @@ fun BottomSheetLayouts() {
32
43
fun BottomSheetDrawer () {
33
44
val bottomSheetScaffoldState = rememberBottomSheetScaffoldState()
34
45
val coroutineScope = rememberCoroutineScope()
35
- val showCustomScrim = remember { mutableStateOf( false ) }
46
+ val sheetState = rememberModalBottomSheetState(initialValue = ModalBottomSheetValue . Hidden )
36
47
BottomSheetScaffold (
37
48
content = {
38
49
Box {
39
- ScafoldContent (coroutineScope, bottomSheetScaffoldState, showCustomScrim)
40
- if (showCustomScrim.value) {
41
- CustomBottomSheetBackgroundScrim (scaffoldState = bottomSheetScaffoldState)
42
- }
50
+ ScafoldContent (coroutineScope, bottomSheetScaffoldState, sheetState)
43
51
}
44
52
},
45
53
sheetContent = {
46
- BottomSheetContent ()
54
+ PlayerBottomSheet ()
47
55
},
48
56
drawerContent = {
49
57
DrawerContent ()
50
58
},
51
59
scaffoldState = bottomSheetScaffoldState,
52
- sheetPeekHeight = 0 .dp,
53
- sheetElevation = 16 .dp,
54
- sheetShape = RoundedCornerShape (topStart = 16 .dp, topEnd = 16 .dp)
60
+ sheetPeekHeight = if (sheetState.isAnimationRunning || sheetState.isVisible) 0 .dp else 65
61
+ .dp,
55
62
)
56
63
}
57
64
@@ -60,83 +67,60 @@ fun BottomSheetDrawer() {
60
67
private fun ScafoldContent (
61
68
coroutineScope : CoroutineScope ,
62
69
bottomSheetScaffoldState : BottomSheetScaffoldState ,
63
- showCustomScrim : MutableState < Boolean >
70
+ sheetState : ModalBottomSheetState
64
71
) {
65
- Column (modifier = Modifier .fillMaxSize()) {
66
- Button (
67
- modifier = Modifier
68
- .fillMaxWidth()
69
- .padding(16 .dp)
70
- .height(55 .dp),
71
- onClick = {
72
- showCustomScrim.value = false
73
- coroutineScope.launch {
74
- bottomSheetScaffoldState.bottomSheetState.expand()
75
- }
76
- }) {
77
- Text (text = " Bottom Sheet" )
78
- }
79
- Button (
80
- modifier = Modifier
81
- .fillMaxWidth()
82
- .padding(16 .dp)
83
- .height(55 .dp),
84
- onClick = {
85
- coroutineScope.launch {
86
- bottomSheetScaffoldState.drawerState.open()
87
- }
88
- }) {
89
- Text (text = " Navigation Drawer" )
72
+ ModalBottomSheetLayout (
73
+ modifier = Modifier .fillMaxSize(),
74
+ sheetState = sheetState,
75
+ sheetContent = {
76
+ BottomSheetContent ()
90
77
}
91
- Button (
92
- modifier = Modifier
93
- .fillMaxWidth()
94
- .padding(16 .dp)
95
- .height(55 .dp),
96
- onClick = {
97
- showCustomScrim.value = true
98
- coroutineScope.launch {
99
- bottomSheetScaffoldState.bottomSheetState.expand()
100
- }
101
- }) {
102
- Text (text = " BottomSheet + Custom Scrim" )
78
+ ) {
79
+ Column (modifier = Modifier .fillMaxSize()) {
80
+ Button (
81
+ modifier = Modifier
82
+ .fillMaxWidth()
83
+ .padding(16 .dp)
84
+ .height(55 .dp),
85
+ onClick = {
86
+ coroutineScope.launch {
87
+ bottomSheetScaffoldState.drawerState.open()
88
+ }
89
+ }) {
90
+ Text (text = " Navigation Drawer" )
91
+ }
92
+ Button (
93
+ modifier = Modifier
94
+ .fillMaxWidth()
95
+ .padding(16 .dp)
96
+ .height(55 .dp),
97
+ onClick = {
98
+ coroutineScope.launch {
99
+ bottomSheetScaffoldState.bottomSheetState.expand()
100
+ }
101
+ }) {
102
+ Text (text = " Bottom Sheet" )
103
+ }
104
+ Button (
105
+ modifier = Modifier
106
+ .fillMaxWidth()
107
+ .padding(16 .dp)
108
+ .height(55 .dp),
109
+ onClick = {
110
+ coroutineScope.launch {
111
+ sheetState.show()
112
+ }
113
+ }) {
114
+ Text (text = " Modal Bottom sheet" )
115
+ }
103
116
}
104
117
}
105
118
}
106
119
107
120
108
121
@Composable
109
122
fun BottomSheetContent () {
110
- Text (text = " Bottom Sheet" , textAlign = TextAlign .Center , modifier = Modifier
111
- .fillMaxWidth()
112
- .padding(16 .dp))
113
- Button (
114
- modifier = Modifier
115
- .fillMaxWidth()
116
- .padding(16 .dp)
117
- .height(55 .dp),
118
- onClick = {
119
- }) {
120
- Text (text = " Action 1" )
121
- }
122
- Button (
123
- modifier = Modifier
124
- .fillMaxWidth()
125
- .padding(16 .dp)
126
- .height(55 .dp),
127
- onClick = {
128
- }) {
129
- Text (text = " Action 2" )
130
- }
131
- Button (
132
- modifier = Modifier
133
- .fillMaxWidth()
134
- .padding(16 .dp)
135
- .height(55 .dp),
136
- onClick = {
137
- }) {
138
- Text (text = " Action 3" )
139
- }
123
+ DrawerContent ()
140
124
}
141
125
142
126
@Composable
@@ -166,22 +150,50 @@ fun DrawerContent() {
166
150
}
167
151
}
168
152
169
- @ExperimentalMaterialApi
170
153
@Composable
171
- fun CustomBottomSheetBackgroundScrim (scaffoldState : BottomSheetScaffoldState ) {
172
- val coroutineScope = rememberCoroutineScope()
173
- val bottomSheetProgress = scaffoldState.bottomSheetState.progress
174
- val bottomSheetFraction = bottomSheetProgress.fraction
175
- if ((bottomSheetProgress.from == BottomSheetValue .Collapsed && bottomSheetFraction < 1.0 )
176
- || bottomSheetProgress.from == BottomSheetValue .Expanded && scaffoldState.bottomSheetState.progress.fraction.toInt() == 1 ) {
177
- Spacer (modifier = Modifier
178
- .fillMaxSize()
179
- .background(MaterialTheme .colors.onSurface.copy(alpha = DrawerDefaults .ScrimOpacity ))
180
- .clickable {
181
- coroutineScope.launch {
182
- scaffoldState.bottomSheetState.collapse()
183
- }
184
- }
154
+ fun PlayerBottomSheet () {
155
+ val backgroundColor = MaterialTheme .colors.background.copy(alpha = 0.7f )
156
+ Row (
157
+ modifier = Modifier
158
+ .fillMaxWidth()
159
+ .background(color = backgroundColor),
160
+ verticalAlignment = Alignment .CenterVertically ,
161
+ ) {
162
+ Image (
163
+ painter = painterResource(id = R .drawable.adele21),
164
+ modifier = Modifier .size(65 .dp),
165
+ contentDescription = null ,
166
+ contentScale = ContentScale .Crop
167
+ )
168
+ Text (
169
+ text = " Someone Like you by Adele" ,
170
+ style = typography.h6.copy(fontSize = 14 .sp),
171
+ modifier = Modifier
172
+ .padding(8 .dp)
173
+ .weight(1f ),
174
+ )
175
+ Icon (
176
+ imageVector = Icons .Default .FavoriteBorder , modifier = Modifier .padding(8 .dp),
177
+ contentDescription = null
178
+ )
179
+ Icon (
180
+ imageVector = Icons .Default .PlayArrow , modifier = Modifier .padding(8 .dp),
181
+ contentDescription = null
185
182
)
186
183
}
187
- }
184
+ Text (text = " Lyrics" , style = typography.h6, modifier = Modifier .padding(16 .dp))
185
+ Text (
186
+ text = " I heard that you're settled down\n " +
187
+ " That you found a girl and you're married now\n " +
188
+ " I heard that your dreams came true\n " +
189
+ " Guess she gave you things, I didn't give to you\n " +
190
+ " Old friend, why are you so shy?\n " +
191
+ " Ain't like you to hold back or hide from the light\n " +
192
+ " I hate to turn up out of the blue, uninvited\n " +
193
+ " But I couldn't stay away, I couldn't fight it\n " +
194
+ " I had hoped you'd see my face\n " +
195
+ " And that you'd be reminded that for me, it isn't over" ,
196
+ modifier = Modifier .padding(16 .dp)
197
+ )
198
+
199
+ }
0 commit comments