fix: async view removal from onDetachedFromWindow
#244
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.
📜 Description
Remove
eventView
asynchronously.💡 Motivation and Context
It seems that before opening a universal link and before
onDetachedFromWindow
Android takes a snapshot of view hierarchy. Then inonDetachedFromWindow
we are removing a View and later Android callsdispatchDetachedFromWindow
for each view from snapshot. But since we've already removed a view it tries to call a method onnull
object reference and we are getting an expected NPE.In this PR I've reworked an approach (to one that was suggested in the thread of the issue). And I remove a view asynchronously. It shouldn't add more new issues, but it'll prevent NPE in the case described above, because we'll remove a view after
dispatchDetachedFromWindow
has been called.Also I've added deep links/universal links to both examples app (paper, fabric). In order to open an app from a link I had to:
Later I'll try to cover this scenario by e2e tests.
Closes #242
📢 Changelog
Android
this.removeKeyboardCallbacks()
asHandler(Looper.getMainLooper()).post { this.removeKeyboardCallbacks() }
🤔 How Has This Been Tested?
Tested on Pixel 7 Pro.
📸 Screenshots (if appropriate):
npe-trimmed.mp4
📝 Checklist