react-native-htmlview icon indicating copy to clipboard operation
react-native-htmlview copied to clipboard

<div> not break lines

Open SunnyEver0 opened this issue 8 years ago • 4 comments

I have meet this problem, the html code

<div style="font-family: verdana, sans-serif; word-wrap: break-word;">As
    <div>A</div>
    <div>As</div>
    <div>A</div>
    <div>As</div>
    <div><br></div>
    <div>As</div>
    <div>D</div>
    <div>As</div>
    <div>D</div>
    <div>A</div>
    <div>As</div>
    <div><br></div>
    <div>A</div>
    <div>D</div>
    <div>A</div>
    <div>A</div>
    <div>D</div>
    <div><br></div>
</div>

but showed in this simulator123 and in brower 123 how to reslove this problem? thanks a lot.

SunnyEver0 avatar Aug 18 '17 03:08 SunnyEver0

Yep, this is a current bug. To more succinctly reproduce:

import React from 'react';
import HTMLView from 'react-native-htmlview'
import { StyleSheet, View } from 'react-native';

export default class App extends React.Component {
  render() {
    const htmlContent = `<div>Outer<div>Inner</div><div>Inner</div>Outer</div>`
    return (
      <HTMLView value={htmlContent} />
    )
  }
}

If you remove the outer div and instead pass an object with a style property to your HTMLView using textComponentProps, you can work around this for now (the inline style attribute on your outer div wouldn't have worked anyway):

    return (
      <HTMLView
        textComponentProps={{ style: styles.textComponent }}
        value={htmlContent} />
    )

// ...

const styles = StyleSheet.create({
  textComponent: {
    fontFamily: 'monospace'
  }
})

bas-ie avatar Aug 21 '17 04:08 bas-ie

Firstly,I'm so glad u have understood my option with my poor English.Aha,according to use this method,I have fixed this problem.But if I remove the outer div,maybe to lost the style of the whole text and using regex to remove html code of <div>, I probably think it's too complex in the front-end.

SunnyEver0 avatar Aug 21 '17 07:08 SunnyEver0

Your English is fine :smile: I hope I can devote some time to fixing the nesting issue soon, but it definitely still wouldn't support the inline style. Hope you find an alternative solution.

bas-ie avatar Aug 21 '17 19:08 bas-ie

how do we select a class and how do we define various selectors in stylesheet or style ??

<div class='main-container'>
          <div class='privacy-policy'><p>To view our privacy policy, scan the QR code below or visit https://abc.com/privacy-policy.</p></div>
      </div>

how do we select main-container here ??

4mit avatar Apr 05 '24 10:04 4mit