• Dmitriy Gaiduk

    Dmitriy Gaiduk

    11 months ago
    Hello, What’s the preferred way to implement a custom string resource system in Compose? Problem: We are adding the Lokalise SDK https://docs.lokalise.com/en/articles/1400668-lokalise-android-sdk. And working with strings looks like this:
    val resources = new LokaliseResources(context)
    val text = resources.getString(R.string.screen_title)
    What’s the best way to store and create the
    LokaliseResources
    object in Compose? We want to use the
    LokaliseResources.getString ()
    function as a replacement for
    androidx.compose.ui.res.stringResource ()
    . We now have an implementation like this:
    @Composable
    fun CustomTheme(
      useDarkTheme: Boolean = false,
      content: @Composable () -> Unit,
    ) {
      val colors = if (useDarkTheme) DarkColorPalette else LightColorPalette
      val colorPalette = remember { colors }
      colorPalette.update(colors)
      
      MaterialTheme(
        colors = debugColors(),
        typography = MaterialTypography,
      ) {
        CompositionLocalProvider(
          CustomColors provides colorPalette,
          content = content,
        )
      }
    }
    
    class Screen : com.bluelinelabs.conductor.Controller {
      private val lokaliseResources: LokaliseResources by lazy { LokaliseResources(activity) }
      private fun getString(@StringRes resId: Int): String {
        return lokaliseResources.getString(resId)
      }
    
     @Composable
     fun Content() {
        CustomTheme(useDarkTheme = false) {
          Text(value = getString(R.string.screen_title))
        }
      }
    }
    But the problem is that you cannot get a string resource outside of the
    Screen
    class in any Compose method. Is it possible to create LokaliseResources in a singleton? Or can this be added to
    CustomTheme
    somehow?
    Dmitriy Gaiduk
    a
    +1
    5 replies
    Copy to Clipboard
  • Alexander Suraphel

    Alexander Suraphel

    11 months ago
    I’m following this guide to add compose to my existing app.. It says
    Make sure you're using Kotlin 1.5.21 in your project.
    Will Kotlin version
    1.5.31
    work?
    Alexander Suraphel
    m
    +1
    25 replies
    Copy to Clipboard
  • a

    Andrew Hughes

    11 months ago
    Would anyone be able to provide some guidance on how to implement an animated expanding/collapsing navigation rail similar to what is shown here (which is from the Navigation drawer section of this page)? The issue that I'm running into is related to how the text in the FAB or list items behaves when the rail is collapsing. As you can see in the animation, the desired effect is to have the text (i.e. "Compose" and "Inbox") fade out as the rail collapses with the result being that only the icons are visible. However, in practice, since the FAB and list items are contained within the rail, the text gets wrapped during the animation as the width of the rail animates to the collapsed size. The only thing I have found to "work" is to set the
    wrapContentWidth(unbounded = true)
    modifier on the
    Text
    composable, however, this has the side-effect of never wrapping the text, which I don't necessarily want. I started looking into creating a transition and using
    AnimatedContent
    but I haven't been having much luck so far.
    a
    Doris Liu
    +1
    40 replies
    Copy to Clipboard
  • l

    Lilly

    11 months ago
    I have a data class annotated with
    @Stable
    and would expect that a change to the property would reflect the new state but it doesn't:
    @Stable
    data class StableState(var isChecked: Boolean)
    
    @Composable
    fun StableTest(state: StableState) {
        Checkbox(checked = state.isChecked, onCheckedChange = {
            state.isChecked = it
        })
    }
    What did I miss?
    l
    m
    +2
    13 replies
    Copy to Clipboard
  • i

    Ink

    11 months ago
    Hi guys How Can I wrap my text to new line when it's too long to be fully visible in one line?
    i
    1 replies
    Copy to Clipboard
  • brabo-hi

    brabo-hi

    11 months ago
    Hi, how can we get elevation only at the bottom when using a
    Card
    composable
    brabo-hi
    Will Shelor
    2 replies
    Copy to Clipboard
  • s

    smallshen

    11 months ago
    is there a version of compose build that everything is open? I try to implement something but everything is marked as internal
    s
    Zach Klippenstein (he/him) [MOD]
    5 replies
    Copy to Clipboard
  • Alex

    Alex

    11 months ago
    Is there a snap-helper for snapping to items in lists? (e.g. when the user stops scrolling, the list snaps to the nearest item)
    Alex
    Albert Chang
    +2
    9 replies
    Copy to Clipboard
  • Andrei Kovalev

    Andrei Kovalev

    11 months ago
    Hi folks, I’m trying to resolve the issue when cards overlap in grid view with
    zIndex
    , but the problem is that in lazy LazyGrid Implementation
    val rows = (scope.totalSize + nColumns - 1) / nColumns
        LazyColumn(
            modifier = modifier,
            state = state,
            contentPadding = contentPadding
        ) {
            items(rows) { rowIndex ->
                Row {
                    for (columnIndex in 0 until nColumns) {
                        val itemIndex = rowIndex * nColumns + columnIndex
                        if (itemIndex < scope.totalSize) {
                            Box(
                                modifier = Modifier.weight(1f, fill = true),
                                propagateMinConstraints = true
                            ) {
                                scope.contentFor(itemIndex, this@items).invoke()
                            }
                        } else {
                            Spacer(Modifier.weight(1f, fill = true))
                        }
                    }
                }
            }
        }
    our composable items are wrapped in a Box, but
    zIndex
    only works for direct children of the composable node. How would you resolve this issue? Any suggestions are welcome
    Andrei Kovalev
    p
    +2
    9 replies
    Copy to Clipboard
  • Lucien Guimaraes

    Lucien Guimaraes

    11 months ago
    Just updated to Accompanist 0.19.0, and I have an issue with the reworked HorizontalPager: my items have now a start/end padding to fill the pager width, instead of only keeping the item width. Anyone know how to fix this ?
    Lucien Guimaraes
    n
    +1
    20 replies
    Copy to Clipboard