Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/simonnickel/fb13214002-swiftuipreferredcolorschemetonilinsheet
https://github.com/simonnickel/fb13214002-swiftuipreferredcolorschemetonilinsheet
Last synced: 24 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/simonnickel/fb13214002-swiftuipreferredcolorschemetonilinsheet
- Owner: simonnickel
- Created: 2023-09-29T09:45:41.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-09-29T11:32:00.000Z (over 1 year ago)
- Last Synced: 2024-12-16T16:06:20.196Z (25 days ago)
- Language: Swift
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# FB13214002 - Setting PreferredColorScheme to nil does not work in sheet.
## Scenario
An app opens a sheet to show a toggle to override the preferredColorScheme of the app.
The device is in .light colorScheme.
When the toggle is enabled it is set to .dark via preferredColorScheme.
When the toggle is disabled it should follow system settings.## Issue
Disabling the override by setting the preferredColorScheme to nil does work on the main view, but not inside the sheet.
## Example Code
The example shows a Button to open the sheet.
The sheet contains a toggle to override to dark mode.Device: Any iPhone Simulator.
1. Make sure the device is in light mode.
2. Open the sheet.
3. Enable the toggle.
-> Everything is dark.
4. Disable the toggle.
-> Only the background view is back to light, the sheet stays dark.## Workaround
Set the preferredColorScheme inside of the sheet with the colorScheme form the Environments from outside of the sheet.
```
@Environment(\.colorScheme) private var colorScheme
view.sheet {
view.preferredColorScheme(isDark ? .dark : colorScheme)
}```
## Tested on
- Xcode Version 15.0 (15A240d): iPhone 15 Pro (iOS 17.0 (21A328)) Simulator