Rafs
11/23/2020, 7:10 PMsheetpeekHeight
of a BottomSheetScaffold
composable? I tried passing a state variable and modifying it but it has no effectloloof64
11/23/2020, 8:23 PMKshitij Patil
11/24/2020, 5:18 AMonResume
, the screen should be shown directly. How can I achieve this?chao
11/24/2020, 7:37 AMorg.jetbrains.kotlin.diagnostics.SimpleDiagnostic@676ce3fe (error: could not render message)
sashjakk
11/24/2020, 10:08 AMloloof64
11/24/2020, 10:39 AM@Composable
MyComposable(size: Dp) {
// how to get size in px ?
}
Because it seems that withDensity
is not available in the newest API.Geert
11/24/2020, 10:51 AMescodro
11/24/2020, 11:21 AMViewModel
in brand new Android projects or projects that we are able to refactor this part? I'm asking this because Compose seems to be growing over the Android Environment and I saw some projects using ViewModel
and other ignoring it.Grzegorz Baczek
11/24/2020, 3:01 PMLazyRowFor
with elements whose width is equal to window width. And I'm trying to get currently visible item on the screen by using rememberLazyListState()
with firstVisibleItemIndex
. The problem is that whenever I reach the end of the list, this index is not updated. So the second to last item is fully hidden and only the last one is visible, but it still indicates second to last item. I've worked around it by adding 1 dp to the items width but it doesn't seem right. Also I've got question: is it possible in this case to make items adjust their position after each fling to the start of the screen? For example 3rd item is visible on the screen, I swipe from right to left and then 4th item enters from right side and gets snapped to the start of the screen, so it fill whole screen width.loloof64
11/24/2020, 5:01 PM@Composable
fun MyComposable(modifier: Mofifier) {
Column(modifier = modifier.background(backgroundColor)) {
(0 until 8).forEach { row ->
val color = if (row%2 == 0) whiteCellColor else blackCellColor
Row(modifier = Modifier.size(10.dp).background(color)) { // Here how to get a ration of 0.111 of the Composable size rather than a fixed 10dp Size ?
}
}
}
}
How can make the size(10.dp)
(see the comment) be a ratio of the parent instead ?loloof64
11/24/2020, 7:49 PM@Composable
fun SimpleZone(modifier: Modifier) {
val backgroundColor = Color(0xCAD63B60) // purple
val cellColor = Color(0xFFFFCE9E) // brown
Column(modifier = modifier.background(backgroundColor)) {
Row(modifier = Modifier.fillMaxHeight(0.1f).background(cellColor)) {
}
}
}
@Preview
@Composable
fun SimpleZonePreview() {
SimpleZone(modifier = Modifier.size(100.dp))
}
Arun
11/24/2020, 9:02 PM.preferredHeight(IntrinsicSize.Min)
. Getting the following error if a Composable using it is inside ScrollableColumn:
java.lang.IllegalStateException: Intrinsic measurements are not currently supported by SubcomposeLayout
Any idea what this is and how to get around this? I’m currently on alpha07.loloof64
11/25/2020, 12:21 AM@Composable
fun StaticChessBoard(
modifier: Modifier = Modifier,
positionFen: String = standardStartFen
) {
val backgroundColor = Color(0xCAD63B60)
val whiteCellColor = Color(0xFFFFCE9E)
val blackCellColor = Color(0xFFD18B47)
val textColor = Color(0xFFFFCC00)
val filesCoordinates = arrayListOf("A", "B", "C", "D", "E", "F", "G", "H")
val rankCoordinates = arrayListOf("8", "7", "6", "5", "4", "3", "2", "1")
Column(
modifier = modifier
.background(backgroundColor),
verticalArrangement = Arrangement.Center,
) {
Row(modifier = Modifier
.fillMaxWidth(0.8888f)
.weight(1f)
.align(Alignment.CenterHorizontally)) {
(0 until 8).forEach { col ->
val text = filesCoordinates[col]
// Can I adapt the size here ?
Text(text, color = textColor, fontWeight = FontWeight.Bold, modifier = Modifier.weight(1f))
}
}
Column(
modifier = Modifier.fillMaxWidth().weight(8f),
) {
(0 until 8).forEach { row ->
Row(
modifier = Modifier
.fillMaxWidth(0.8888f)
.weight(1f)
.align(Alignment.CenterHorizontally)
) {
(0 until 8).forEach { col ->
val color = if ((col + row) % 2 == 0) whiteCellColor else blackCellColor
Column(
modifier = Modifier
.fillMaxHeight()
.weight(1f)
.background(color)
) {
}
}
}
}
}
Row(modifier = Modifier
.fillMaxWidth(0.8888f)
.weight(1f)
.align(Alignment.CenterHorizontally)) {
(0 until 8).forEach { col ->
val text = filesCoordinates[col]
// Can I adapt the size here ?
Text(text, color = textColor, fontWeight = FontWeight.Bold, modifier = Modifier.weight(1f))
}
}
}
}
@Preview
@Composable
fun StaticChessBoardPreview() {
StaticChessBoard(
modifier = Modifier.size(100.dp),
positionFen = "rnbqkbnr/pp1ppppp/8/2p5/4P3/5N2/PPPP1PPP/RNBQKB1R b KQkq - 1 2\n"
)
Bradleycorn
11/25/2020, 2:35 AMAndroidView
and/or WebView
? I have a composable that is a Column
with a few Text
and Image
Composables, and then an AndroidView
which loads a WebView
… When it loads, the AndroidView/WebView display fine (and in the proper spot on the screen), but the other Text and Image composables don’t show up at all. Anyone run into this issue?
If I comment out the AndroidView, then the Text and Image composables show up.
Also, if I use an AndroidView, but just load it with a generic View
, then the Text and Image composables also show up. So it seems to be something specific to WebView?
More strange, if I DO NOT use androidx.webkit for the WebView, then if I wait a while after the screen loads up (maybe 20 or 30 seconds?) and then scroll around in the webview, the content then all of a sudden pops into placeMehdi Haghgoo
11/25/2020, 5:19 AMasLiveData()
is not understood.
Unresolved referenceasLiveData
class CostViewModel(private val repository: CostRepository): ViewModel() {
val costs : LiveData<List<Cost>> = repository.costs.asLiveData()
fun addCost(vararg cost: Cost) = viewModelScope.launch{
repository.addCost(*cost)
}
}
class CostViewModelFactory(private val repository: CostRepository) : ViewModelProvider.Factory {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
if (modelClass.isAssignableFrom(CostViewModel::class.java)) {
@Suppress("UNCHECKED_CAST")
return CostViewModel(repository) as T
}
throw IllegalArgumentException("Unknown ViewModel class")
}
}
My Repo:
import kotlinx.coroutines.flow.Flow
class CostRepository(private val costDao: CostDao){
val costs: Flow<List<Cost>> = costDao.getCosts()
suspend fun addCost(vararg cost: Cost){
costDao.addCost(*cost)
}
suspend fun deleteCosts(vararg cost: Cost){
costDao.deleteCost(*cost)
}
}
My Dao:
@Dao
interface CostDao {
@Query("SELECT * FROM cost")
fun getCosts(): Flow<List<Cost>>
@Insert()
suspend fun addCost(vararg cost: Cost)
@Delete()
fun deleteCost(vararg cost: Cost)
}
Ananiya
11/25/2020, 5:29 AMMBegemot
11/25/2020, 7:05 AMkevin_abrioux
11/25/2020, 8:18 AMsetContentDescription
?loloof64
11/25/2020, 9:32 AMval cellsSize = with(DensityAmbient.current) {
(size.toIntPx() * 0.1111) // Can I convert this result (which is px in Int) into an Sp unit, for a text ?
}
I've been searching at https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/package-summary. But did not find which one could be useful.Manuel Lorenzo
11/25/2020, 12:59 PMgrandstaish
11/25/2020, 1:52 PMloloof64
11/25/2020, 1:57 PMxetra11
11/25/2020, 2:44 PMJetpack Compose
vs
JetBrains Compose Android/JVM/Multiplatform
Siyamed
11/25/2020, 3:03 PMBradleycorn
11/25/2020, 3:53 PMAndroidView
when used with a WebView
, or am I doing something wrong? I have the following Composables that setup a screen containing a Column with some images and text, and then an AndroidView with a WebView. When the screen is composed, None of the top composables seem to get rendered, including the root level Surface that draws the entire screen with a dark background color (I have darkmode enabled). The ONLY thing that gets rendered is the AndroidView/WebView … Oddly enough, if I scroll in the WebView a little bit, all of a sudden the top views and Surface are rendered and magically appear ( have checked, nothing is recomposed, they just all of a sudden get rendered). Have I done something wrong, or is this a defect? Here are my composables:
@Composable
fun PostContent(post: Post, postContent: String) {
Column {
PostImage(url = post.imageUrl)
Column(modifier = Modifier.padding(horizontal = 16.dp)) {
Spacer(modifier = Modifier.height(8.dp))
Providers(AmbientContentAlpha provides ContentAlpha.high) {
Text(
text = post.title,
style = MaterialTheme.typography.h5,
color = MaterialTheme.colors.primaryOnSurface
)
}
Spacer(modifier = Modifier.height(8.dp))
Row(modifier = Modifier.padding(vertical = 8.dp)) {
CoilImage(
data = post.authorImage ?: "",
requestBuilder = {
transformations(CircleCropTransformation())
},
modifier = Modifier.width(36.dp).height(36.dp)
.align(Alignment.CenterVertically),
contentScale = ContentScale.Fit
)
Column(modifier = Modifier.padding(horizontal = 8.dp)) {
Text(text = post.author)
Providers(AmbientContentAlpha provides ContentAlpha.medium) {
Text(text = post.datePosted.toString("MMMM dd, h:mm a"))
}
}
}
Spacer(modifier = Modifier.height(8.dp))
PostBody(postContent)
}
}
}
@SuppressLint("SetJavaScriptEnabled")
@Composable
fun PostBody(html: String, modifier: Modifier = Modifier) {
val darkModeEnabled = !MaterialTheme.colors.isLight
AndroidView(viewBlock = { context ->
WebView(context).apply {
webViewClient = WebViewClient()
settings.javaScriptEnabled = true
settings.loadWithOverviewMode = true
settings.useWideViewPort = true
isVerticalScrollBarEnabled = false
setBackgroundColor(context.getColorFromAttr(R.attr.colorSurface))
if (darkModeEnabled) {
if (WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK)) {
WebSettingsCompat.setForceDark(settings, WebSettingsCompat.FORCE_DARK_ON);
}
}
if(WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK_STRATEGY)) {
WebSettingsCompat.setForceDarkStrategy(settings, WebSettingsCompat.DARK_STRATEGY_USER_AGENT_DARKENING_ONLY);
}
}
},
update = {
it.loadDataWithBaseURL("file:///android_asset/", html, "text/html", "base64", null)
})
}
loloof64
11/25/2020, 7:50 PM@Composable
fun GameScreen(topLevelNavController: NavController) {
GameScreenTheme {
Scaffold(
topBar = {
TopAppBar(
title = {
Text(
stringResource(id = R.string.game_page),
)
},
navigationIcon = {
IconButton(onClick = {
topLevelNavController.popBackStack()
}) {
Icon(Icons.Filled.ArrowBack)
}
}
)
},
) {
// Is there a way to get available width and height ?
}
}
}
Timo Drick
11/25/2020, 8:27 PMdata class Test(val pos: Int) {
protected fun finalize() {
log("Test finalized: $pos")
}
}
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
var pos by remember { mutableStateOf(0) }
Box(Modifier.fillMaxSize().clickable { pos++ }) {
val test = remember(pos) { Test(pos) }
Text("${test.pos}")
onCommit {
log("Test: $pos commited")
onDispose {
log("Test: $pos disposed")
}
}
}
}
}
}
Jeisson Sáchica
11/25/2020, 8:34 PMnavigation
defined in the NavHost
? I am currently getting an error stating the the NavDeepLink cannot be found when navigating from a composable
Sebastian Neagrau
11/25/2020, 10:41 PMHalil Ozercan
11/25/2020, 11:16 PMjava.lang.IllegalStateException: KeyEvent can't be processed because this key input node is not active.
Is this worthy of filing a bug? Or is it too weird of a use case? Should compose never be entangled in different layers with the old View system like this?