Skip to content

feat: add per-instance theme engine - #513

Merged
volodymyr-chekyrta merged 4 commits into
openedx:developfrom
raccoongang:infra/03-theme-engine
Oct 27, 2026
Merged

volodymyr-chekyrta merged 4 commits into
openedx:developfrom
raccoongang:infra/03-theme-engine

Conversation

@IvanStepanok

Copy link
Copy Markdown
Contributor

Base: #512

Summary

Adds the theme engine. Port of openedx-app-ios#675 (forwarded to develop in #684). Given an instance's accent color and its optional THEME.LIGHT / THEME.DARK overrides, InstanceTheme derives the palette: only the fields an instance sets change, everything else keeps the compiled default, and a field missing from DARK uses its LIGHT value.

Design notes

  • Themes are identified by the stable instance key, never by a display name.
  • InstanceTheme takes primitives, not the Instance model, so the theme layer doesn't depend on how instances are configured.
  • The palette field names are the ones iOS uses (accent_color, text_primary, card_view_background, ...), mapped onto Android's AppColors, so one catalog can brand both apps. The accent drives every color the default palette derives from primary. Unknown names and invalid hex values are ignored.
  • OpenEdXTheme observes InstanceThemeManager, so applying a theme restyles every Compose screen. Unlike iOS, where the final app applies only the accent color, the whole derived palette is applied.

Not included in this PR

  • Nothing applies a theme yet; every screen still renders the default palette.
  • Logo and header images: rendered by the picker PR.

Testing

  • InstanceThemeTest (8 cases: derivation, partial overrides, per-mode accent, dark fallback, light/dark independence, ignored input, hex parsing, manager state)
  • ./gradlew detektAll testProdDebugUnitTest :app:assembleProdDebug

Note

This is the 3rd pull request of the multi-instance stack.

Introduces Instance and InstancesConfig: what one Open edX platform is and how it is
parsed from the INSTANCES block of the bundled config. Nothing reads it yet.

Required fields are NAME, API_HOST_URL and OAUTH_CLIENT_ID; a malformed entry is dropped.
KEY falls back to a slug of NAME, INSTANCE_NAME is localized with an English fallback,
and PLATFORM_NAME defaults to the display name. The schema matches iOS (#672).
InstanceStore holds the instance catalog and the selected instance, persists the
selection by key and publishes it as a StateFlow. A single-instance catalog selects its
only instance automatically. Registered in Koin as InstanceStore and InstanceProvider;
nothing consumes it yet. Mirrors iOS #673.
InstanceTheme derives a palette from an instance's accent color and its optional
THEME.LIGHT/THEME.DARK overrides: only the fields an instance sets change, the rest keep
the compiled default, and a missing dark value falls back to the light one. Palette field
names are the ones iOS uses (#675), mapped onto AppColors.

OpenEdXTheme observes InstanceThemeManager, which holds the selected instance's theme.
Nothing applies a theme yet, so every screen still renders the default palette.
@IvanStepanok IvanStepanok mentioned this pull request Oct 19, 2026
1 task done
@openedx-webhooks openedx-webhooks added open-source-contribution PR author is not from Axim or 2U core contributor PR author is a Core Contributor (who may or may not have write access to this repo). labels Oct 19, 2026
@openedx-webhooks

Copy link
Copy Markdown

Thanks for the pull request, @IvanStepanok!

This repository is currently maintained by @openedx/openedx-mobile-maintainers.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

Details
Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

RawanMatar89
RawanMatar89 previously approved these changes Oct 21, 2026
fun applyTo(base: AppColors, isDark: Boolean): AppColors {
val modeAccent = if (isDark) dark[ACCENT_COLOR] ?: light[ACCENT_COLOR] else light[ACCENT_COLOR]
var colors = (modeAccent ?: accentColorHex)?.toColorOrNull()?.let(base::withAccent) ?: base
light.forEach { (field, lightHex) ->

@RawanMatar89 RawanMatar89 Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a concern here, I think any dark key only with no light key will be ignored. @IvanStepanok please check before merge

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, you're right. applyTo only walked the light keys, so a field set only under DARK was dropped.

Fixed in 587193f. It now walks both maps: dark mode uses the dark value, else the light one; light mode uses only the light value, so a dark-only field leaves light mode on the default. There's a unit test for it now.

Screenshot below: Verawood South with background, text_primary and the text input colors set only under DARK. Dark mode before and after the fix, then light mode after the fix, which stays on the default palette.

Dark-only palette fields, before and after

Could you take another look?

applyTo walked only the light keys, so a field present in the dark map
alone was dropped. It now walks both: dark mode uses the dark value, else
the light one; light mode uses only the light value, so a dark-only field
leaves light mode on the compiled default.
IvanStepanok added a commit to raccoongang/openedx-app-android that referenced this pull request Oct 21, 2026
@mphilbrick211 mphilbrick211 moved this from Needs Triage to Ready for Review in Contributions Oct 22, 2026
@volodymyr-chekyrta
volodymyr-chekyrta merged commit b11783a into openedx:develop Oct 27, 2026
6 checks passed
@github-project-automation github-project-automation Bot moved this from Ready for Review to Done in Contributions Oct 27, 2026
@volodymyr-chekyrta
volodymyr-chekyrta deleted the infra/03-theme-engine branch October 27, 2026 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core contributor PR author is a Core Contributor (who may or may not have write access to this repo). open-source-contribution PR author is not from Axim or 2U

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants