fix(SNOTES-468): use injectJavascript to set safe area inset vars #2907
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.
I've only been able to repro this on my production app by leaving the app open (minimized) overnight and then focusing on it again the next day. I'm not entirely sure what's going on, but I suspect that in those conditions either the effect that triggers the message to update the insets isn't fired, or the condition that checks for
didAppLaunch
before sending the message returns false.This PR sets the CSS safe area inset vars using
injectJavascript
instead ofpostMessage
. Injecting JS is actually the recommended way to pass information from RN to Web per the react-native-webview docs, and there's an example in the docs where this is used to update the background color of the webview https://github.com/react-native-webview/react-native-webview/blob/master/docs/Guide.md#the-injectjavascript-method. This will run on every render, and that way we ensure that the correct inset paddings are always being set.