Skip to content

Commit

Permalink
Use alpha-versions of Compose, fix instrumented tests
Browse files Browse the repository at this point in the history
  • Loading branch information
illarionov committed May 14, 2024
1 parent ed33d3c commit 1093575
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import ru.pixnews.anvil.codegen.initializer.inject.ContributesInitializer
import ru.pixnews.foundation.initializers.Initializer
import ru.pixnews.inject.DebugStrictModeInitializerModule
import ru.pixnews.util.strictmode.ViolationPolicy.FAIL
import ru.pixnews.util.strictmode.isFontRequestViolation
import ru.pixnews.util.strictmode.isGmsDiskReadViolation
import ru.pixnews.util.strictmode.isInstanceCountViolation
import ru.pixnews.util.strictmode.isInstrumentationDexMakerViolation
import ru.pixnews.util.strictmode.isProfileSizeOfAppViolation
Expand Down Expand Up @@ -71,11 +73,13 @@ class TestStrictModeInitializer @Inject constructor(logger: Logger) : Initialize

private companion object {
val ALLOWLIST = listOf(
isFontRequestViolation,
isGmsDiskReadViolation,
isInstanceCountViolation,
isInstrumentationDexMakerViolation,
isProfileSizeOfAppViolation,
isTypefaceFullFlipFontViolation,
isUntaggedSocketViolation,
isInstanceCountViolation,
)
}
}
17 changes: 17 additions & 0 deletions app/src/main/kotlin/ru/pixnews/util/strictmode/ViolationExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ internal val isTypefaceFullFlipFontViolation: Violation.() -> Boolean = {
}
}

@SuppressLint("NewApi")
internal val isFontRequestViolation: Violation.() -> Boolean = {
this is DiskReadViolation && this.stackTrace.any {
it.className == "androidx.core.provider.FontRequestWorker" && it.fileName == "FontRequestWorker.java"
}
}

