Setting up Pintura Image Editor with React Native

Pintura is a web based image editor and makes extensive use of web technology, this means it cannot be rendered as a native component. The React Native version of Pintura is rendered in a WebView and communication between the WebView and the app itself is abstracted away by a proxy component.

Files created by Pintura when used in the React Native WebView will be in encoded as a base64 dataURL. To conserve memory the proxy component removes the src and dest property from the value returned by the onLoad callback and removes the src property from the value returned by the onProcess callback.

For a quick start use the React Native (Expo) example project included in the product package ('/presets/react native'). The React Native package only includes a the normal inline editor component.

The React Native example project includes an HTML page (assets/pintura.html) that contains the editor and its styles. This page is automatically loaded in a WebView by the PinturaEditor.js component.

The React Native <PinturaEditor> component loads all the editor default settings and plugins and can then be used in the same manner as the non-native React component.

import PinturaEditor from './PinturaEditor.js';

const editorStyle = { width: 300, height: 600 };

export default function App() {
    return (
                imageCropAspectRatio={1} />

export default App;

Events and properties

To handle events we can use camelcase props. This means that to listen for the Pintura Image Editor load event we have to set the onLoad prop.

<PinturaEditor onLoad={handleEvent} />

Properties can be used as we would with the normal JavaScript version of the editor.

<PinturaEditor src="./my-image.jpeg" />


To run editor methods we need to get a ref to the editor component. We can do so using the useRef hook. When the reference is set up we can access the editor instance.

export default function Example() {
    // get a reference to the PinturaEditor component
    const componentRef = useRef(null);

    const handleUndo = () => {
        // get reference to editor instance
        const { editor } = componentRef.current;

        // run history.undo()

    return (
            <Button onPress={handleUndo}>Undo</Button>

            <PinturaEditor ref={componentRef} src="./image.jpeg" />

Next steps

With the editor set up, we can continue to configure the editor to our liking by adjusting the available configuration options