Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Theme variant broken for theme.ColorNameHeaderBackground on Android #4562

Open
2 tasks done
fortuna opened this issue Jan 24, 2024 · 1 comment
Open
2 tasks done

Theme variant broken for theme.ColorNameHeaderBackground on Android #4562

fortuna opened this issue Jan 24, 2024 · 1 comment
Labels
unverified A bug that has been reported but not verified

Comments

@fortuna
Copy link

fortuna commented Jan 24, 2024

Checklist

  • I have searched the issue tracker for open issues that relate to the same problem, before opening a new one.
  • This issue only relates to a single bug. I will open new issues for any other problems.

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

@fortuna fortuna added the unverified A bug that has been reported but not verified label Jan 24, 2024
@andydotxyz
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
unverified A bug that has been reported but not verified
Projects
None yet
Development

No branches or pull requests

2 participants