terrylinla / react-native-sketch-canvas

A React Native component for drawing by touching on both iOS and Android.
MIT License
693 stars 450 forks source link

undefined is not a function (evaluating 'this.state.canvas.getBase64') #113

Closed freightlive closed 5 years ago

freightlive commented 5 years ago

I'm probably doing something wrong in the 'obvious department' but I can't seem to get thus to work...

Header import SketchCanvas from "@terrylinla/react-native-sketch-canvas";

In render:

<SketchCanvas
   containerStyle={{ backgroundColor: "transparent", flex: 1 }}
   canvasStyle={{ backgroundColor: "transparent", flex: 1 }}
   defaultStrokeIndex={0}
   defaultStrokeWidth={5}
   ref={ref => (this.state.canvas = ref)}
 />

In the button handler:


    navigationButtonPressed({ buttonId }) {
        if (buttonId == "saveBtn") {
            this.state.canvas.getBase64('png', false, false, false, (err, result) => {
                if (err) {
                    return console.log(err);
                }
                this.setState({imageData: result});
            });
        }
    }```

Which result in:

`undefined is not a function (evaluating 'this.state.canvas.getBase64')`
freightlive commented 5 years ago

Ah.. import was the problem:

import { SketchCanvas } from "@terrylinla/react-native-sketch-canvas";