• l

    loloof64

    1 year ago
    Can anybody tell me what's wrong with the following component ? It should be made of two colors : a purple background and a brown line at top. Instead, all I can see is a purple square.
    @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))
    }
    l
    n
    +1
    12 replies
    Copy to Clipboard
  • a

    Arun

    1 year ago
    Trying to use
    .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.
    a
    Adam Powell
    8 replies
    Copy to Clipboard
  • l

    loloof64

    1 year ago
    Hi again, this is a composable I am building. Is it possible to make the coordinates' font size adapt to the size of their different "boxes" ? I mean, can I make the font size be a ratio of the available space for a given letter text ? (I've put some comments in order to locate the issue)
    @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"
        )
    l
    1 replies
    Copy to Clipboard
  • b

    Bradleycorn

    1 year ago
    Anyone ever run into trouble with
    AndroidView
    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 place
    b
    1 replies
    Copy to Clipboard
  • Mehdi Haghgoo

    Mehdi Haghgoo

    1 year ago
    I want to back my Compose app's viewmodel with Room and I'm trying to use Room+Kotlin codelab, which seems to have been changed a bit since it was first written. In my ViewModel,
    asLiveData()
    is not understood.
    Unresolved reference
    asLiveData
    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)
    }
    Mehdi Haghgoo
    1 replies
    Copy to Clipboard
  • Ananiya

    Ananiya

    1 year ago
    Hello there, i am unable to download "kotlin-complier-embedable-$vers-dev-withExperimental.." Compose Library in android studio due to network unstablity causing read timeout, so I have download it with chrome, but where should I locate it Please help
    Ananiya
    Adam Powell
    6 replies
    Copy to Clipboard
  • m

    MBegemot

    1 year ago
    Has anybody stumbled into this ->java.lang.IllegalStateException: Missed recording an endGroup, the problem is that the exception happens randomly, and it's hard to debug, what does it mean? thanks a lot
    m
    n
    2 replies
    Copy to Clipboard
  • k

    kevin_abrioux

    1 year ago
    Hi guys, any idea how to manage accessibility on Compose, like
    setContentDescription
    ?
    k
    André Kindwall
    2 replies
    Copy to Clipboard
  • l

    loloof64

    1 year ago
    Hi ! Is there a simple way to convert size (is given as dp) to sp unit ?
    val 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.
    l
    André Kindwall
    5 replies
    Copy to Clipboard
  • m

    Manuel Lorenzo

    1 year ago
    hi everybody, how do you guys show and hide a progress indicator while some data is being loaded?
    m
    k
    +1
    10 replies
    Copy to Clipboard