https://kotlinlang.org logo
#compose
Title
# compose
g

galex

07/23/2020, 4:03 AM
Hello, this is going to stay isn’t? Any way around it?
Copy code
e: /Users/galex/projects/alexpizzapp/app/src/main/java/il/co/galex/alexpizzapp/common/navigation/Navigation.kt: (24, 16): @Composable invocations can only happen from the context of a @Composable function
I can reference
Icons.Filled.AccountBox
but I can’t call to
vectorResource
at the same level 😞
l

Leland Richardson [G]

07/23/2020, 4:34 AM
is there a reason you need to? like is just holding
AccountBox
instead of the vector resource itself good enough?
g

galex

07/23/2020, 6:16 AM
Ah I didn’t know the icons were accessible by resources as well, are they in the material R? I can’t seem to find them
l

Leland Richardson [G]

07/23/2020, 6:41 AM
sorry, i just meant if you’re wanting to do
Copy code
val foo = vectorResource(bar)
and using it inside a composable as
Copy code
Image(foo)
Is it not easy enough to instead just do
Copy code
val foo = bar
and then use it inside a composable as
Copy code
Image(vectorResource(foo))
And if not, what is the use case that makes it not?
g

galex

07/23/2020, 8:17 AM
Have a look at this class:
Copy code
sealed class Screen(val id: ScreenName, @StringRes val label: Int, val icon: VectorAsset? = null, val iconResId: Int? = 0) {

    object Home : Screen(
        id = ScreenName.HOME,
        label = R.string.title_home,
        icon = Icons.Filled.Home,
    )

    object Calculator : Screen(
        id = ScreenName.CALCULATOR,
        label = R.string.title_calculator,
        iconResId = R.drawable.ic_calculate_24dp
    )

    object Profile : Screen(
        id = ScreenName.PROFILE,
        label = R.string.title_profile,
        icon = Icons.Filled.AccountBox
    )
}
For Calculator, I wanted to define also
icon
as a
vectorResource
because I couldn’t find the calculator icon in
Icons.Filled.*
so I added it in my project old style
I can’t so had to add an
iconResId
property and condtionnaly load one or the other depending on
icon
nullability
I just changed all my items to be resources and I realised that in
BottomNavigation
, if I set the icon as
Icons.Filled.Home
it is dark, and if I set it up as
Icon(vectorResource(id = R.drawable.home)
it gets tinted to white! Should I open a bug?