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

pajatopmr

07/15/2020, 4:39 AM
One of the first things I notice in my journey into the land of Compose (sample apps like Jetnews) is that there are two types of theme files, one legacy type referenced from the manifest file and one new type referenced as code files (e.g. Jetnewssample/app/src/main/java/com/example/jetnews/ui/theme/*.kt). My guess is that the legacy type will go away eventually to be replaced by the code file approach. Would this be a good guess? If not, what is the rational for having both approaches?
t

Timo Drick

07/15/2020, 8:57 AM
In my Compose project i do not need any color in my xml legacy style definitions except for the windowBackground. Every other theme definitions can be done in Code and use the new Compose system for color definitions.
a

Adrian Blanco

07/15/2020, 9:57 AM
Also things like splash screen, insets, day/night mode are also currently only really available by setting app themes afaik
t

Timo Drick

07/15/2020, 10:01 AM
insets i do programmatically. Day/night mode is supported by Compose directly. So only splash screen -> windowBackground
When you apply a WindowInsetsListener:
Copy code
private var insets by mutableStateOf(WindowInsetsCompat.Builder().build())
private val systemWindowInsetListener = { view: View, insets: WindowInsetsCompat ->
        this.insets = insets
        insets}

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    ViewCompat.setOnApplyWindowInsetsListener(window.decorView.rootView, systemWindowInsetListener)
Than you can draw your app also behinde system bars. But it is and was every time in Android very hard to get every thing right. So i think you also need some style attributes like following:
Copy code
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:windowIsTranslucent">false</item>
<item name="android:windowBackground">@color/transparent</item>
<!--<item name="android:windowShowWallpaper">true</item>-->
<item name="android:colorBackgroundCacheHint">@null</item>
For the insets to work properly you also need to map them to dp and RTL layout direction in your compose view.
Copy code
val insetPadding = with(DensityAmbient.current) {
    val ltr = ConfigurationAmbient.current.localeLayoutDirection == LayoutDirection.Ltr
    with (insets) {
        InnerPadding(
                start = if (ltr) systemWindowInsetLeft.toDp() else systemWindowInsetRight.toDp(),
                top = systemWindowInsetTop.toDp(),
                end = if (ltr) systemWindowInsetRight.toDp() else systemWindowInsetLeft.toDp(),
                bottom = systemWindowInsetBottom.toDp()
        )
    }
}
p

pajatopmr

07/16/2020, 8:18 AM
@Timo Drick more to the point, are your code suggestions in this thread workarounds waiting for better solutions from the framework, or consequences of likely to be unchanged compose design decisions? I just don't know compose well enough to discern this yet.
t

Timo Drick

07/16/2020, 9:17 AM
No i just wanted to point out that it is already possible to avoid many legacy XML style configurations.
2 Views