Skip to main content

cranpose_ui/
configuration.rs

1use cranpose_core::{CompositionLocal, compositionLocalOf};
2
3/// The kind of device the application runs on, as the type part of Android's
4/// `Configuration.uiMode` (`UI_MODE_TYPE_TELEVISION` is
5/// [`UiModeType::Television`]).
6#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
7pub enum UiModeType {
8    /// A phone, a tablet, a desktop computer or a browser.
9    #[default]
10    Normal,
11    /// A device in a desk dock.
12    Desk,
13    /// A device in a car dock or a car's own display.
14    Car,
15    /// A TV: Android TV, Google TV or Apple TV, driven by a remote.
16    Television,
17    /// A device with no display of its own, or one that is not mainly for
18    /// people to look at.
19    Appliance,
20    /// A watch.
21    Watch,
22    /// A virtual reality headset.
23    VrHeadset,
24}
25
26/// What the platform tells the application about the device, as
27/// `LocalConfiguration.current` holds in Compose.
28#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
29pub struct Configuration {
30    /// The kind of device.
31    pub ui_mode_type: UiModeType,
32}
33
34/// CompositionLocal carrying the [`Configuration`], as `LocalConfiguration`
35/// does in Compose. A TV layout reads
36/// `local_configuration().current().ui_mode_type == UiModeType::Television`.
37pub fn local_configuration() -> CompositionLocal<Configuration> {
38    crate::environment_locals::cached_local(
39        |locals| &locals.configuration,
40        || compositionLocalOf(Configuration::default),
41    )
42}