@SuppressLint("NewApi")
internal val isProfileSizeOfAppViolation: Violation.() -> Boolean = {
this is DiskReadViolation && this.stackTrace.any {
Expand All @@ -46,3 +53,13 @@ internal val isUntaggedSocketViolation: Violation.() -> Boolean = {
internal val isInstanceCountViolation: Violation.() -> Boolean = {
this is InstanceCountViolation
}

/**
* Difficult to diagnose violation in GMS
*/
@SuppressLint("NewApi")
internal val isGmsDiskReadViolation: Violation.() -> Boolean = {
(this is DiskReadViolation) && this.stackTrace.any {
it.fileName?.contains(":com.google.android.gms") ?: false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ internal class ViolationListener(
) {
if (violation.shouldSkip()) {
if (logAllowListViolation) {
logger.e { "Skipping $type violation `$violation: ${violation.message}`" }
logger.e {
"Skipping $type violation `$violation: message: ${violation.message}`, " +
"stracktrace: ${violation.stackTraceToString()}"
}
}
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import androidx.compose.material.icons.filled.ArrowDropDown
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Icon
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.LocalMinimumInteractiveComponentEnforcement
import androidx.compose.material3.LocalMinimumInteractiveComponentSize
import androidx.compose.material3.LocalTextStyle
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
Expand Down Expand Up @@ -143,7 +143,7 @@ internal fun WeekDaysRow(
}
CompositionLocalProvider(
LocalTextStyle provides textStyle,
LocalMinimumInteractiveComponentEnforcement provides false,
LocalMinimumInteractiveComponentSize provides 42.dp,
) {
Surface(
contentColor = contentColor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ package ru.pixnews.foundation.ui.design.navigation

import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.RowScope
import androidx.compose.material.ripple.LocalRippleTheme
import androidx.compose.material.ripple.RippleAlpha
import androidx.compose.material.ripple.RippleTheme
import androidx.compose.material3.LocalRippleConfiguration
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarItem
import androidx.compose.material3.NavigationBarItemColors
import androidx.compose.material3.NavigationBarItemDefaults
import androidx.compose.material3.RippleConfiguration
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.Immutable
import androidx.compose.runtime.NonRestartableComposable
import androidx.compose.runtime.ReadOnlyComposable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
Expand All @@ -28,7 +28,7 @@ public fun PixnewsBottomNavigationBar(
modifier: Modifier = Modifier,
content: @Composable RowScope.() -> Unit,
) {
CompositionLocalProvider(LocalRippleTheme provides NavigationBarItemRippleTheme) {
CompositionLocalProvider(LocalRippleConfiguration provides BottomNavigationBarDefaults.rippleConfiguration()) {
NavigationBar(
modifier = modifier,
content = content,
Expand Down Expand Up @@ -66,26 +66,25 @@ public fun RowScope.PixnewsBottomNavigationBarItem(
}

public object BottomNavigationBarDefaults {
private val rippleAlpha = RippleAlpha(
draggedAlpha = 0.16f,
focusedAlpha = 0.12f,
hoveredAlpha = 0.08f,
pressedAlpha = 0.12f,
)

@Composable
@ReadOnlyComposable
public fun indicatorColor(): Color = MaterialTheme.colorScheme.secondaryContainer

@Composable
@ReadOnlyComposable
public fun selectedIconColor(): Color = MaterialTheme.colorScheme.onSecondaryContainer

@Composable
public fun rippleDefaultColor(): Color = MaterialTheme.colorScheme.secondary
}

@Immutable
private object NavigationBarItemRippleTheme : RippleTheme {
@Composable
override fun defaultColor(): Color = BottomNavigationBarDefaults.rippleDefaultColor()

@Composable
override fun rippleAlpha(): RippleAlpha = RippleAlpha(
draggedAlpha = 0.16f,
focusedAlpha = 0.12f,
hoveredAlpha = 0.08f,
pressedAlpha = 0.12f,
@ReadOnlyComposable
public fun rippleConfiguration(): RippleConfiguration = RippleConfiguration(
color = MaterialTheme.colorScheme.secondary,
rippleAlpha = rippleAlpha,
)
}
6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ androidx-appcompat = "1.7.0-beta01"
androidx-arch-core = "2.2.0"
androidx-benchmark = "1.2.4"
androidx-collection = "1.4.0"
androidx-compose-bom = "2024.05.00"
chrisbanes-compose-bom = "2024.05.00-alpha01"
androidx-compose-compiler = "1.5.13"
androidx-compose-material3 = "1.2.1"
androidx-compose-runtime-tracing = "1.0.0-beta01"
Expand Down Expand Up @@ -93,7 +93,6 @@ androidx-activity-compose = { group = "androidx.activity", name = "activity-comp
androidx-annotation = { group = "androidx.annotation", name = "annotation", version.ref = "androidx-annotation" }
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "androidx-appcompat" }
androidx-benchmark-macro = { group = "androidx.benchmark", name = "benchmark-macro-junit4", version.ref = "androidx-benchmark" }
androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "androidx-compose-bom" }
androidx-compose-foundation = { group = "androidx.compose.foundation", name = "foundation" }
androidx-compose-material3 = { group = "androidx.compose.material3", name = "material3", version.ref = "androidx-compose-material3" }
androidx-compose-material3-windowSizeClass = { group = "androidx.compose.material3", name = "material3-window-size-class" }
Expand Down Expand Up @@ -145,6 +144,7 @@ arrow-bom = { group = "io.arrow-kt", name = "arrow-stack", version.ref = "arrow"
arrow-core = { group = "io.arrow-kt", name = "arrow-core" }
assertk = { group = "com.willowtreeapps.assertk", name = "assertk-jvm", version.ref = "assertk" }
asm-bom = { group = "org.ow2.asm", name = "asm-bom", version.ref = "asm" }
chrisbanes-compose-bom = { group = "dev.chrisbanes.compose", name = "compose-bom", version.ref = "chrisbanes-compose-bom" }
coil-base = { group = "io.coil-kt", name = "coil-base" }
coil-bom = { group = "io.coil-kt", name = "coil-bom", version.ref = "coil" }
coil-compose-base = { group = "io.coil-kt", name = "coil-compose-base" }
Expand Down Expand Up @@ -229,7 +229,7 @@ wire-plugin = { group = "com.squareup.wire", name = "wire-gradle-plugin", versio
[bundles]
coil = ["coil-compose-base"]
boms = [
"androidx-compose-bom",
"chrisbanes-compose-bom",
"arrow-bom",
"asm-bom",
"coil-bom",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ fun configureAndroidTestDependencies() {
add("androidTestImplementation", project(":foundation:instrumented-test"))
add("androidTestRuntimeOnly", versionCatalog.findLibrary("androidx-test-runner").orElseThrow())
if (pixnews.compose.get()) {
val composeBom = platform(versionCatalog.findLibrary("androidx.compose.bom").orElseThrow())
val composeBom = platform(versionCatalog.findLibrary("chrisbanes.compose.bom").orElseThrow())
add("androidTestImplementation", composeBom)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal fun Project.configureCompose(
}

dependencies {
val composeBom = platform(versionCatalog.findLibrary("androidx.compose.bom").orElseThrow())
val composeBom = platform(versionCatalog.findLibrary("chrisbanes.compose.bom").orElseThrow())
add("implementation", composeBom)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fun createComposeRuntimeCompileClasspath(): FileCollection {
dependencies {
add(
compileClasspathAarConfiguration.name,
platform(versionCatalog.findLibrary("androidx-compose-bom").get()),
platform(versionCatalog.findLibrary("chrisbanes-compose-bom").get()),
)
add(compileClasspathAarConfiguration.name, versionCatalog.findLibrary("androidx-compose-runtime").get())

Expand Down

0 comments on commit 1093575

Please sign in to comment.