Skip to content

fix(android): restore unaccepted controlled switch toggles - #154

Merged
sbaiahmed1 merged 2 commits into
sbaiahmed1:mainfrom
OskarEichler:codex/blur-controlled-android-switch
Sep 20, 2026
Merged

sbaiahmed1 merged 2 commits into
sbaiahmed1:mainfrom
OskarEichler:codex/blur-controlled-android-switch

Conversation

@OskarEichler

@OskarEichler OskarEichler commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Fix

Add a Fabric setNativeValue command and restore the supplied value when the parent does not accept a native toggle. Record each event, including repeated rejected toggles, and leave accepted updates alone.

Compatibility / breaking changes

Behavior change: Android callers relying on an uncontrolled-looking switch must store value and update it in onValueChange. Omitting value keeps the switch off. This matches the existing iOS/web controlled Switch contract; public prop signatures are unchanged.

Verification

Actual React wrapper with a native-state/command double: absent and ignored handlers fail on baseline and restore correctly after the fix; repeated rejected toggles restore each time, accepted toggles issue no reset command. Generated native command and Kotlin manager compile against RN 0.87.1.

Combined review branch: 40 existing Jest tests across four suites, TypeScript, ESLint (three pre-existing inline-style warnings), Bob builds, web-entry graph validation and whitespace checks passed. No checked-in tests/specs were added or changed. Consumer integration passed both products’ Android Debug and iOS Simulator Debug builds, four production Metro bundles, 13 web targets and four browser-extension targets. The upstream example built for Android and iOS, exported for web, and its iOS home screen was launched and visually inspected. Physical-device, signed-release and Android runtime testing were not performed.

Closes #139

Summary by CodeRabbit

  • Bug Fixes

    • Improved switch state synchronization across platforms, restoring the controlled value when a toggle is not accepted by the parent component.
  • Documentation

    • Clarified that BlurSwitch is controlled on every platform.
    • Documented the need to update value from onValueChange to accept user toggles.
    • Added migration guidance for Android applications using controlled switches.

@coderabbitai

coderabbitai Bot commented Aug 27, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 34624e20-3e0e-4857-9911-3be7af4f268e

📥 Commits

Reviewing files that changed from the base of the PR and between ce3fb0b and 6917823.

📒 Files selected for processing (6)
  • android/src/main/java/com/sbaiahmed1/reactnativeblur/ReactNativeBlurSwitchManager.kt
  • src/BlurSwitch.tsx
  • src/ReactNativeBlurSwitchNativeComponent.ts
  • website/src/content/docs/blur-switch.mdx
  • website/src/content/docs/migration.mdx
  • website/src/content/props-data/blur-switch.ts

Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.


📝 Walkthrough

Walkthrough

BlurSwitch now restores its controlled value after a native toggle is not accepted. A codegen command connects the JavaScript reconciliation effect to the Android switch manager. Documentation describes the controlled behavior.

Changes

Controlled BlurSwitch reconciliation

Layer / File(s) Summary
Native value command
src/ReactNativeBlurSwitchNativeComponent.ts, android/src/main/java/com/sbaiahmed1/reactnativeblur/ReactNativeBlurSwitchManager.kt
Registers setNativeValue and implements it by calling the native switch's setValue.
Controlled value reconciliation
src/BlurSwitch.tsx
Stores the latest native value event, attaches a native ref, and restores the controlled value when the values differ.
Controlled behavior documentation
website/src/content/docs/blur-switch.mdx, website/src/content/docs/migration.mdx, website/src/content/props-data/blur-switch.ts
Documents that value must be updated from onValueChange to accept a toggle and that the supplied value is otherwise restored.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant NativeSwitch as ReactNativeBlurSwitch
  participant Wrapper as BlurSwitchComponent
  participant Commands
  participant Manager as ReactNativeBlurSwitchManager
  NativeSwitch->>Wrapper: onValueChange(nativeValue)
  Wrapper->>Wrapper: record nativeValue
  Wrapper->>Commands: setNativeValue(nativeRef, value)
  Commands->>Manager: setNativeValue(viewRef, value)
  Manager->>NativeSwitch: setValue(value)
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 4 files. (2 skipped: 2 … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main Android behavior change: restoring controlled switch toggles that the parent does not accept.
Linked Issues check ✅ Passed The changes satisfy #139. BlurSwitch records every Android native event with a new state object, including repeated rejected toggles. useLayoutEffect calls Commands.setNativeValue when native st…
Out of Scope Changes check ✅ Passed The changed files stay within #139. The Kotlin manager and codegen files implement the native command. The wrapper implements state reconciliation. The documentation explains the Android controlled-va…
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 4 files. (2 skipped: 2 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@DanielAraldi DanielAraldi added the android Android only label Aug 31, 2026
…-android-switch

# Conflicts:
#	src/BlurSwitch.tsx
#	src/ReactNativeBlurSwitchNativeComponent.ts
#	website/src/content/docs/migration.mdx
@sbaiahmed1
sbaiahmed1 merged commit 868b89d into sbaiahmed1:main Sep 20, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

android Android only

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Android BlurSwitch does not restore a controlled value when a toggle is rejected

3 participants