Giter VIP home page Giter VIP logo

Comments (9)

nobalmohan avatar nobalmohan commented on May 31, 2024
const styles = StyleSheet.create({
    wrapper: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center'
  }
});

from react-native-htmlview.

dan-katz avatar dan-katz commented on May 31, 2024

Is there any progress on this? textAlign: 'center' still doesn't work for me.

from react-native-htmlview.

shaibar avatar shaibar commented on May 31, 2024

@reni99, @dan-katz
I just used the following:

The HTML view usage using the renderNode prop function for custom rendering

<HTMLView value={this.props.item.description()} stylesheet={descriptionStyles}
                                          renderNode={this.renderDescription}/>

Render my node function

renderDescription = (node, index, list, parent) => {
        if (node.type === 'text') {
            return (
                <Text key={index} style={descriptionStyles.p}>
                    {entities.decodeHTML(node.data)}
                </Text>);
        } else if (node.type === 'tag') {
            return (
                <View>
                    {node.children.map(this.renderDescription)}
                </View>)
        }
        return false;
    }

Style

const descriptionStyles = StyleSheet.create({
    p: {
        color: 'white',
        fontSize: 18,
        textAlign: 'center',
    },
});

from react-native-htmlview.

TrinityHC avatar TrinityHC commented on May 31, 2024

I tried the above code, but it doesn't work. Has anyone found the solution?

from react-native-htmlview.

indrasantosa avatar indrasantosa commented on May 31, 2024

Here is what I did.

Define the element like this

const htmlContent = `<a href="http://path-to-your-link.com">link</a>`;

And use it like this

<View style={{ flex: 1, flexDirection: 'row', alignItems: 'center', justifyContent: 'center' }}>
   <HTMLView
      value={htmlContent}
   />
</View>

from react-native-htmlview.

davidruisinger avatar davidruisinger commented on May 31, 2024

The HTMLView accepts an (undocumented) style prop. So you could also apply the wrapper style directly to the HTMLView:

<HTMLView
  style={{ alignItems: 'center', justifyContent: 'center' }}
  value={ htmlString } />

from react-native-htmlview.

xsgkaka avatar xsgkaka commented on May 31, 2024

i got the solution
i use the 0.9.0. change the line 96 in htmlToElement.js to like this
<View key={index} onPress={linkPressHandler}> {linebreakBefore} {listItemPrefix} {domToElement(node.children, node)} {linebreakAfter} </View>

from react-native-htmlview.

RobPando avatar RobPando commented on May 31, 2024

@xsgkaka This throws an error of RawText "" must be wrapped in an explicit <Text> component and @flavordaaave solution only center aligns the first tag if you have multiple tags. I found a global solution, I created a PR for it #116 this makes the entire value of the component align text center. due to the implementation it is complicated to make them independently align text. But if you are looking to align the entire value then this works good.

UPDATE: I updated the PR with the actual fix, it now individually aligns each tag according to what you want, I have a nice explanation on the PR #116 about what was causing it and the fix of course.

from react-native-htmlview.

richchurcher avatar richchurcher commented on May 31, 2024

Should work as soon as 0.12 is published 😄

from react-native-htmlview.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.