Update JankStats to 1.0.0-alpha03

Accomodating API changes along the way.
pull/219/head
Ben Weiss 2 years ago
parent 4a0fbf99b2
commit 6dc17126da
No known key found for this signature in database
GPG Key ID: 8424F9C1E763A74C

@ -24,9 +24,6 @@ import dagger.Module
import dagger.Provides import dagger.Provides
import dagger.hilt.InstallIn import dagger.hilt.InstallIn
import dagger.hilt.android.components.ActivityComponent import dagger.hilt.android.components.ActivityComponent
import java.util.concurrent.Executor
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.asExecutor
@Module @Module
@InstallIn(ActivityComponent::class) @InstallIn(ActivityComponent::class)
@ -47,17 +44,11 @@ object JankStatsModule {
return activity.window return activity.window
} }
@Provides
fun providesDefaultExecutor(): Executor {
return Dispatchers.Default.asExecutor()
}
@Provides @Provides
fun providesJankStats( fun providesJankStats(
window: Window, window: Window,
executor: Executor,
frameListener: JankStats.OnFrameListener frameListener: JankStats.OnFrameListener
): JankStats { ): JankStats {
return JankStats.createAndTrack(window, executor, frameListener) return JankStats.createAndTrack(window, frameListener)
} }
} }

@ -143,7 +143,7 @@ class NiaAppState(
private fun NavigationTrackingSideEffect(navController: NavHostController) { private fun NavigationTrackingSideEffect(navController: NavHostController) {
JankMetricDisposableEffect(navController) { metricsHolder -> JankMetricDisposableEffect(navController) { metricsHolder ->
val listener = NavController.OnDestinationChangedListener { _, destination, _ -> val listener = NavController.OnDestinationChangedListener { _, destination, _ ->
metricsHolder.state?.addState("Navigation", destination.route.toString()) metricsHolder.state?.putState("Navigation", destination.route.toString())
} }
navController.addOnDestinationChangedListener(listener) navController.addOnDestinationChangedListener(listener)

@ -26,7 +26,7 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.snapshotFlow import androidx.compose.runtime.snapshotFlow
import androidx.compose.ui.platform.LocalView import androidx.compose.ui.platform.LocalView
import androidx.metrics.performance.PerformanceMetricsState import androidx.metrics.performance.PerformanceMetricsState
import androidx.metrics.performance.PerformanceMetricsState.MetricsStateHolder import androidx.metrics.performance.PerformanceMetricsState.Holder
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
/** /**
@ -35,11 +35,11 @@ import kotlinx.coroutines.CoroutineScope
* @see PerformanceMetricsState.getForHierarchy * @see PerformanceMetricsState.getForHierarchy
*/ */
@Composable @Composable
fun rememberMetricsStateHolder(): MetricsStateHolder { fun rememberMetricsStateHolder(): Holder {
val localView = LocalView.current val localView = LocalView.current
return remember(localView) { return remember(localView) {
PerformanceMetricsState.getForHierarchy(localView) PerformanceMetricsState.getHolderForHierarchy(localView)
} }
} }
@ -51,7 +51,7 @@ fun rememberMetricsStateHolder(): MetricsStateHolder {
@Composable @Composable
fun JankMetricEffect( fun JankMetricEffect(
vararg keys: Any?, vararg keys: Any?,
reportMetric: suspend CoroutineScope.(state: MetricsStateHolder) -> Unit reportMetric: suspend CoroutineScope.(state: Holder) -> Unit
) { ) {
val metrics = rememberMetricsStateHolder() val metrics = rememberMetricsStateHolder()
LaunchedEffect(metrics, *keys) { LaunchedEffect(metrics, *keys) {
@ -66,7 +66,7 @@ fun JankMetricEffect(
@Composable @Composable
fun JankMetricDisposableEffect( fun JankMetricDisposableEffect(
vararg keys: Any?, vararg keys: Any?,
reportMetric: DisposableEffectScope.(state: MetricsStateHolder) -> DisposableEffectResult reportMetric: DisposableEffectScope.(state: Holder) -> DisposableEffectResult
) { ) {
val metrics = rememberMetricsStateHolder() val metrics = rememberMetricsStateHolder()
DisposableEffect(metrics, *keys) { DisposableEffect(metrics, *keys) {
@ -80,7 +80,7 @@ fun TrackScrollJank(scrollableState: ScrollableState, stateName: String) {
snapshotFlow { scrollableState.isScrollInProgress }.collect { isScrollInProgress -> snapshotFlow { scrollableState.isScrollInProgress }.collect { isScrollInProgress ->
metricsHolder.state?.apply { metricsHolder.state?.apply {
if (isScrollInProgress) { if (isScrollInProgress) {
addState(stateName, "Scrolling=true") putState(stateName, "Scrolling=true")
} else { } else {
removeState(stateName) removeState(stateName)
} }

@ -69,7 +69,7 @@ fun InterestsRoute(
) )
JankMetricDisposableEffect(tabState) { metricsHolder -> JankMetricDisposableEffect(tabState) { metricsHolder ->
metricsHolder.state?.addState("Interests:TabState", "currentIndex:${tabState.currentIndex}") metricsHolder.state?.putState("Interests:TabState", "currentIndex:${tabState.currentIndex}")
onDispose { onDispose {
metricsHolder.state?.removeState("Interests:TabState") metricsHolder.state?.removeState("Interests:TabState")

@ -15,7 +15,7 @@ androidxHiltNavigationCompose = "1.0.0"
androidxLifecycle = "2.6.0-alpha01" androidxLifecycle = "2.6.0-alpha01"
androidxMacroBenchmark = "1.1.0" androidxMacroBenchmark = "1.1.0"
androidxNavigation = "2.5.0" androidxNavigation = "2.5.0"
androidxMetrics = "1.0.0-alpha01" androidxMetrics = "1.0.0-alpha03"
androidxProfileinstaller = "1.2.0-rc01" androidxProfileinstaller = "1.2.0-rc01"
androidxSavedState = "1.1.0" androidxSavedState = "1.1.0"
androidxStartup = "1.1.1" androidxStartup = "1.1.1"

Loading…
Cancel
Save