Skip to content

[FREQ] Problems with using @Environment(\.colorScheme) var colorScheme #148

Open
@Kejiasir

Description

@Kejiasir

When using @Environment(\.colorScheme) var colorScheme, Xcode prompts: Accessing Environment<ColorScheme>'s value outside of being installed on a View. This will always read the default value and will not update.

Sample code:

struct SamplePopupView: BottomPopup {
    
    @Environment(\.colorScheme) var colorScheme
    
    func configurePopup(popup: BottomPopupConfig) -> BottomPopupConfig {
        popup.backgroundColour(colorScheme == .light ? .black : .white)
    }
    
    func createContent() -> some View {
        // code
    }
    
}

As Xcode suggests, it is not possible to change colors based on a colorScheme.

Is there a way to fix this?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

  • Status

    Backlog

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions