fyne-io / fyne

Cross platform GUI toolkit in Go inspired by Material Design
https://fyne.io/
Other
25k stars 1.39k forks source link

Theme variant broken for `theme.ColorNameHeaderBackground` on Android #4562

Open fortuna opened 9 months ago

fortuna commented 9 months ago

Checklist

Describe the bug

On Android, the theme.ColorNameHeaderBackground is getting the color for the dark variant instead of light, even if the theme is set to light.

It works fine on macOS:

image image

But on Android I get the color for the dark variant, but only for the header background:

image

How to reproduce

Run from desktop:

FYNE_THEME=light go run github.com/Jigsaw-Code/outline-sdk/x/examples/fyne-tools@latest
FYNE_THEME=dark go run github.com/Jigsaw-Code/outline-sdk/x/examples/fyne-tools@latest

To run for Android:

git clone --filter=blob:none git@github.com:Jigsaw-Code/outline-sdk.git
cd x/examples/fyne-tools
go run fyne.io/fyne/v2/cmd/fyne package -os android && adb install Net_Tools.apk

Make sure your ANDROID_NDK_HOME is set and that adb is in the PATH.

Screenshots

No response

Example code

See https://github.com/Jigsaw-Code/outline-sdk/blob/main/x/examples/fyne-tools/main.go

Relevant code:

type customTheme struct {
    fyne.Theme
}

const ColorNameOnPrimary = "OnPrimary"

func (t *customTheme) Color(name fyne.ThemeColorName, variant fyne.ThemeVariant) color.Color {
    switch name {
    case theme.ColorNameHeaderBackground:
        return t.Color(theme.ColorNamePrimary, variant)
    case theme.ColorNamePrimary:
        if variant == theme.VariantLight {
            // Dark teal.
            return color.RGBA{R: 0x00, G: 0x67, B: 0x7F, A: 255}
        } else {
            // Sky blue.
            return color.RGBA{R: 0x7C, G: 0xD2, B: 0xF0, A: 255}
        }
    case ColorNameOnPrimary:
        if variant == theme.VariantLight {
            return color.White
        } else {
            // Deep dark teal.
            return color.RGBA{R: 0x00, G: 0x35, B: 0x43, A: 255}
        }
    default:
        return t.Theme.Color(name, variant)
    }
}

func makeAppHeader(title string) *fyne.Container {
    titleLabel := &widget.RichText{Scroll: container.ScrollNone, Segments: []widget.RichTextSegment{
        &widget.TextSegment{Text: title, Style: widget.RichTextStyle{
            Alignment: fyne.TextAlignCenter,
            ColorName: ColorNameOnPrimary,
            SizeName:  theme.SizeNameHeadingText,
            TextStyle: fyne.TextStyle{Bold: true},
        }},
    }}
    settings := fyne.CurrentApp().Settings()
    bgColor := settings.Theme().Color(theme.ColorNameHeaderBackground, settings.ThemeVariant())
    return container.NewStack(canvas.NewRectangle(bgColor), titleLabel)
}

Fyne version

2.4.3

Go compiler version

1.20.4

Operating system and version

macOS Sonoma 14.2.1 arm64

Additional Information

No response

andydotxyz commented 9 months ago

Can you please verify the colour values that function returns inside your code? It is more likely relating to the UI not refreshing when the theme type is discovered than that the Theme code is randomly returning the wrong variant for a single type on a single platform.