Returns
AnEnvironmentValues object with the following fields:
"light" | "dark"
The current appearance mode.
number
The display pixel density (e.g. 2.0 for Retina displays).
DynamicTypeSize
The user’s preferred text size setting. See DynamicTypeSize.
string
The current locale identifier (e.g.
"en_US")."leftToRight" | "rightToLeft"
Text layout direction.
{ width: number; height: number }
Screen dimensions in points.
string
The current platform (e.g.
"iOS", "web", "android").(url: string, resultCallback?: (success: boolean) => void) => void
Opens a URL using the platform’s default handler.
.environment() modifier are also available as additional properties on the returned object.
Usage
Adapt to color scheme
Responsive layout
Read custom environment values
Open a URL
Notes
useEnvironmentmust be called inside a componentbodyfunction, not at the top level.- Custom values are set via the
.environment()modifier on a parent component, e.g..environment("accentColor", "purple"). - The
screendimensions are in logical points, not physical pixels.
See Also
- OpenURLAction — custom URL handling