Skip to content

fix: StatusBar race conditions#1074

Merged
kirillzyusko merged 1 commit intomainfrom
fix/status-bar-events-race-condition
Aug 9, 2025
Merged

fix: StatusBar race conditions#1074
kirillzyusko merged 1 commit intomainfrom
fix/status-bar-events-race-condition

Conversation

@kirillzyusko
Copy link
Copy Markdown
Owner

@kirillzyusko kirillzyusko commented Aug 8, 2025

📜 Description

Fixed a problem when StatusBar can manipulate its properties before EdgeToEdge view was attached to the hierarchy.

💡 Motivation and Context

The original problem stems from the fact, that sometimes StatusBar module may handle setters earlier, than EdgeToEdge view was attached. As a result it adds undesired paddings and may break the keyboard controller logic.

The first my idea was adding a condition if (view() == null) { return }. However it's not very reliable, because some apps may use keyboard-controller features (OverKeyboardView, KeyboardBackgroundView etc.) without KeyboardProvider. In this case the react-native-keyboard-controller will break all StatusBar manipulations, so it's not the solution.

I started to investigate further and found out that we actually have a race condition: view may be created but not attached to hierarchy yet. In this case we forward call to original implementation. Here I wanted to fix it with code that will reset all flags that were set by StatusBar. But again the trick didn't work, because the pipeline is next:

  • view gets created/configured (I reset flags here)
  • StatusBar handles its setter
  • view gets attached to hierarchy.

So I had to put the code in onAttachedToWindow lifecycle, but I think it would make code more complicated/harder to debug in future. So I decided to re-work approach a little bit. Instead of using hierarchy as source of truth I added a registry, that holds a reference. In this case I can get more synchronous access and be sure that there is no potential race conditions.

Closes #993

📢 Changelog

Android

  • added EdgeToEdgeViewRegistry;
  • use EdgeToEdgeViewRegistry for detecting EdgeToEdge view/its properties.

🤔 How Has This Been Tested?

Tested manually on Pixel 9 PRO API 31 (emulator) with double "R" reload. Issue was reproducible more frequently if you would try to reload during reload. Or if you open first screen and then do a reload.

📸 Screenshots (if appropriate):

Screen.Recording.2025-08-09.at.15.53.03.mov

📝 Checklist

  • CI successfully passed
  • I added new mocks and corresponding unit-tests if library API was changed

@kirillzyusko kirillzyusko self-assigned this Aug 8, 2025
@kirillzyusko kirillzyusko added 🐛 bug Something isn't working 🤖 android Android specific labels Aug 8, 2025
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Aug 8, 2025

📊 Package size report

Current size Target Size Difference
212866 bytes 212821 bytes 45 bytes 📈

@kirillzyusko kirillzyusko merged commit c1d18cc into main Aug 9, 2025
16 checks passed
@kirillzyusko kirillzyusko deleted the fix/status-bar-events-race-condition branch August 9, 2025 16:22
@vicprz
Copy link
Copy Markdown

vicprz commented Oct 29, 2025

Hi @kirillzyusko, I think the bug is still present on older Android devices — more details in #1181.

Thanks!

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

Labels

🤖 android Android specific 🐛 bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Why does KeyboardController leave blank space or space of bottom after restarting the app?

2 participants