Mhret Aatifa

Mhret Aatifa

1597315560

iOS/Android pure javascript react-native component that renders your HTML

react-native-render-html

Based on the original work of Thomas Beverley, props to him.

An iOS/Android pure javascript react-native component that renders your HTML into 100% native views. It’s made to be extremely customizable and easy to use and aims at being able to render anything you throw at it.

Versions

⚠️ You are on the master branch which is home for the latest development. Check the table bellow to get documentation for your exact version. Because the patch version is irrelevant regarding the features of one version, we will point to the last patch release of a minor version. You can read our full branching policy in the MAINTAINING.adoc file.

⚠️ We indulged ourselves when releasing 4.2.0 regarding Semantic Versioning, because we introduced react-native-webview as a peer dependency. As a result, you need to install it yourself. Please follow the plugin’s instructions. We have since deliberately committed to Semantic Versioning.

Stable releases

Minor Branch Documentation Test Status Latest
4.2 release/4.2 release/4.2/README.md CI npm
4.1 release/4.1 release/4.1/README.md CI npm
4.0 release/4.0 release/4.0/README.md CI npm

Pre-releases

Tag Branch Test Status Latest
next dev/4.x CI
unstable master CI

Install

npm install react-native-render-html

🌇 To try out pre-releases up-to-date with development, including many fixes, you are encouraged to install the next tag versions. With our (new) test-first approach, the fixes and features in this branch will have been tested, so the chances you encounter a bug is pretty low. If you encounter any issue on a pre-release, you don’t need to fill a full bug report. Just comment our latest release thread. To install the next version:

npm install react-native-render-html@next

If you wish, you can also try directly the master branch:

npm install "github:archriss/react-native-render-html#master"

Basic usage

import React, { Component } from "react";
import { ScrollView, Dimensions } from "react-native";
import HTML from "react-native-render-html";

const htmlContent = `
    <h1>This HTML snippet is now rendered with native components !</h1>
    <h2>Enjoy a webview-free and blazing fast application</h2>
    <img src="https://i.imgur.com/dHLmxfO.jpg?2" />
    <em style="textAlign: center;">Look at how happy this native cat is</em>
`;

export default class Demo extends Component {
  render() {
    return (
      <ScrollView style={{ flex: 1 }}>
        <HTML
          html={htmlContent}
          imagesMaxWidth={Dimensions.get("window").width}
        />
      </ScrollView>
    );
  }
}

Props

Prop Description Type Required/Default
renderers Your custom renderers object Optional, some default ones are supplied (<a>, <img>…)
renderersProps Set of props accessible into your custom renderers in passProps (4th argument) object Optional
html HTML string to parse and render string Required
uri (experimental) remote website to parse and render string Optional
decodeEntities Decode HTML entities of your content bool Optional, defaults to true
imagesMaxWidth Resize your images to this maximum width, see images number Optional
staticContentMaxWidth Set a maximum width to non-responsive content (<iframe> for instance) number Optional
imagesInitialDimensions Default width and height to display while image’s dimensions are being retrieved, see images { width: 100, height: 100 } Optional
onLinkPress Fired with the event, the href and an object with all attributes of the tag as its arguments when tapping a link function Optional
onParsed Fired when your HTML content has been parsed. Also useful to tweak your rendering, see onParsed function Optional
tagsStyles Provide your styles for specific HTML tags, see styling object Optional
classesStyles Provide your styles for specific HTML classes, see styling object Optional
listsPrefixesRenderers Your custom renderers from ul and ol bullets, see lists prefixes object Optional
containerStyle Custom style for the default container of the renderered HTML object Optional
customWrapper Replace the default wrapper with a function that takes your content as the first parameter function Optional
remoteLoadingView Replace the default loader while fetching a remote website’s content function Optional
remoteErrorView Replace the default error if a remote website’s content could not be fetched function Optional
emSize The default value in pixels for 1em number 14
ptSize The default value in pixels for 1pt number 1.3
baseFontStyle The default style applied to <Text> components object { fontSize: 14 }
allowFontScaling Specifies whether fonts should scale to respect Text Size accessibility settings boolean true
textSelectable Allow all texts to be selected boolean false
alterData Target some specific texts and change their content, see altering content function Optional
alterChildren Target some specific nested children and change them, see altering content function Optional
alterNode Target a specific node and change it, see altering content function Optional
ignoredTags HTML tags you don’t want rendered, see ignoring HTML content array Optional, ['head', 'script', ...]
allowedStyles Allow render only certain CSS style properties and ignore every other. If you have some property both in allowedStyles and ignoredStyles, it will be ignored anyway. array Optional, everything is allowed by default
ignoredStyles CSS styles from the style attribute you don’t want rendered, see ignoring HTML content array Optional
ignoreNodesFunction Return true in this custom function to ignore nodes very precisely, see ignoring HTML content function Optional
debug Prints the parsing result from htmlparser2 and render-html after the initial render bool Optional, defaults to false

