Fix ForYouScreen Compose Previews

Permissions should only be called in an Activity context, which is a layoutlib limitation. We need to avoid launching the permission request when in LocalInspectionMode, otherwise we'll have render errors on the ForYouScreen previews.
pull/789/head
Amaury Medeiros 1 year ago committed by GitHub
parent 5d423c1a85
commit dd70bbd589
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -68,6 +68,7 @@ import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.layout.layout import androidx.compose.ui.layout.layout
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalInspectionMode
import androidx.compose.ui.platform.testTag import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
@ -406,6 +407,8 @@ fun TopicIcon(
@Composable @Composable
@OptIn(ExperimentalPermissionsApi::class) @OptIn(ExperimentalPermissionsApi::class)
private fun NotificationPermissionEffect() { private fun NotificationPermissionEffect() {
// Permissions should be called from in an Activity Context, which is not present in previews
if (LocalInspectionMode.current) return
if (VERSION.SDK_INT < VERSION_CODES.TIRAMISU) return if (VERSION.SDK_INT < VERSION_CODES.TIRAMISU) return
val notificationsPermissionState = rememberPermissionState( val notificationsPermissionState = rememberPermissionState(
android.Manifest.permission.POST_NOTIFICATIONS, android.Manifest.permission.POST_NOTIFICATIONS,

Loading…
Cancel
Save