Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
@expensify/react-native-live-markdown
Advanced tools
Drop-in replacement for React Native's TextInput component with Markdown formatting.
<TextInput>
componentFirst, install the library from npm with the package manager of your choice:
yarn add @expensify/react-native-live-markdown react-native-reanimated expensify-common
npm install @expensify/react-native-live-markdown react-native-reanimated expensify-common --save
npx expo install @expensify/react-native-live-markdown react-native-reanimated expensify-common
React Native Live Markdown requires react-native-reanimated 3.16.4 or newer and expensify-common 2.0.108 or newer.
Then, install the iOS dependencies with CocoaPods:
cd ios && bundler install && bundler exec 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).
import {MarkdownTextInput, parseExpensiMark} 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}
parser={parseExpensiMark}
/>
);
}
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
.
MarkdownTextInput
behavior can be customized via parser
property. Parser is a function that accepts a plaintext string and returns an array of MarkdownRange
objects:
interface MarkdownRange {
type: MarkdownType;
start: number;
length: number;
depth?: number;
}
Currently, only the following types are supported:
type MarkdownType = 'bold' | 'italic' | 'strikethrough' | 'emoji' | 'mention-here' | 'mention-user' | 'mention-report' | 'link' | 'code' | 'pre' | 'blockquote' | 'h1' | 'syntax';
Parser needs to be marked as a worklet because it's executed on the UI thread as the user types.
Here's a sample function that parses all substrings located between two asterisks as bold text:
function parser(input: string) {
'worklet';
const ranges = [];
const regexp = /\*(.*?)\*/g;
let match;
while ((match = regexp.exec(input)) !== null) {
ranges.push({start: match.index, length: 1, type: 'syntax'});
ranges.push({start: match.index + 1, length: match[1]!.length, type: 'bold'});
ranges.push({start: match.index + 1 + match[1]!.length, length: 1, type: 'syntax'});
}
return ranges;
}
[!TIP] We recommend to store the parser function outside of a component body or memoize the parser function with
React.useMemo
.
Currently, react-native-live-markdown
supports only ExpensiMark flavor. We are working on CommonMark support as well as possibility to use other Markdown parsers.
MarkdownTextInput
inherits all props of React Native's TextInput
component as well as introduces the following properties:
Prop | Type | Default | Note |
---|---|---|---|
parser | (value: string) => MarkdownRange[] | undefined | A function that parses the current value and returns an array of ranges. |
markdownStyle | MarkdownStyle | undefined | Adds custom styling to Markdown text. The provided value is merged with default style object. See Styling for more information. |
react-native-live-markdown
requires React Native 0.75 or newer.
react-native | @expensify/react-native-live-markdown |
---|---|
0.76 | 0.1.141+ |
0.75 | 0.1.129+ |
0.74 | 0.1.122 – 0.1.128 |
0.73 | 0.1.15 – 0.1.121 |
MIT
FAQs
Drop-in replacement for React Native's TextInput component with Markdown formatting.
The npm package @expensify/react-native-live-markdown receives a total of 439 weekly downloads. As such, @expensify/react-native-live-markdown popularity was classified as not popular.
We found that @expensify/react-native-live-markdown demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.