Demo

This component comes with a demo that showcases every feature presented here. It’s very useful to keep track of bugs and rendering differences between the different versions of react-native.

It is mandatory to refer to an example of the demo or to provide one when submitting an issue or a pull request for a new feature.

Feel free to write more advanced examples and submit a pull-request for it, it will probably be very useful for other users.

Creating custom renderers

This is very useful if you want to make some very specific styling of your HTML content, or even implement custom HTML tags.

Custom HTML tags

Just pass an object to the renderers prop with the tag name as the key, an a function as its value, like so :

renderers: {
  hr: () => (
    <View style={{ width: "100%", height: 1, backgroundColor: "blue" }} />
  );
}

Here, we have overriden the default <hr /> renderer and made it a blue line.

You can also create your own tags and use them in your HTML content :

const content = `<bluecircle></bluecircle>`;
...

renderers: {
    bluecircle: () => <View style={{ width: 20, height: 20, borderRadius: 10, backgroundColor: 'blue' }} />
}

Your renderers functions receive several arguments that will be very useful to make some very specific rendering.

  • htmlAttribs: attributes attached to the node, parsed in a react-native way
  • children : array with the children of the node
  • convertedCSSStyles : conversion of the style attribute from CSS to react-native’s stylesheet
  • passProps : various useful information : your renderersProps, groupInfo, parentTag, parentIsText

Making your custom component block or inline

By default, a custom renderer behaves like a block. So if you’re rendering it between texts inside a <p>, you’ll break your line.

If you want it to be inline, you can slightly change the way you declare it, like this :

renderers: {
    mytag: { renderer: myTagRenderer, wrapper: 'Text' }, // new way, is inline
    myothertag: myOtherTagRenderer // old regular way (still valid, behaves like a block)
}

Note : the only values for wrapper are Text or View (default). Those don’t represent the <View> and <Text> component of react-native but are instead used in the parser to prevent crashes and properly render every HTML markup.

Lists prefixes

The default renderer of the <ul> and <ol> tags will either render a bullet or the count of your elements. If you wish to change this without having to re-write the whole list rendering implementation, you can use the listsPrefixesRenderers prop.

Just like with the renderers prop, supply an object with ul and/or ul as functions that receive the same arguments as your custom HTML tags. For instance, you can swap the default black bullet of <ul> with a blue cross :

// ... your props
ul: (htmlAttribs, children, convertedCSSStyles, passProps) => {
  return <Text style={{ color: "blue", fontSize: 16 }}>+</Text>;
};

Styling

In addition to your custom renderers, you can apply specific styles to HTML tags (tagsStyles) or HTML classes (classesStyles). You can also combine these styles with your custom renderers.

Styling options override themselves, so you might render a custom HTML tag with a custom renderer like <bluecircle>, make it green with a class <bluecircle class="make-me-green"> or make it red by styling the tag itself.

The default style of your custom renderer will be merged to the one from your classesStyles which will also be merged by the style attribute.

IMPORTANT NOTE : Do NOT use the StyleSheet API to create the styles you’re going to feed to tagsStyle and classesStyles. Although it might look like it’s working at first, the caching logic of react-native makes it impossible for this module to deep check each of your style to properly apply the precedence and priorities of your nested tags’ styles.

Here’s a usage example

// props
    tagsStyles: { i: { textAlign: 'center', fontStyle: 'italic', color: 'grey' } },
    classesStyles: { 'last-paragraph': { textAlign: 'right', color: 'teal', fontWeight: '800' } }

const html = `
    <i>Here, we have a style set on the "i" tag with the "tagsStyles" prop.</i>
    <p class="last-paragraph">Finally, this paragraph is styled through the classesStyles prop</p>`;

