|
8 | 8 | package org.nsh07.pomodoro.ui |
9 | 9 |
|
10 | 10 | import android.app.Activity |
| 11 | +import android.view.WindowManager |
| 12 | +import androidx.activity.compose.LocalActivity |
11 | 13 | import androidx.compose.animation.SharedTransitionLayout |
12 | 14 | import androidx.compose.animation.SharedTransitionScope |
13 | 15 | import androidx.compose.animation.animateColorAsState |
@@ -61,19 +63,29 @@ fun SharedTransitionScope.AlwaysOnDisplay( |
61 | 63 | var sharedElementTransitionComplete by remember { mutableStateOf(false) } |
62 | 64 |
|
63 | 65 | val view = LocalView.current |
| 66 | + val activity = LocalActivity.current |
64 | 67 | val window = remember { (view.context as Activity).window } |
65 | 68 | val insetsController = remember { WindowCompat.getInsetsController(window, view) } |
66 | 69 |
|
67 | 70 | DisposableEffect(Unit) { |
68 | | - view.keepScreenOn = true |
| 71 | + window.addFlags( |
| 72 | + WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON or |
| 73 | + WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON |
| 74 | + ) |
| 75 | + activity?.setShowWhenLocked(true) |
69 | 76 | insetsController.apply { |
70 | 77 | hide(WindowInsetsCompat.Type.statusBars()) |
71 | 78 | hide(WindowInsetsCompat.Type.navigationBars()) |
72 | 79 | systemBarsBehavior = |
73 | 80 | WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE |
74 | 81 | } |
| 82 | + |
75 | 83 | onDispose { |
76 | | - view.keepScreenOn = false |
| 84 | + window.clearFlags( |
| 85 | + WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON or |
| 86 | + WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON |
| 87 | + ) |
| 88 | + activity?.setShowWhenLocked(false) |
77 | 89 | insetsController.apply { |
78 | 90 | show(WindowInsetsCompat.Type.statusBars()) |
79 | 91 | show(WindowInsetsCompat.Type.navigationBars()) |
|
0 commit comments