React-Native-Canvas doesn't draw whole rectangle


Brian Ton

While making another app, I ran into a problem react-native-canvas, so I created this minimal project. The problem is that the WebView is much smaller than the Canvas and doesn't fill the entire canvas when appropriate. Here is the code (very similar to the example code ):

import React, { Component } from 'react';
import { View } from "react-native"
import Canvas from 'react-native-canvas';

export default class App extends Component {

  handleCanvas = (canvas) => {
    const ctx = canvas.getContext('2d');
    ctx.fillStyle = 'purple';
    ctx.fillRect(0, 0, 350, 700);
  }

  render() {
    return (
      <View style={{
        width: 350,
        height: 700
      }}>
        <Canvas ref={this.handleCanvas} style={{
          width: 350,
          height: 700,
          borderWidth: 1,
          borderColor: "red"
        }} width={350} height={700} />
      </View>
    )
  }
}

Here's a screenshot of the app: screenshotas you can see, the code should not render the rectangle to the full size of the canvas (marked in red), it does. According to the Expo Inspect-Element debugging tool, the WebView (ie the entire rectangle) is only 300 x 150 pixels.

Am I missing something obvious? Or is this a bug's bug react-native-canvas?

This is on Android by the way.

Jason

Put this in your handleCanvas:

canvas.width = 400;
canvas.height = 700;

Related


React-Native-Canvas doesn't draw whole rectangle

Brian Ton While making another app, I ran into a problem react-native-canvas, so I created this minimal project. The problem is that the WebView is much smaller than the Canvas and doesn't fill the entire canvas when appropriate. Here is the code (very similar

Canvas doesn't draw rectangle after for loop

Digital Brent I'm trying to create a news ticker that renders text in small square "pixels". I say "pixels" because they look like pixels, but the actual displayed square is larger than 1px. So far I can get all the rendered letters from the object I build (co

Canvas doesn't draw rectangle after for loop

Digital Brent I'm trying to create a news ticker that renders text in small square "pixels". I say "pixels" because they look like pixels, but the actual displayed square is larger than 1px. So far I can get all the rendered letters from the object I build (co

Canvas doesn't draw rectangle after for loop

Digital Brent I'm trying to create a news ticker that renders text in small square "pixels". I say "pixels" because they look like pixels, but the actual displayed square is larger than 1px. So far I can get all the rendered letters from the object I build (co

Canvas doesn't draw rectangle after for loop

Digital Brent I'm trying to create a news ticker that renders text in small square "pixels". I say "pixels" because they look like pixels, but the actual displayed square is larger than 1px. So far I can get all the rendered letters from the object I build (co

canvas.drawRect doesn't draw a rectangle on the image

