grahammendick / navigation

Scene-Based Navigation for React and React Native
https://grahammendick.github.io/navigation/
Apache License 2.0
571 stars 40 forks source link

Prevented error when SearchBar is unmounted (iOS Fabric) #798

Closed grahammendick closed 3 weeks ago

grahammendick commented 3 weeks ago

Fixes #797

When the SearchBar is unmounted on Fabric the Navigation router throws an error because it tries to remove the keyPath observer twice. (This only happens on Fabric because React Native unmounts the child and then iOS calls dealloc - on the old arch React Native doesn't call removeReactSubview).

Retested the original scenario for why the keyPath observer was introduced and the problem doesn't happen on Fabric. The search results aren't shown when first tapping the search bar. So removed the keyPath observer logic on Fabric.

(Even though the double remove didn't happen on the old architecture, added a defensive check in dealloc to make sure the observer is only removed if it's still added.)

grahammendick commented 3 weeks ago

Correction - the reason it didn't happen on the old architecture was because set reactSubview to nil so it didn't do anything in dealloc. Forgot to do that on Fabric in unmount. The if check added for safety on old architecture wasn't necessary because if it's nil then iOS won't remove - but harmless to leave it in there