Images

By default, unstyled images will be rendered with their respective height and width without resizing. You can force their dimensions by using the style attribute in your HTML content or style them with a class or through the <img> tag.

If you can’t set the dimension of each image in your content, you might find the imagesMaxWidth prop useful. It resizes (and keeps proportions) your images to a maximum width, ensuring that your images won’t overflow out of your viewport.

A nice trick, demonstrated in the basic usage of this module is to use the Dimensions API of react-native : imagesMaxWidth={Dimensions.get('window').width}. You could subtract a value to it to make a margin.

Please note that if you set width AND height through any mean of styling, imagesMaxWidth will be ignored.

Before their dimensions have been properly retrieved, images will temporarily be rendered in 100px wide squares. You can override this default value with prop imagesInitialDimensions.

Images with broken links will render an empty square with a thin border, similar to what safari renders in a webview.

Please note that all of these behaviors are implemented in the default <img> renderer. If you want to provide your own <img> renderer, you’ll have to make this happen by yourself. You can use the img function in HTMLRenderers.js as a starting point.

Altering content

alterData and alterChildren props are very useful to make some modifications on the structure of your HTML before it’s actually rendered with react components.

They both are functions that receive the parsed node as their first and only parameter. You must return your changes: a string with alterData and an array with alterChildren or a falsy value if you don’t need to change anything.

alterData

alterData allows you to change the text content of your nodes. For instance, you can customize the content of <h1> and <h2> to render your titles in uppercase.

Here’s how you would do that :

// ... your props
alterData: (node) => {
  let { parent, data } = node;
  if (parent && parent.name === "h1") {
    // Texts elements are always children of wrappers, this is why we check the tag
    // with "parent.name" and not "name"
    return data.toUpperCase();
  }
  // Don't return anything (eg a falsy value) for anything else than the <h1> tag so nothing is altered
};

alterChildren

alterChildren allows you to change the children wrapped in any node. For instance, you might want to change the content of a list.

Here’s an example :

// ... your props
alterChildren: (node) => {
  const { children, name } = node;
  if (name === "ol" && children && children.length) {
    // Keep only the first two elements of the list
    return children.splice(0, 2);
  }
  // Don't return anything (eg a falsy value) for anything else than the <ol> tag so nothing is altered
};

alterNode

alterNode allows you to change the values parsed from your HTML before it’s rendered. It’s extremely powerful as a last resort to add some very specific styling or circumvent rendering problems.

Here’s an advanced example where you would change the color of links inside a <blockquote> :

alterNode: (node) => {
  const { name, parent } = node;
  // If the tag is an <a> and we've found a parent to be a blockquote
  // (see the utils part of this documentation to know more about getParentsTagsRecursively)
  if (
    name === "a" &&
    getParentsTagsRecursively(parent).indexOf("blockquote") !== -1
  ) {
    // Let's assign a specific color to the node's attribs (if there already are)
    node.attribs = { ...(node.attribs || {}), style: `color:lightblue;` };
    return node;
  }
  // Don't return anything (eg a falsy value) for anything else so nothing is altered
};

onParsed

onParsed is a callback and lets you know when your HTML has been parsed. Its first argument is the dom array from htmlparser2, its second is RNElements which is the result of the parsing of this module.

If you want to tweak the parsed values, you can change RNElements and return it. For instance, you could insert one of your custom component although it was not in your HTML content, like this :

onHTMLParsed = (dom, RNElements) => {
  // Find the index of the first paragraph
  const ad = {
    wrapper: "View",
    tagName: "mycustomblock",
    attribs: {},
    parent: false,
    parentTag: false,
    nodeIndex: 4,
  };
  // Insert the component
  RNElements.splice(4, 0, ad);
  return RNElements;
};

Ignoring HTML content

You can’t expect native components to be able to render everything you can find in your browser. And you might not entirely trust your contributors, so here are 3 props allowing you to prevent disasters without sanitizing your HTML on the server-side (that doesn’t mean you shouldn’t !).

  • ignoredTags : array of ignored HTML tags, by default head and scripts are removed
  • ignoredStyles : array of ignored CSS rules. Nothing is ignored by default
  • ignoreNodesFunction : this is a cumbersome, yet powerful, way of ignoring very specific stuff.

