Use viewDidChangeBackingProperties to remove the use of notifications in RCTImageView #1834
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Please select one of the following
Summary
In some rare cases a react native app on macOS would crash with the following message:
The notification center is supposed to check if the object subscribed to the notification still exists before calling the registered selector for the notification. This is supposed to relieve us from having to remove the observer when deallocating the observing object.
In these rare crashes I assume another NSObject got allocated at the same address as what was previously an observing RCTImageView and the notification center may have considered the observer still active and sent the registered selector to it.
To fix the potential bug and also remove a couple differences with React Native this PR removes the need for notification subscriptions by using the NSView
viewDidChangeBackingProperties
instead.Changelog
[macOS] [CHANGED] - Use viewDidChangeBackingProperties for image reloads on backing properties change
Test Plan
Tested by running RNTester on macOS with paper and dragging the window from a 1.0 backing scale factor display to a 2.0 backing scale factor display and checking that the image reload happens in the debugger.
Screen.Recording.2023-05-30.at.23.47.47.mov