【问题标题】:React Native WebView rendering unexpected border at bottomReact Native WebView 在底部呈现意外边框
【发布时间】:2017-05-02 11:37:34
【问题描述】:

这有点难以描述。我正在使用 react native WebView 组件来制作迷你浏览器。它工作正常,但底部有一个奇怪的黑色边框,我没有放入。它在滚动到或超出网页底部时出现。

您可以在下面的“blah”文本上方看到细黑线。废话文本和底部粉红色部分的原因是为了排除 WebView 或其容器上的流浪 borderBottom* 样式。

另外需要注意的是,在重新加载页面时,边框会短暂消失,所以它似乎在 WebView 的 html 中。但我不明白如何或为什么,因为 a) 它出现在所有网站上,b) 它没有出现在其他 iOS 浏览器中。

我在这里做了什么奇怪的事情吗?

截图:

元素和样式:

<View style={styles.container as any}>
    <View style={styles.header as any}>
      {this.addressbarButtonProps().map(props => React.createElement(Button, { ...props, key: props.title }))}
      <TextInput
        ref={ADDRESSBAR_REF}
        placeholder="type url"
        style={{ minWidth: this.screenWidth - 50 * this.addressbarButtonProps().filter(b => !b.hidden).length - 10 }}
        />
    </View>
    <WebView
      ref={WEBVIEW_REF}
      source={{uri: this.state.uri}}
      style={{ ...styles.web, width: this.screenWidth, paddingBottom: 0, padding: 0 }}
      scalesPageToFit={true}
      allowsInlineMediaPlayback={true}
      onMessage={m => this.onMessage(m.nativeEvent.data)}
      injectedJavaScript={js}
      startInLoadingState={true}
    />
    <Text style={{ borderTopWidth:20, borderTopColor: "red" }}>blah</Text>
  </View>

const styles = {
  container: {
    paddingTop: 20,
    flex: 1,
    alignItems: "center",
    justifyContent: "space-between",
    backgroundColor: "#fafafa",
    borderBottomColor: "pink",
    borderBottomWidth: 100
  },
  header: {
    flexDirection: "row",
    alignItems: "flex-start",
    justifyContent: "flex-start",
    alignSelf: "stretch"
  },
  web: {
    flex: 1,
    borderBottomColor: "#fafafa",
    backgroundColor: "#fafafa"
  }
}

【问题讨论】:

    标签: ios reactjs react-native react-native-ios


    【解决方案1】:

    将WebView的backgroundColor设置为透明,“边框”不会被渲染。

    <Webview style={{backgroundColor: 'transparent'}} .../>
    

    【讨论】:

    • 一直在拖我的头发关于这个。先生,您救了一条命!非常非常非常感谢!
    • 我们遇到过类似的问题,内容水平滚动和边框呈现在容器的右边缘。该解决方案也适用于此,谢谢!
    猜你喜欢
    • 1970-01-01
    • 2019-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-05
    • 1970-01-01
    • 2017-10-14
    相关资源
    最近更新 更多