Skip to content

fix(android,ios): prevent blur initialization delay and z-ordering bug#99

Merged
DanielAraldi merged 2 commits into
mainfrom
fix/perf-issues-with-blur-navigation
Mar 11, 2026
Merged

fix(android,ios): prevent blur initialization delay and z-ordering bug#99
DanielAraldi merged 2 commits into
mainfrom
fix/perf-issues-with-blur-navigation

Conversation

@sbaiahmed1
Copy link
Copy Markdown
Owner

@sbaiahmed1 sbaiahmed1 commented Mar 9, 2026

On Android, remove the deferred runnable that caused a 1-second delay artifact and initialize blur immediately in onAttachedToWindow.

On iOS, ensure the blur view is inserted at index 0 to stay behind content, and update the existing hosting controller's root view instead of recreating it to fix performance and state sync issues.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed blur initialization timing on Android.
    • Corrected view layering/z-order on iOS.
  • Performance Improvements

    • Improved iOS blur/vibrancy update to avoid recreating controllers and to apply effects more efficiently.
  • Chores

    • Added iOS bundle identifier to example app and a prebuild hook for iOS.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 9, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 008c93ad-a5f6-4116-a88b-9636aafd704e

📥 Commits

Reviewing files that changed from the base of the PR and between 3da8a26 and a1f21c2.

📒 Files selected for processing (3)
  • example/app.json
  • example/package.json
  • ios/Views/VibrancyEffectView.swift

📝 Walkthrough

Walkthrough

The PR moves Android blur initialization from a delayed runnable to immediate inline calls, adjusts iOS AdvancedBlurView to insert hosting view at correct z-order and update hosting controller in place, and changes VibrancyEffectView to apply effects immediately then animate them off. Example app metadata/scripts are also updated.

Changes

Cohort / File(s) Summary
Android Initialization
android/src/main/java/com/sbaiahmed1/reactnativeblur/ReactNativeBlurView.kt
Removed deferred 1s runnable in onAttachedToWindow; now calls swapBlurRootToScreenAncestor() and initializeBlur() immediately inline.
iOS Advanced Blur
ios/Views/AdvancedBlurView.swift
Insert hosting view at index 0 when subviews exist to preserve z-order; update existing hosting controller by replacing its rootView and calling layout instead of recreating controller.
iOS Vibrancy / Effects
ios/Views/VibrancyEffectView.swift
Apply blur/vibrancy effects immediately, then run animator that clears them (reversed fractionComplete mapping) to drive intensity; removed animator-based initial effect assignment.
Example project metadata & scripts
example/app.json, example/package.json
Added expo.ios.bundleIdentifier in example/app.json; added prebuild:ios script (expo prebuild --platform ios --clean) in example/package.json.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • DanielAraldi

Poem

🐰
I hopped in, quick and spry, no pause or delay,
I nudged the views to order and kept states at bay.
Blur set true, then faded with a wink,
Faster starts and gentler kinks — that’s my trick! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: preventing blur initialization delay on Android and fixing z-ordering on iOS.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/perf-issues-with-blur-navigation

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 and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@ios/Views/AdvancedBlurView.swift`:
- Around line 102-103: The new else path calls setupHostingController() too
early and bypasses the existing layoutSubviews() guard; instead of calling
setupHostingController() unconditionally in that branch, only initialize the
hosting controller when the view has non-zero bounds (e.g. check bounds.isEmpty
or width/height > 0) or defer by returning and letting layoutSubviews() call
setupHostingController(); update the branch around setupHostingController() so
it mirrors the layoutSubviews() gating to avoid initializing before first
layout.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 757f3331-5daf-4aac-ba46-1ebd70e11972

📥 Commits

Reviewing files that changed from the base of the PR and between ad7864a and 3da8a26.

📒 Files selected for processing (2)
  • android/src/main/java/com/sbaiahmed1/reactnativeblur/ReactNativeBlurView.kt
  • ios/Views/AdvancedBlurView.swift

Comment on lines +102 to +103
} else {
setupHostingController()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Keep the initial hosting-controller creation gated on non-zero bounds.

layoutSubviews() explicitly defers setupHostingController() until the view has a real frame, but this new else path bypasses that guard. Any prop update before first layout will now recreate the original “initialize too early” behavior the file is trying to avoid.

Suggested fix
   private func updateView() {
     if let hosting = hostingController {
         // Update the existing controller's root view to avoid expensive recreation
         // This fixes performance bottlenecks and state synchronization issues
         let blurStyle = blurStyleFromString(blurTypeString)
         let swiftUIView = BasicColoredView(
           blurAmount: blurAmount,
           blurStyle: blurStyle,
           ignoreSafeArea: ignoreSafeArea,
           reducedTransparencyFallbackColor: reducedTransparencyFallbackColor
         )
         hosting.rootView = swiftUIView
         hosting.view.setNeedsLayout()
     } else {
-        setupHostingController()
+        guard bounds.width > 0 && bounds.height > 0 else { return }
+        setupHostingController()
     }
   }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@ios/Views/AdvancedBlurView.swift` around lines 102 - 103, The new else path
calls setupHostingController() too early and bypasses the existing
layoutSubviews() guard; instead of calling setupHostingController()
unconditionally in that branch, only initialize the hosting controller when the
view has non-zero bounds (e.g. check bounds.isEmpty or width/height > 0) or
defer by returning and letting layoutSubviews() call setupHostingController();
update the branch around setupHostingController() so it mirrors the
layoutSubviews() gating to avoid initializing before first layout.

@DanielAraldi DanielAraldi added bug Something isn't working android Android only ios iOS only labels Mar 10, 2026
@DanielAraldi DanielAraldi self-requested a review March 10, 2026 00:21
Copy link
Copy Markdown
Collaborator

@DanielAraldi DanielAraldi left a comment

Choose a reason for hiding this comment

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

In iOS, the VibrancyView isn't working:
Image

In Android, the build breaks:

Error: /Users/danielsaraldi/Documents/react-native-blur/example/android/gradlew app:assembleDebug -x lint -x test --configure-on-demand --build-cache -PreactNativeDevServerPort=8081 -PreactNativeArchitectures=arm64-v8a exited with non-zero code: 1

Copy link
Copy Markdown
Collaborator

@DanielAraldi DanielAraldi left a comment

Choose a reason for hiding this comment

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

LGTM!

Android works, I have cleaned it, and it works haha 😂

@DanielAraldi DanielAraldi merged commit 2bf8aee into main Mar 11, 2026
6 checks passed
@DanielAraldi DanielAraldi deleted the fix/perf-issues-with-blur-navigation branch March 11, 2026 11:35
@sbaiahmed1
Copy link
Copy Markdown
Owner Author

LGTM!

Android works, I have cleaned it, and it works haha 😂

I was going to ask you to clean the cache xD perfect!!! 👌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

android Android only bug Something isn't working ios iOS only

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants