Giter VIP home page Giter VIP logo

react-native-webview-quill's Introduction

React Native Webview Quill

Quill component for React Native built using postMessage communication and a WebView.

npm npm npm npm

Installation

npm install react-native-webview-quill

to use you must set a webview provider once on your project

import {providerRegistry} from "react-native-webview-quill"
import {WebView} from 'react-native-webview-quill/src/providers/WebView/ReactNative/index';

providerRegistry.WebViewProvider = WebView

then you can use the Quill component:

import {Quill} from 'react-native-webview-quill';

Preview

screenshot

Properties

All properties are optional.

Property Description
onContentChange A callback receiving the quilljs contents as parameter, whenever the contents change.
options A quilljs instance config, see their documentation.
containerStyle The style property for the inner WebView component, see documentation.
content The initial quilljs contents, useful for readonly/viewer component.

Functions

Use this.quill.reloadResources(), to force component to update content.

componentDidUpdate(prevProps, prevState){
  if (prevState.delta !== this.state.delta)
    this.quill.reloadResources()
}

<Quill
  ref={(quill) => { this.quill = quill }}
  content={ this.state.delta } />

Example Usage

This example is typescript, though the library works with plain javascript as well.

//Generic Dependencies
import * as React from 'react';
import { StatusBar, View } from 'react-native';

// React native webview quill
import { DeltaStatic, providerRegistry, Quill } from 'react-native-webview-quill';
import { WebView } from 'react-native-webview-quill/src/providers/WebView/ReactNative/index';

// Only once: Set the webview implementation to use
// Should be done once, probably in your index.js
providerRegistry.WebViewProvider = WebView;

// This is a example of a QuillDelta object that describes the
// content and formatting of the richtext editor
// More information at https://quilljs.com/docs/delta/
const defaultOps: DeltaStatic = {
  ops: [
    {
      insert: 'Test',
      attributes: {
        bold: true,
      },
    },
  ],
};

export default class App extends React.Component<{}, { content: DeltaStatic }> {
  constructor(props: any) {
    super(props);
    this.state = {
      content: defaultOps,
    };
  }

  public render() {
    //Render a full screen quill editor
    return (
      <View style={{ flex: 1 }}>
        <View style={{ height: StatusBar.currentHeight }} />
        <Quill
          content={
            /* the initial content */
            this.state.content
          }
          onContentChange={
            /* Callend when an edit is made */
            this.onContentChange
          }
          containerStyle={
            /*The style passed to the editor container*/
            { flex: 1 }
           }
        />
      </View>
    );
  }

  private onContentChange = (content: DeltaStatic) => {
    // Save this content
    this.setState({ content });
  };
}

react-native-webview-quill's People

Contributors

bmmevius avatar bramthedev avatar cagigas avatar dependabot[bot] avatar dobosmarton avatar jolanrensen avatar luudjanssen avatar mousetail avatar revadike avatar stefanhoekstra avatar

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.