Skip to content

Instantly share code, notes, and snippets.

@ashar-7
Created November 8, 2020 15:14
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 ashar-7/a0127714d9f94112426474b4b0cb808b to your computer and use it in GitHub Desktop.
Save ashar-7/a0127714d9f94112426474b4b0cb808b to your computer and use it in GitHub Desktop.
BottomDrawerLayout with FAB
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.Text
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.setContent
import androidx.ui.tooling.preview.Preview
import com.example.bottomdrawerwithfab.ui.BottomDrawerWithFabTheme
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
BottomDrawerWithFabTheme {
// A surface container using the 'background' color from the theme
Surface(color = MaterialTheme.colors.background) {
val drawerState = rememberBottomDrawerState(initialValue = BottomDrawerValue.Closed)
BottomDrawerLayout(
drawerContent = { Greeting("Drawer") },
drawerState = drawerState
) {
Column(
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.SpaceBetween
) {
Greeting("BottomDrawerLayout", onClick = { drawerState.open() })
ExtendedFloatingActionButton(
text = { Greeting("FAB") },
onClick = { drawerState.open() }
)
}
}
}
}
}
}
}
@Composable
fun Greeting(name: String, onClick: () -> Unit = {}) {
Text(text = "Hello $name!", modifier = Modifier.clickable(onClick = onClick))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment