|
|
|
@ -16,10 +16,14 @@
|
|
|
|
|
|
|
|
|
|
package com.google.samples.apps.nowinandroid.ui
|
|
|
|
|
|
|
|
|
|
import android.app.Activity
|
|
|
|
|
import android.view.View
|
|
|
|
|
import androidx.compose.material3.Text
|
|
|
|
|
import androidx.compose.material3.windowsizeclass.WindowSizeClass
|
|
|
|
|
import androidx.compose.runtime.Composable
|
|
|
|
|
import androidx.compose.ui.Modifier
|
|
|
|
|
import androidx.compose.ui.platform.LocalView
|
|
|
|
|
import androidx.core.view.doOnPreDraw
|
|
|
|
|
import androidx.navigation.NavHostController
|
|
|
|
|
import androidx.navigation.NavType
|
|
|
|
|
import androidx.navigation.compose.NavHost
|
|
|
|
@ -98,4 +102,23 @@ fun NiaNavGraph(
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Reporting the app fully drawn to get accurate TTFD readings for the baseline profile.
|
|
|
|
|
// https://developer.android.com/topic/performance/vitals/launch-time#retrieve-TTFD
|
|
|
|
|
ReportFullyDrawn(NiaDestinations.FOR_YOU_ROUTE)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Calling [Activity#reportFullyDrawn] in compose UI.
|
|
|
|
|
*/
|
|
|
|
|
@Composable
|
|
|
|
|
private fun ReportFullyDrawn(destination: String) {
|
|
|
|
|
// Holding on to the local view and calling `reportFullyDrawn` in an `onPreDraw` listener.
|
|
|
|
|
// Compose currently doesn't offer a way to otherwise report fully drawn,
|
|
|
|
|
// so this is a viable approach.
|
|
|
|
|
val localView: View = LocalView.current
|
|
|
|
|
(localView.context as? Activity)?.run {
|
|
|
|
|
localView.doOnPreDraw {
|
|
|
|
|
reportFullyDrawn()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|