1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.systemui.scene.shared.model 18 19 import com.android.compose.animation.scene.OverlayKey 20 import com.android.compose.animation.scene.SceneKey 21 import com.android.compose.animation.scene.TransitionKey 22 import kotlinx.coroutines.flow.StateFlow 23 24 /** Defines interface for classes that provide access to scene state. */ 25 interface SceneDataSource { 26 27 /** 28 * The current scene, as seen by the real data source in the UI layer. 29 * 30 * During a transition between two scenes, the original scene will still be reflected in 31 * [currentScene] until a time when the UI layer decides to commit the change, which is when 32 * [currentScene] will have the value of the target/new scene. 33 */ 34 val currentScene: StateFlow<SceneKey> 35 36 /** 37 * The current set of overlays to be shown (may be empty). 38 * 39 * Note that during a transition between overlays, a different set of overlays may be rendered - 40 * but only the ones in this set are considered the current overlays. 41 */ 42 val currentOverlays: StateFlow<Set<OverlayKey>> 43 44 /** 45 * Asks for an asynchronous scene switch to [toScene], which will use the corresponding 46 * installed transition or the one specified by [transitionKey], if provided. 47 */ changeScenenull48 fun changeScene(toScene: SceneKey, transitionKey: TransitionKey? = null) 49 50 /** 51 * Asks for an instant scene switch to [toScene], without an animated transition of any kind. 52 */ 53 fun snapToScene(toScene: SceneKey) 54 55 /** 56 * Request to show [overlay] so that it animates in from [currentScene] and ends up being 57 * visible on screen. 58 * 59 * After this returns, this overlay will be included in [currentOverlays]. This does nothing if 60 * [overlay] is already shown. 61 */ 62 fun showOverlay(overlay: OverlayKey, transitionKey: TransitionKey? = null) 63 64 /** 65 * Request to hide [overlay] so that it animates out to [currentScene] and ends up *not* being 66 * visible on screen. 67 * 68 * After this returns, this overlay will not be included in [currentOverlays]. This does nothing 69 * if [overlay] is already hidden. 70 */ 71 fun hideOverlay(overlay: OverlayKey, transitionKey: TransitionKey? = null) 72 73 /** 74 * Replace [from] by [to] so that [from] ends up not being visible on screen and [to] ends up 75 * being visible. 76 * 77 * This throws if [from] is not currently shown or if [to] is already shown. 78 */ 79 fun replaceOverlay(from: OverlayKey, to: OverlayKey, transitionKey: TransitionKey? = null) 80 81 /** Asks for [overlay] to be instantly shown, without an animated transition of any kind. */ 82 fun instantlyShowOverlay(overlay: OverlayKey) 83 84 /** Asks for [overlay] to be instantly hidden, without an animated transition of any kind. */ 85 fun instantlyHideOverlay(overlay: OverlayKey) 86 87 /** 88 * If currently in a transition between contents, cancel that transition and go back to the 89 * pre-transition state. 90 */ 91 fun freezeAndAnimateToCurrentState() 92 } 93