Please note that if you supply ignoredTags, you will override the default ignored ones. There are a lot of them, if you want to keep them and add your own, you can do something like :

import { IGNORED_TAGS } from 'react-native-render-html/src/HTMLUtils';
...

// your props
ignoredTags={[ ...IGNORED_TAGS, 'tag1', 'tag2']}

ignoreNodesFunction receives 3 parameters : node, parentTagName and parentIsText.

node is the result of the HTML parsing, which allows you to look for children, check the parent’s markup and much more. parentTagName is a convenient way to access the parent of your node, and parentIsText is a great way to make sure you won’t be rendering a <View> inside a <Text> which, right now, makes react-native crash.

Useful functions

The API is exposing some functions you can use to write advanced behaviors more easily. You can import them like so :

import { functionName } from "react-native-render-html/src/HTMLUtils";
  • getParentsTagsRecursively(node)
    • Description : Returns an array with the tagname of every parent of a node or an empty array if nothing is found.
    • Parameters : - node : a parsed HTML node from alterChildren for example
    • Returns : An empty array or an array of strings.
    • Notes : this is very useful to check if a node is nested in a specific parent. See alterNode for an advanced example.
  • getClosestNodeParentByTag(node, tag)
    • Description: Returns the closest parent of a node with a specific tag.
    • Parameters : - node : a parsed HTML node from alterChildren for example
    • Returns : An HTML node if found.

Download Details:

Author: archriss

Source Code: https://github.com/archriss/react-native-render-html

#react-native #react #mobile-apps

What is GEEK

Buddha Community

iOS/Android pure javascript react-native component that renders your HTML
Autumn  Blick

Autumn Blick

1598839687

How native is React Native? | React Native vs Native App Development

If you are undertaking a mobile app development for your start-up or enterprise, you are likely wondering whether to use React Native. As a popular development framework, React Native helps you to develop near-native mobile apps. However, you are probably also wondering how close you can get to a native app by using React Native. How native is React Native?

In the article, we discuss the similarities between native mobile development and development using React Native. We also touch upon where they differ and how to bridge the gaps. Read on.

A brief introduction to React Native

Let’s briefly set the context first. We will briefly touch upon what React Native is and how it differs from earlier hybrid frameworks.

React Native is a popular JavaScript framework that Facebook has created. You can use this open-source framework to code natively rendering Android and iOS mobile apps. You can use it to develop web apps too.

Facebook has developed React Native based on React, its JavaScript library. The first release of React Native came in March 2015. At the time of writing this article, the latest stable release of React Native is 0.62.0, and it was released in March 2020.

Although relatively new, React Native has acquired a high degree of popularity. The “Stack Overflow Developer Survey 2019” report identifies it as the 8th most loved framework. Facebook, Walmart, and Bloomberg are some of the top companies that use React Native.

The popularity of React Native comes from its advantages. Some of its advantages are as follows:

  • Performance: It delivers optimal performance.
  • Cross-platform development: You can develop both Android and iOS apps with it. The reuse of code expedites development and reduces costs.
  • UI design: React Native enables you to design simple and responsive UI for your mobile app.
  • 3rd party plugins: This framework supports 3rd party plugins.
  • Developer community: A vibrant community of developers support React Native.

Why React Native is fundamentally different from earlier hybrid frameworks

Are you wondering whether React Native is just another of those hybrid frameworks like Ionic or Cordova? It’s not! React Native is fundamentally different from these earlier hybrid frameworks.

React Native is very close to native. Consider the following aspects as described on the React Native website:

  • Access to many native platforms features: The primitives of React Native render to native platform UI. This means that your React Native app will use many native platform APIs as native apps would do.
  • Near-native user experience: React Native provides several native components, and these are platform agnostic.
  • The ease of accessing native APIs: React Native uses a declarative UI paradigm. This enables React Native to interact easily with native platform APIs since React Native wraps existing native code.

Due to these factors, React Native offers many more advantages compared to those earlier hybrid frameworks. We now review them.

#android app #frontend #ios app #mobile app development #benefits of react native #is react native good for mobile app development #native vs #pros and cons of react native #react mobile development #react native development #react native experience #react native framework #react native ios vs android #react native pros and cons #react native vs android #react native vs native #react native vs native performance #react vs native #why react native #why use react native

