Skip to content

Instantly share code, notes, and snippets.

@Khazbs
Created July 21, 2024 20:19
Show Gist options
  • Save Khazbs/5138f20b9e1da497404680e8ece5ed8b to your computer and use it in GitHub Desktop.
Save Khazbs/5138f20b9e1da497404680e8ece5ed8b to your computer and use it in GitHub Desktop.
How to wed Scaffold, LazyColumn and IME padding in Jetpack Compose edge-to-edge
package com.example.app
import android.os.Bundle
import androidx.activity.*
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Modifier
import com.example.app.ui.theme.ExampleTheme
class MainActivity : ComponentActivity() {
@OptIn(ExperimentalMaterial3Api::class)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContent {
ExampleTheme {
Scaffold(
topBar = {
Row(Modifier.fillMaxWidth(), Arrangement.Center) {
var query by rememberSaveable { mutableStateOf("") }
SearchBar(query, { query = it }, {}, false, {}) {}
}
},
content = { innerPadding ->
LazyColumn(
modifier = Modifier
.consumeWindowInsets(innerPadding)
.imePadding(),
contentPadding = innerPadding,
content = { items(30) { ListItem({ Text("Item #$it") }) } },
)
},
)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment