Repository navigation
feat(android): support themeVariant on the default date and time dialogs - #1075
Open
zarek-marshall wants to merge 1 commit into
Open
zarek-marshall wants to merge 1 commit into
zarek-marshall wants to merge 1 commit into
Conversation
themeVariant was iOS-only. On Android the default (non-material) dialogs always followed the Activity's night mode, so apps with an in-app theme that differs from the system theme got a mismatched picker unless they changed the Activity's night mode at runtime. Forward themeVariant from the component and DateTimePickerAndroid.open through androidUtils.getOpenPicker to both native modules, and build each dialog on a context whose resources have the uiMode night bit forced and whose theme is created fresh from the Activity's theme resource (not copied from the Activity's live Theme). The Activity is not changed. Without themeVariant, behaviour is unchanged; material pickers are untouched. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019NZ2QVLavesbwzc7npEiDM
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.
Summary
themeVariantis currently iOS-only. On Android, the default (non-material)DatePickerDialogandTimePickerDialogalways take their light or dark look from the Activity's night mode. Apps with an in-app theme switch that differs from the system theme get a dark picker on a light screen, or the reverse. The only workaround is changing the Activity's night mode at runtime (AppCompatDelegate.setDefaultNightMode). That triggers a configuration change or recreate, which some apps avoid because it can orphan open dialogs.This PR makes Android honour
themeVariantper dialog:themeVariantis forwarded fromdatetimepicker.android.jsandDateTimePickerAndroid.openthroughandroidUtils.getOpenPicker, which rebuilds the params from a fixed field list, toRNCDatePicker.openandRNCTimePicker.open. The field is added to both TurboModule specs,index.d.tsandtypes.js.Common.applyThemeVariant(activity, args)returns aContextWrapperaround the Activity with resources fromcreateConfigurationContext(uiMode night bit forced) and a freshThemebuilt from the Activity's theme resource on those resources. The Activity's live Theme isn't copied, because it can hold attributes resolved under the other night mode. Window and system services still come from the Activity, so the dialog keeps its window token. Both dialog fragments build their dialog on this context.themeVariant, behaviour is the same as before. Material pickers (design="material") are not touched.themeVariantis no longer marked iOS only, and the Android behaviour is described.Test Plan
test/index.test.jsrunsDateTimePickerAndroid.open→getOpenPickeragainst a mocked picker module and assertsthemeVariantreaches the date and time pickers. It fails without theandroidUtils.jschange.yarn test: 32 passed. ESLint shows no new warnings. I couldn't runflow checklocally (flow-bin version mismatch with.flowconfig).What's required for testing (prerequisites)?
An Android device or emulator with the system theme set to Dark.
What are the steps to reproduce (after prerequisites)?
Render
<DateTimePicker value={new Date()} themeVariant="light" />(default design) and open it. Before this change the dialog is dark; with it, it's light. For the time picker, usemode="time".Compatibility
Checklist
README.mdexample/App.js)🤖 Generated with Claude Code