terrylinla / react-native-sketch-canvas

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

How to clear localSourceImage manually? #73

Closed leiz-me closed 3 years ago

leiz-me commented 6 years ago

I have a button called 'clear background image'. When I click this button, I want to remove the canvas' background image. How can I make it happen?

jamesnogra commented 5 years ago

This is how I did it (I added a ref in the SketchCanvas):

<SketchCanvas
     ref="sketchRef"
     style={{ flex: 1 }}
     strokeColor={'black'} 
     strokeWidth={strokeWidthMain}
/>

<TouchableOpacity style={styles.customButton} onPress={() => { this.refs.sketchRef.clear() }}>
     <Text>Clear</Text>
</TouchableOpacity>
leiz-me commented 5 years ago

@jamesnogra you are not understanding what i asked.

I mean clear the localSourceImage, since I found that if you set the localSourceImage, this way the sketch canvas changed its background to localSourceImage, then reset the localSourceImage to null, at this moment, sketch canvas DID NOT refresh its background image.

What you did is to clear the paths on the canvas, that's totally a different thing.

Thanks anyway.

samridhgupta commented 5 years ago

@leiz-me this seems to be a bug in the library, the background image doesn't change to blank when setting null. But there's a way around to this which I have used, You can use a Plain Transparent Image as the background and set the transparent image as the background when you want to clear the screen.

leiz-me commented 5 years ago

@leiz-me this seems to be a bug in the library, the background image doesn't change to blank when setting null. But there's a way around to this which I have used, You can use a Plain Transparent Image as the background and set the transparent image as the background when you want to clear the screen.

Yes, that would be a good choice under the circumstances.

peterateftawfik commented 5 years ago

but the points will be always related to the transparent image and on the required image