Skip to content

Instantly share code, notes, and snippets.

@shakil807g
Created March 15, 2021 11:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shakil807g/451958e2cee0d26527467b8aba12c443 to your computer and use it in GitHub Desktop.
Save shakil807g/451958e2cee0d26527467b8aba12c443 to your computer and use it in GitHub Desktop.
FACRModalBottomSheet(facrViewModel.isClubSheetVisible, onSheetHidden = {
facrViewModel.isClubSheetVisible = false
}) { state ->
AddClubsBottomSheet(facrViewModel = facrViewModel)
}
import androidx.compose.animation.*
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.tween
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import com.facr.fotbal.util.BackHandler
import dev.chrisbanes.accompanist.insets.statusBarsPadding
import kotlinx.coroutines.launch
@ExperimentalAnimationApi
@ExperimentalMaterialApi
@Composable
fun FACRModalBottomSheet(
isSheetVisible: Boolean,
onSheetHidden: () -> Unit,
sheetContent: @Composable (sheetState: ModalBottomSheetState) -> Unit,
) {
AnimatedVisibility(isSheetVisible,
enter = slideInVertically(
initialOffsetY = { it },
animationSpec = tween(durationMillis = 500)
) + fadeIn(initialAlpha = 0.3f,animationSpec = tween(durationMillis = 500)),
exit = slideOutVertically(
targetOffsetY = { it },
animationSpec = tween(durationMillis = 500)
) + fadeOut( animationSpec = tween(durationMillis = 500))
) {
val sheetState = rememberModalBottomSheetState(ModalBottomSheetValue.Expanded)
val scope = rememberCoroutineScope()
BackHandler(
enabled = sheetState.isVisible,
onBack = { scope.launch { sheetState.hide() } }
)
ModalBottomSheetLayout(
sheetState = sheetState,
sheetBackgroundColor = Color.Transparent,
scrimColor = Color.Transparent,
sheetContentColor = contentColorFor(backgroundColor = MaterialTheme.colors.surface),
sheetElevation = 16.dp,
sheetContent = {
Box(
modifier = Modifier
.fillMaxSize()
.statusBarsPadding()
.clip(RoundedCornerShape(16.dp))
) {
Surface(
elevation = ModalBottomSheetDefaults.Elevation,
) {
sheetContent(sheetState)
}
}
},
content = {
Box(modifier = Modifier.fillMaxSize())
}
)
if(sheetState.currentValue == ModalBottomSheetValue.Hidden || sheetState.currentValue == ModalBottomSheetValue.HalfExpanded) {
onSheetHidden()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment