在页面渲染之前将JavaScript或CSS注入React Native WebView

Nar*_*igo 2 webview react-native

我想隐藏我嵌入到React Native WebView中的特定页面的标题.目前,我使用这样的东西,动态删除标题:

<WebView 
  ... some other props ...
  injectedJavaScript={'function hideHead(){document.getElementById("head").style.display="none";};hideHead();'}
  />
Run Code Online (Sandbox Code Playgroud)

有时您仍然可以看到标题闪烁,所以我猜这个JavaScript在WebView中加载页面后会被评估.

是否有可能在页面渲染删除闪烁之前添加/注入JavaScript或CSS?

Nar*_*igo 5

在页面加载之前,我找不到注入JavaScript或CSS的方法.

为了解决闪烁的问题,我把另一个View放在了WebView它仍处于loading状态的状态.该onNavigationStateChanged回调可以用来找出该页面是否被加载.该View放在上面我简单地显示了一个ActivityIndicatorIOS.