Repository navigation
feat(android): add blurBehindRadius to Modal - #60217
Open
kagantemizkan wants to merge 1 commit into
Open
kagantemizkan wants to merge 1 commit into
kagantemizkan wants to merge 1 commit into
Conversation
Adds an Android-only `blurBehindRadius` prop (dp) to Modal. On Android 12+ the modal window sets FLAG_BLUR_BEHIND and setBlurBehindRadius, so the system compositor blurs the windows behind it without copying the content. When cross-window blur is unavailable or turned off, the window behind is dimmed instead. A cross-window blur listener keeps this in sync while the modal is shown. Changing the radius updates the open dialog without recreating it. Adds a "Modal blur behind" RNTester example with a radius slider.
This branch has not been deployed
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
Adds an Android-only
blurBehindRadiusprop (dp) toModal. When set on atransparentmodal, the system blurs the app behind the modal window with the window blur Android has shipped since 12 (WindowManager.LayoutParams.FLAG_BLUR_BEHIND+setBlurBehindRadius). The compositor draws the blur, so there is no snapshot of the content and no per-frame drawing in the app, unlike JS/view based blur libraries that copy the backdrop every frame.ReactModalHostView.updateProperties, so changing the radius while the modal is open updates the window without recreating the dialog.WindowManager.isCrossWindowBlurEnabledis false: no GPU support, tunnel mode, "Allow window-level blurs" turned off, or OEM power saving), the window behind is dimmed instead (FLAG_DIM_BEHIND, 0.5), so the modal is still set apart from what it covers. AaddCrossWindowBlurEnabledListenerkeeps this in sync while the modal is shown and is removed on dismiss.animationTypefade/slide andstatusBarTranslucent/navigationBarTranslucentkeep working.Naming: the other Android-only Modal props (
hardwareAccelerated,statusBarTranslucent,navigationBarTranslucent) and the codegen specs are unprefixed, so this follows that instead ofandroid_*. Happy to rename (e.g.android_blurBehindRadius) if preferred.Not included (possible follow-up):
Window.setBackgroundBlurRadiusfor blurring the dialog's own background.Changelog:
[ANDROID] [ADDED] - Add
blurBehindRadiusprop toModalto blur the content behind it with the system window blur (Android 12+)Test Plan:
New RNTester example: Modal → "Modal blur behind" (radius slider 0–80 dp outside and inside the modal, animation type chips).
Tested with RNTester (debug, arm64) on:
Checked on both:
dumpsys windowshowsfl=BLUR_BEHINDandblurBehindRadius= radius × density.adb shell settings put global disable_window_blurs 1while the modal is open: the listener fires, the window switches toDIM_BEHIND; setting it back to 0 restores the blur.animationTypefade and slide open and close normally (recorded frame by frame on the Redmi).Known behavior: the system applies the blur as soon as the window is added and removes it when the exit animation starts, so with
fade/slidethe blur appears/disappears at once while the modal content animates. This is how window blur-behind works on Android today; animating the radius would need a per-frame window attribute update and is left out of this change.yarn flow check, eslint, prettier and ktfmt pass.Screenshots
Landscape with the modal open (emulator, SDK 37.2):