Juned Ghanchi

1621573085

React Native App Developers India, React Native App Development Company

Expand your user base by using react-native apps developed by our expert team for various platforms like Android, Android TV, iOS, macOS, tvOS, the Web, Windows, and UWP.

We help businesses to scale up the process and achieve greater performance by providing the best react native app development services. Our skilled and experienced team’s apps have delivered all the expected results for our clients across the world.

To achieve growth for your business, hire react native app developers in India. You can count on us for all the technical services and support.

#react native app development company india #react native app developers india #hire react native developers india #react native app development company #react native app developers #hire react native developers

Hire Dedicated React Native Developer

Have you ever thought of having your own app that runs smoothly over multiple platforms?

React Native is an open-source cross-platform mobile application framework which is a great option to create mobile apps for both Android and iOS. Hire Dedicated React Native Developer from top React Native development company, HourlyDeveloper.io to design a spectacular React Native application for your business.

Consult with experts:- https://bit.ly/2A8L4vz

#hire dedicated react native developer #react native development company #react native development services #react native development #react native developer #react native

Android App to iOS App Porting Services in Virginia, USA | SISGAIN

Want to port your android app to IOS ? The Android to iOS portion can be easy with SISGAIN. Our android to ios porting services make it easier to port android apps to iOS in Virginia, USA. With our remote team you can port your app today. Our dedicated android to iOS Porting developers will help you to run your business smoothly without any hassle. For more information call us at +18444455767 or email us at hello@sisgain.com

#android to ios porting #port android app to ios #porting android to ios #android to ios porting #android app to ios app porting in usa #dedicated android to ios porting developers

Autumn  Blick

Autumn Blick

1593867420

Top Android Projects with Source Code

Android Projects with Source Code – Your entry pass into the world of Android

Hello Everyone, welcome to this article, which is going to be really important to all those who’re in dilemma for their projects and the project submissions. This article is also going to help you if you’re an enthusiast looking forward to explore and enhance your Android skills. The reason is that we’re here to provide you the best ideas of Android Project with source code that you can choose as per your choice.

These project ideas are simple suggestions to help you deal with the difficulty of choosing the correct projects. In this article, we’ll see the project ideas from beginners level and later we’ll move on to intermediate to advance.

top android projects with source code

Android Projects with Source Code

Before working on real-time projects, it is recommended to create a sample hello world project in android studio and get a flavor of project creation as well as execution: Create your first android project

Android Projects for beginners

1. Calculator

build a simple calculator app in android studio source code

Android Project: A calculator will be an easy application if you have just learned Android and coding for Java. This Application will simply take the input values and the operation to be performed from the users. After taking the input it’ll return the results to them on the screen. This is a really easy application and doesn’t need use of any particular package.

To make a calculator you’d need Android IDE, Kotlin/Java for coding, and for layout of your application, you’d need XML or JSON. For this, coding would be the same as that in any language, but in the form of an application. Not to forget creating a calculator initially will increase your logical thinking.

Once the user installs the calculator, they’re ready to use it even without the internet. They’ll enter the values, and the application will show them the value after performing the given operations on the entered operands.

Source Code: Simple Calculator Project

2. A Reminder App

Android Project: This is a good project for beginners. A Reminder App can help you set reminders for different events that you have throughout the day. It’ll help you stay updated with all your tasks for the day. It can be useful for all those who are not so good at organizing their plans and forget easily. This would be a simple application just whose task would be just to remind you of something at a particular time.

To make a Reminder App you need to code in Kotlin/Java and design the layout using XML or JSON. For the functionality of the app, you’d need to make use of AlarmManager Class and Notifications in Android.

In this, the user would be able to set reminders and time in the application. Users can schedule reminders that would remind them to drink water again and again throughout the day. Or to remind them of their medications.

3. Quiz Application

Android Project: Another beginner’s level project Idea can be a Quiz Application in android. Here you can provide the users with Quiz on various general knowledge topics. These practices will ensure that you’re able to set the layouts properly and slowly increase your pace of learning the Android application development. In this you’ll learn to use various Layout components at the same time understanding them better.

To make a quiz application you’ll need to code in Java and set layouts using xml or java whichever you prefer. You can also use JSON for the layouts whichever preferable.

