Git Product home page Git Product logo

badeggg / react-native-live-markdown Goto Github PK

View Code? Open in Web Editor NEW

This project forked from expensify/react-native-live-markdown

0.0 0.0 0.0 3.58 MB

Drop-in replacement for React Native's TextInput component with Markdown formatting.

Home Page: https://www.npmjs.com/package/@expensify/react-native-live-markdown

License: MIT License

JavaScript 10.13% Ruby 1.47% C++ 11.92% Objective-C 3.15% Java 18.88% Kotlin 1.16% TypeScript 32.96% CSS 0.24% Objective-C++ 18.93% CMake 1.16%

react-native-live-markdown's Introduction

@expensify/react-native-live-markdown

Features

  • ⚛️ Drop-in replacement for <TextInput> component
  • ⌨️ Live synchronous formatting on every keystroke
  • ⚡ Fully native experience (selection, spellcheck, autocomplete)
  • 🎨 Customizable styles
  • 🌐 Universal support (Android, iOS, web)
  • 🏗️ Supports New Architecture

Installation

First, install the library from npm with the package manager of your choice:

yarn add @expensify/react-native-live-markdown
npm install @expensify/react-native-live-markdown --save
npx expo install @expensify/react-native-live-markdown

Then, install the iOS dependencies with CocoaPods:

cd ios && pod install

The library includes native code so you will need to re-build the native app.

Note

The library does not support Expo Go, you will need to setup Expo Dev Client (see here).

Usage

import {MarkdownTextInput} from '@expensify/react-native-live-markdown';
import React from 'react';

export default function App() {
  const [text, setText] = React.useState('Hello, *world*!');

  return (
    <MarkdownTextInput
      value={text}
      onChangeText={setText}
    />
  );
}

Styling

MarkdownTextInput can be styled using style prop just like regular TextInput component.

It is also possible to customize the styling of the formatted contents of MarkdownTextInput component. The style object supports all color representations from React Native including PlatformColor and DynamicColorIOS according to the color reference. Currently, a limited set of styles is customizable but this is subject to change in the future.

import type {MarkdownStyle} from '@expensify/react-native-live-markdown';

const FONT_FAMILY_MONOSPACE = Platform.select({
  ios: 'Courier',
  default: 'monospace',
});

const markdownStyle: MarkdownStyle = {
  syntax: {
    color: 'gray',
  },
  link: {
    color: 'blue',
  },
  h1: {
    fontSize: 25,
  },
  emoji: {
    fontSize: 20,
  },
  blockquote: {
    borderColor: 'gray',
    borderWidth: 6,
    marginLeft: 6,
    paddingLeft: 6,
  },
  code: {
    fontFamily: FONT_FAMILY_MONOSPACE,
    fontSize: 20,
    color: 'black',
    backgroundColor: 'lightgray',
  },
  pre: {
    fontFamily: FONT_FAMILY_MONOSPACE,
    fontSize: 20,
    color: 'black',
    backgroundColor: 'lightgray',
  },
  mentionHere: {
    color: 'green',
    backgroundColor: 'lime',
  },
  mentionUser: {
    color: 'blue',
    backgroundColor: 'cyan',
  },
};

The style object can be passed to multiple MarkdownTextInput components using markdownStyle prop:

<MarkdownTextInput
  value={text}
  onChangeText={setText}
  style={styles.input}
  markdownStyle={markdownStyle}
/>

Tip

We recommend to store the style object outside of a component body or memoize the style object with React.useMemo.

Markdown flavors support

Currently, react-native-live-markdown supports only ExpensiMark flavor. We are working on CommonMark support as well as possibility to use other Markdown parsers.

API reference

MarkdownTextInput inherits all props of React Native's TextInput component as well as introduces the following properties:

Prop Type Default Note
markdownStyle MarkdownStyle undefined Adds custom styling to Markdown text. The provided value is merged with default style object. See Styling for more information.

Compatibility

react-native-live-markdown requires React Native 0.71 or newer.

License

MIT


Brought to you by Software Mansion + Expensify

react-native-live-markdown's People

Contributors

tomekzaw avatar osbotify avatar robertkozik avatar skalakid avatar bartoszgrajdek avatar j-piasecki avatar andrewgable avatar maksg avatar bernhardoj avatar nandorojo avatar staszekscp avatar nkdengineer 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.