Skip to content

fix(sdk): persist theme preference and inject into all container globalProps - #57

Open
Huxpro wants to merge 1 commit into
mainfrom
03-28-fix_sdk_persist_theme_preference_and_inject_into_all_container_globalprops_sub-pages_opened_via_navigate__open_don_t_inherit_the_user_s_theme_preference_because_each_container_is_an_isolated_lynxview_with_its_own_js_runtime._the
Open

fix(sdk): persist theme preference and inject into all container globalProps#57
Huxpro wants to merge 1 commit into
mainfrom
03-28-fix_sdk_persist_theme_preference_and_inject_into_all_container_globalprops_sub-pages_opened_via_navigate__open_don_t_inherit_the_user_s_theme_preference_because_each_container_is_an_isolated_lynxview_with_its_own_js_runtime._the

Conversation

@Huxpro

@Huxpro Huxpro commented Mar 29, 2026

Copy link
Copy Markdown
Collaborator

Closes #56

Problem

Sub-pages opened via navigate()/open() don't inherit the user's in-app theme preference. Each container is an isolated LynxView with its own JS runtime — theme is determined at creation from force_theme_style (if set) or the system dark mode setting. There's no mechanism to propagate an in-app preference across containers.

Solution

Add setPreferredTheme / getPreferredTheme APIs to the SDK, backed by native persistence:

iOS (SPKGlobalPropsUtils):

SPKGlobalPropsUtils.setPreferredTheme("dark")   // persist
SPKGlobalPropsUtils.preferredTheme()              // read

Android (GlobalPropsUtils):

GlobalPropsUtils.setPreferredTheme(context, "dark")  // persist
GlobalPropsUtils.getPreferredTheme(context)           // read

The persisted value is automatically injected as preferredTheme in globalProps for every new container. Frontend ThemeProviders can read lynx.__globalProps.preferredTheme to initialize with the correct theme.

What's NOT in this PR (follow-ups)

  • Pipe method for JS to call setPreferredTheme (needs a new method in sparkling-method or debug-tool)
  • Broadcasting theme changes to already-open containers (updateGlobalProps on active views)
  • Respecting persisted preference in HybridContext.getTheme() when force_theme_style is absent

Test plan

  • iOS: call SPKGlobalPropsUtils.setPreferredTheme("dark") → open a sub-page → verify lynx.__globalProps.preferredTheme == "dark"
  • Android: call GlobalPropsUtils.setPreferredTheme(ctx, "light") → open a sub-page → verify lynx.__globalProps.preferredTheme == "light"
  • Verify preferredTheme is empty string (iOS) / absent (Android) when no preference is set

@leeekyrie leeekyrie left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We already have a globalProps named forceThemeStyle for similar feature, not sure if that match you requirement

…alProps

Sub-pages opened via navigate()/open() don't inherit the user's
theme preference because each container is an isolated LynxView
with its own JS runtime. The theme is determined at container
creation from force_theme_style or system setting, with no way
to propagate an in-app preference.

Add setPreferredTheme/getPreferredTheme to SPKGlobalPropsUtils
(iOS) and GlobalPropsUtils (Android) backed by UserDefaults /
SharedPreferences. The persisted preference is automatically
injected as preferredTheme in globalProps for every new container.

Frontend ThemeProviders can read lynx.__globalProps.preferredTheme
to initialize with the correct theme without requiring
force_theme_style on every navigation call.

Closes #56
@Huxpro
Huxpro force-pushed the 03-28-fix_sdk_persist_theme_preference_and_inject_into_all_container_globalprops_sub-pages_opened_via_navigate__open_don_t_inherit_the_user_s_theme_preference_because_each_container_is_an_isolated_lynxview_with_its_own_js_runtime._the branch from 1553d73 to bd0cd68 Compare April 29, 2026 13:07
Comment thread template/sparkling-app-template/src/components/FormField/index.tsx Fixed
Comment thread template/sparkling-app-template/src/components/FormField/index.tsx Fixed
Comment thread template/sparkling-app-template/src/components/FormField/index.tsx Fixed
Comment thread template/sparkling-app-template/src/pages/gp-container/App.tsx Fixed
Comment thread template/sparkling-app-template/src/pages/media-choose/App.tsx Fixed
Comment thread template/sparkling-app-template/src/pages/media-choose/App.tsx Fixed
Comment thread template/sparkling-app-template/src/pages/media-choose/App.tsx Fixed
Comment thread template/sparkling-app-template/src/pages/media-choose/App.tsx Fixed
Comment thread template/sparkling-app-template/src/pages/media-choose/App.tsx Fixed
Comment thread template/sparkling-app-template/src/pages/media-download/App.tsx Fixed
@Huxpro
Huxpro force-pushed the 03-28-fix_sdk_persist_theme_preference_and_inject_into_all_container_globalprops_sub-pages_opened_via_navigate__open_don_t_inherit_the_user_s_theme_preference_because_each_container_is_an_isolated_lynxview_with_its_own_js_runtime._the branch from bd0cd68 to 4bad43a Compare April 29, 2026 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Theme preference doesn't sync to sub-page containers

2 participants