kirillzyusko / react-native-keyboard-controller

Keyboard manager which works in identical way on both iOS and Android
https://kirillzyusko.github.io/react-native-keyboard-controller/
MIT License
1.38k stars 55 forks source link

fix: memoize `WindowDimensionListener` on per context base (instead of global memoization) #492

Closed kirillzyusko closed 2 days ago

kirillzyusko commented 3 days ago

πŸ“œ Description

Re-create WindowDimensionListener if context gets changed.

πŸ’‘ Motivation and Context

We need to memoize WindowDimensionListener and have a single listener across the app to avoid potential and unnecessary multiple events (many listeners will produce many events at the same time and it will just hit performance and will consume more memory, resources etc. so it's highly undesirable).

However, when you reload the RN app (double R press) -> you will re-create all internal variables and you will not attach a new listener. And the problem is in the fact that old listener will be destroyed (and even if not destroyed -> then it will not propagate events because the context was destroyed). And we'll always have height=0.

Of course such behavior is not correct and the proper solution would be to re-attach listener when app is re-loaded. I handled it in this PR by caching listener using context hash as an identifier for an active listener.

Closes https://github.com/kirillzyusko/react-native-keyboard-controller/issues/486

πŸ“’ Changelog

Android

πŸ€” How Has This Been Tested?

Tested manually on pixel 3a (API 33, Android 13, emulator).

πŸ“Έ Screenshots (if appropriate):

Before After

πŸ“ Checklist

github-actions[bot] commented 3 days ago

πŸ“Š Package size report

Current size Target Size Difference
144205 bytes 144183 bytes 22 bytes πŸ“ˆ