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.
π 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 haveheight=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
context.hashCode
as identifier for attached listener (instead of global boolean variable);π€ How Has This Been Tested?
Tested manually on pixel 3a (API 33, Android 13, emulator).
πΈ Screenshots (if appropriate):
π Checklist