Skip to content

Commit 1758f92

Browse files
authored
Merge pull request #62 from android/windowing
Introduce Modifier.onVisibilityChanged
2 parents 5b324d1 + bebd697 commit 1758f92

File tree

1 file changed

+5
-16
lines changed
  • feature/home/src/main/java/com/android/developers/androidify/home

1 file changed

+5
-16
lines changed

feature/home/src/main/java/com/android/developers/androidify/home/HomeScreen.kt

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ import androidx.compose.ui.graphics.graphicsLayer
7676
import androidx.compose.ui.graphics.vector.ImageVector
7777
import androidx.compose.ui.graphics.vector.rememberVectorPainter
7878
import androidx.compose.ui.layout.onLayoutRectChanged
79+
import androidx.compose.ui.layout.onVisibilityChanged
7980
import androidx.compose.ui.platform.LocalContext
8081
import androidx.compose.ui.platform.LocalInspectionMode
8182
import androidx.compose.ui.platform.LocalView
@@ -541,9 +542,10 @@ private fun VideoPlayer(
541542
Modifier
542543
.background(MaterialTheme.colorScheme.surfaceContainerLowest)
543544
.onVisibilityChanged(
544-
containerWidth = LocalView.current.width,
545-
containerHeight = LocalView.current.height,
546-
) { fullyVisible -> videoFullyOnScreen = fullyVisible }
545+
minDurationMs = 100,
546+
minFractionVisible = 1f
547+
)
548+
{ fullyVisible -> videoFullyOnScreen = fullyVisible }
547549
.then(modifier),
548550
) {
549551
player?.let { currentPlayer ->
@@ -579,16 +581,3 @@ private fun VideoPlayer(
579581
}
580582
}
581583
}
582-
583-
fun Modifier.onVisibilityChanged(
584-
containerWidth: Int,
585-
containerHeight: Int,
586-
onChanged: (visible: Boolean) -> Unit,
587-
) = this then Modifier.onLayoutRectChanged(100, 0) { layoutBounds ->
588-
onChanged(
589-
layoutBounds.boundsInRoot.top > 0 &&
590-
layoutBounds.boundsInRoot.bottom < containerHeight &&
591-
layoutBounds.boundsInRoot.left > 0 &&
592-
layoutBounds.boundsInRoot.right < containerWidth,
593-
)
594-
}

0 commit comments

Comments
 (0)