fix(sdk): persist theme preference and inject into all container globalProps - #57
Conversation
leeekyrie
approved these changes
Mar 29, 2026
leeekyrie
reviewed
Mar 29, 2026
…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
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
April 29, 2026 13:07
1553d73 to
bd0cd68
Compare
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
April 29, 2026 13:14
bd0cd68 to
4bad43a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 fromforce_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/getPreferredThemeAPIs to the SDK, backed by native persistence:iOS (
SPKGlobalPropsUtils):Android (
GlobalPropsUtils):The persisted value is automatically injected as
preferredThemeinglobalPropsfor every new container. FrontendThemeProviders can readlynx.__globalProps.preferredThemeto initialize with the correct theme.What's NOT in this PR (follow-ups)
setPreferredTheme(needs a new method in sparkling-method or debug-tool)updateGlobalPropson active views)HybridContext.getTheme()whenforce_theme_styleis absentTest plan
SPKGlobalPropsUtils.setPreferredTheme("dark")→ open a sub-page → verifylynx.__globalProps.preferredTheme == "dark"GlobalPropsUtils.setPreferredTheme(ctx, "light")→ open a sub-page → verifylynx.__globalProps.preferredTheme == "light"preferredThemeis empty string (iOS) / absent (Android) when no preference is set