🤖 Merge PR #46542 [@types/react-native-canvas] Fix Canvas#toDataURL type definition. by @gin0606

https://github.com/iddan/react-native-canvas#canvastodataurl
This commit is contained in:
gin0606 2020-08-04 17:05:18 +09:00 committed by GitHub
parent be5c4773c1
commit 4eb18eb7f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View File

@ -131,7 +131,7 @@ export interface CanvasRenderingContext2D {
export default class Canvas extends React.Component<CanvasProps> {
width: number;
height: number;
toDataURL: () => string;
toDataURL: () => Promise<string>;
getContext: (context: string) => CanvasRenderingContext2D;
}

View File

@ -130,6 +130,20 @@ class CanvasTest extends React.Component {
});
}
handleToDataURL(canvas: Canvas) {
canvas.width = 100;
canvas.height = 100;
const context = canvas.getContext('2d');
context.fillStyle = 'purple';
context.fillRect(0, 0, 100, 100);
canvas.toDataURL().then((dataURL: string) => {
void dataURL;
});
}
render() {
return (
<View>
@ -156,6 +170,9 @@ class CanvasTest extends React.Component {
<Example sample={require('./images/embed-html.png')}>
<Canvas ref={this.handleEmbedHTML} />
</Example>
<Example sample={require('./images/to-data-url.png')}>
<Canvas ref={this.handleToDataURL} />
</Example>
</ScrollView>
</View>
);