Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: apply monkey patch before StatusBar updates #744

Merged
merged 1 commit into from
Dec 24, 2024

Conversation

kirillzyusko
Copy link
Owner

@kirillzyusko kirillzyusko commented Dec 23, 2024

📜 Description

Execute monkey-patch applying earlier than StatusBar modifications.

💡 Motivation and Context

It happens when KeyboardProvider had direct child as StatusBar - and such thing can happen in expo-router, for example: https://github.com/expo/expo/blob/5f40a80019bb6b892eda94dd244fdc0df8880ccb/packages/expo-router/src/ExpoRoot.tsx#L57

To prevent this problem I'm executing monkey patch applying in "layout effect" instead of plain "effect". This gives me a precious time and an ability to apply patch earlier and thus re-direct a call to my module.

And if we dig a little bit deeper. When KeyboardProvider gets mounted the useLayoutEffect will be fired after component mount. On contrast StatusBar will try to change its properties in componentDidMount. And technically componentDidMount will be executed first (before useLayoutEffect). But StatusBar schedules update via setImmediate and setImmediate will execute its callback after useLayoutEffect, so this fix should work 🙂

Closes #708 #587

📢 Changelog

Android

  • apply monkey patch in layout effect to be sure monkey patch can be applied earlier than first call to StatusBar module (if KeyboardProvider and StatusBar were mounted simultaneously).

🤔 How Has This Been Tested?

Tested manually in https://github.com/NyoriK/keyboard-controller-test-project

📸 Screenshots (if appropriate):

Screen.Recording.2024-12-23.at.15.41.19.mov

📝 Checklist

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

Copy link
Contributor

📊 Package size report

Current size Target Size Difference
164463 bytes 164442 bytes 21 bytes 📈

@kirillzyusko kirillzyusko marked this pull request as ready for review December 23, 2024 14:42
@kirillzyusko kirillzyusko changed the title fix: apply monkey patch synchronously fix: apply monkey patch before StatusBar updates Dec 23, 2024
@kirillzyusko kirillzyusko merged commit 19371d8 into main Dec 24, 2024
12 checks passed
@kirillzyusko kirillzyusko deleted the fix/apply-monkey-patch-synchronously branch December 24, 2024 10:31
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
1 participant