In the app, questions would be asked and answers would be shown as multiple choices. The user selects the answer and gets shown on the screen if the answers are correct. In the end the final marks would be shown to the users.

4. Simple Tic-Tac-Toe

android project tic tac toe game app

Android Project: Tic-Tac-Toe is a nice game, I guess most of you all are well aware of it. This will be a game for two players. In this android game, users would be putting X and O in the given 9 parts of a box one by one. The first player to arrange X or O in an adjacent line of three wins.

To build this game, you’d need Java and XML for Android Studio. And simply apply the logic on that. This game will have a set of three matches. So, it’ll also have a scoreboard. This scoreboard will show the final result at the end of one complete set.

Upon entering the game they’ll enter their names. And that’s when the game begins. They’ll touch one of the empty boxes present there and get their turn one by one. At the end of the game, there would be a winner declared.

Source Code: Tic Tac Toe Game Project

5. Stopwatch

Android Project: A stopwatch is another simple android project idea that will work the same as a normal handheld timepiece that measures the time elapsed between its activation and deactivation. This application will have three buttons that are: start, stop, and hold.

This application would need to use Java and XML. For this application, we need to set the timer properly as it is initially set to milliseconds, and that should be converted to minutes and then hours properly. The users can use this application and all they’d need to do is, start the stopwatch and then stop it when they are done. They can also pause the timer and continue it again when they like.

6. To Do App

Android Project: This is another very simple project idea for you as a beginner. This application as the name suggests will be a To-Do list holding app. It’ll store the users schedules and their upcoming meetings or events. In this application, users will be enabled to write their important notes as well. To make it safe, provide a login page before the user can access it.

So, this app will have a login page, sign-up page, logout system, and the area to write their tasks, events, or important notes. You can build it in android studio using Java and XML at ease. Using XML you can build the user interface as user-friendly as you can. And to store the users’ data, you can use SQLite enabling the users to even delete the data permanently.

Now for users, they will sign up and get access to the write section. Here the users can note down the things and store them permanently. Users can also alter the data or delete them. Finally, they can logout and also, login again and again whenever they like.

7. Roman to decimal converter

Android Project: This app is aimed at the conversion of Roman numbers to their significant decimal number. It’ll help to check the meaning of the roman numbers. Moreover, it will be easy to develop and will help you get your hands on coding and Android.

You need to use Android Studio, Java for coding and XML for interface. The application will take input from the users and convert them to decimal. Once it converts the Roman no. into decimal, it will show the results on the screen.

The users are supposed to just enter the Roman Number and they’ll get the decimal values on the screen. This can be a good android project for final year students.

8. Virtual Dice Roller

Android Project: Well, coming to this part that is Virtual Dice or a random no. generator. It is another simple but interesting app for computer science students. The only task that it would need to do would be to generate a number randomly. This can help people who’re often confused between two or more things.

Using a simple random number generator you can actually create something as good as this. All you’d need to do is get you hands-on OnClick listeners. And a good layout would be cherry on the cake.

The user’s task would be to set the range of the numbers and then click on the roll button. And the app will show them a randomly generated number. Isn’t it interesting ? Try soon!

9. A Scientific Calculator App

Android Project: This application is very important for you as a beginner as it will let you use your logical thinking and improve your programming skills. This is a scientific calculator that will help the users to do various calculations at ease.

To make this application you’d need to use Android Studio. Here you’d need to use arithmetic logics for the calculations. The user would need to give input to the application that will be in terms of numbers. After that, the user will give the operator as an input. Then the Application will calculate and generate the result on the user screen.

10. SMS App

Android Project: An SMS app is another easy but effective idea. It will let you send the SMS to various no. just in the same way as you use the default messaging application in your phone. This project will help you with better understanding of SMSManager in Android.

For this application, you would need to implement Java class SMSManager in Android. For the Layout you can use XML or JSON. Implementing SMSManager into the app is an easy task, so you would love this.

The user would be provided with the facility to text to whichever number they wish also, they’d be able to choose the numbers from the contact list. Another thing would be the Textbox, where they’ll enter their message. Once the message is entered they can happily click on the send button.

#android tutorials #android application final year project #android mini projects #android project for beginners #android project ideas #android project ideas for beginners #android projects #android projects for students #android projects with source code #android topics list #intermediate android projects #real-time android projects