Krishna Here canvas.drawRect will be different when using different bitmaps. I want to draw a rectangle over the top image and want the part of the image outside the rectangle to be darkened or blurred. please help me. draw.setOnClickListener(new View.OnClickL

canvas.drawRect doesn't draw a rectangle on the image

Krishna Here canvas.drawRect will be different when using different bitmaps. I want to draw a rectangle over the top image and want the part of the image outside the rectangle to be darkened or blurred. Please help me. draw.setOnClickListener(new View.OnClickL

Tkinter won't draw rectangle on Canvas

Cadel Watson I'm trying to initialize a grid of blue rectangles with a user-specified size. However, the rectangle is not drawn on the initialized canvas. I am trying to store them in a matrix for later use. My code is as follows: import Tkinter import sys fro

Tkinter won't draw rectangle on Canvas

Cadel Watson I'm trying to initialize a grid of blue rectangles with a user-specified size. However, the rectangle is not drawn on the initialized canvas. I am trying to store them in a matrix for later use. My code is as follows: import Tkinter import sys fro

Canvas doesn't draw text?

code M I want to display some text on the screen when the user clicks buttonwith canvasin android studio. I've been watching a lot of posts and videos on how to do this. The problem is, when I try their code, when I click the button, nothing is displayed. Does

Canvas doesn't draw in a loop

Saba Silagadze Why draw arent rectangles in a loop? I just started a snake game n trying to draw the snake's body through a loop, but for some reason ctx is not drawing the loop. If I write the rectangle without the loop, it works. var canv = document.getEleme

Canvas doesn't draw in a loop

Saba Silagadze Why draw arent rectangles in a loop? I just started a snake game n trying to draw the snake's body through a loop, but for some reason ctx doesn't draw the loop. If I write the rectangle without the loop, it works. var canv = document.getElement

How to draw rectangle in image in React Native

Athila Zuma I've been looking for references on how to draw rectangles in an image using react native, but I haven't found anything. What I'm trying to do is like passing parameters, the photo and the coordinates of the diagonal vertices of the rectangle as pa

How to draw a rounded rectangle in React Native ART

Wimal Weerawansa I'm using react-native ARTthe library to draw scalable vector elements in a mobile app, it ART's a perfect library as it can be easily animated and deformed with its own tools. But without custom elements ARTlike SVG Circle, Rectetch... ART ca

How to draw rectangle in image in React Native

Athila Zuma I've been looking for references on how to draw rectangles in an image using react native, but I haven't found anything. What I'm trying to do is like passing parameters, the photo and the coordinates of the diagonal vertices of the rectangle as pa

How to draw a rounded rectangle in React Native ART

Wimal Weerawansa I'm using react-native ARTthe library to draw scalable vector elements in a mobile application and it ART's a perfect library as it can be easily animated and deformed with its own tools. But without custom elements ARTlike SVG Circle, Rectetc

How to draw a rounded rectangle in React Native ART

Wimal Weerawansa I'm using react-native ARTthe library to draw scalable vector elements in a mobile application and it ART's a perfect library as it can be easily animated and deformed with its own tools. But without custom elements ARTlike SVG Circle, Rectetc

draw rectangle in canvas

125fur I can draw rectangle on video on canvas. But it's hidden behind the video but can't suggest how I should draw the rectangle on the video through the side.Pls like I can draw the code on the image. : <p>Video to use:</p> <video id="video1" controls wi

draw rectangle in canvas

125fur I can draw rectangle on video on canvas. But it's hidden behind the video but can't suggest how I should draw the rectangle on the video through the side.Pls like I can draw the code on the image. : <p>Video to use:</p> <video id="video1" controls wi

Draw resizable rectangle on canvas

Inde · 穆里罗 (Masinde Muliro) I am trying to draw a resizable rectangle on a canvas element. I check the position of the mouse relative to the rectangle on the screen and then update the width/height of the triangle the mouse falls into. So far I've managed to s

draw rectangle on canvas

Avsana Khan I'm trying to develop a ping pong game in Android where I will have two bats to hit the ball. I drew a bat on the canvas and it was placed at the far left of the screen. I need another bat on the far right of the screen, but every time the paddle i

draw rectangle on canvas

Avsana Khan I'm trying to develop a ping pong game in Android where I will have two bats to hit the ball. I drew a bat on the canvas and it was placed at the far left of the screen. I need another bat on the far right of the screen, but every time the paddle i

Draw resizable rectangle on canvas

Inde · 穆里罗 (Masinde Muliro) I am trying to draw a resizable rectangle on a canvas element. I check the position of the mouse relative to the rectangle on the screen and then update the width/height of the triangle the mouse falls into. So far I've managed to s

draw rectangle in canvas

125fur I can draw rectangle on video on canvas. But it's hidden behind the video but can't suggest how I should draw the rectangle on the video through the side.Pls like I can draw the code on the image. : <p>Video to use:</p> <video id="video1" controls wi

Canvas rectangle doesn't move with label, why?

companion I'm making a gui application and for aesthetic reasons I want to randomly generate labels with colored backgrounds. But whenever the label is generated, the canvas rectangle stays at the bottom left corner. pos_hint does not affect the rectangle, onl

Canvas rectangle doesn't move with label, why?

companion I'm making a gui application and for aesthetic reasons I want to randomly generate labels with colored backgrounds. But whenever the label is generated, the canvas rectangle stays at the bottom left corner. pos_hint does not affect the rectangle, onl