Coder Social home page Coder Social logo

Comments (14)

trickeyd avatar trickeyd commented on August 16, 2024

These are the properties of the object returned by createRadialGradient:

_40: 0
_65: 0
_55: null
_72: null
then: null
catch: null
done: null
finally: null

from react-native-canvas.

iddan avatar iddan commented on August 16, 2024

Hey there, thanks for trying the module and reporting.
react-native-canvas returns promises instead of values for all of it's methods so if you're code looks like this:

class App extends Component {
    handleCanvas = (canvas) => {
         const ctx = canvas.getContext('2d')
         const gradient = ctx.createRadialGradient(x0, y0, r0, x1, y1, r1)
         gradient.addColorStop(offset, color)

It should look like:

class App extends Component {
    handleCanvas = async (canvas) => {
         const ctx = canvas.getContext('2d')
         const gradient = await ctx.createRadialGradient(x0, y0, r0, x1, y1, r1)
         gradient.addColorStop(offset, color)

By await-ing for the gradient object you can access it's methods.
Please share if that worked for you or need more help.

from react-native-canvas.

trickeyd avatar trickeyd commented on August 16, 2024

Thanks for coming back. Yes I saw it was a promise so I tried:


handleCanvas = (canvas) => { 
const ctx = canvas.getContext("2d")
const gradient = ctx.createRadialGradient(x0, y0, r0, x1, y1, r1)
         .then(gradient => {
                 gradient.addColorStop(offset, color)
         })

But the promise never resolves.

I just tried your implementation too - first time I've used async :-) - but it never gets past await. So in the example bellow, "after" is never logged.

        console.log('before');
        gradient = await ctx.createRadialGradient(36.3, 39.6, 0.0, 36.3, 39.6, 36.5);
        console.log('after');

:edit: = the 'then' method is actually null as shown above

:edit: - :edit: = actually that cant be the case as it doesn't throw a null exception when I call it. Must be something to do with the way I was logging it.

from react-native-canvas.

iddan avatar iddan commented on August 16, 2024

Will look into it

from react-native-canvas.

trickeyd avatar trickeyd commented on August 16, 2024

Hello - I was just wondering if you have had a chance to look into this at all. I'm hoping that it's just to do with my own implementation.

Have you tried to use the method yourself?

from react-native-canvas.

trickeyd avatar trickeyd commented on August 16, 2024

(Thanks BTW - I'm sure you're busy)

from react-native-canvas.

iddan avatar iddan commented on August 16, 2024

I will try it later today

from react-native-canvas.

trickeyd avatar trickeyd commented on August 16, 2024

Hey - I updated to: "react-native-canvas": "^0.1.9"

Unfortunately it still doesn't work I'm afraid.

The Promise now resolves but it appears to return an empty object.

console.log("before");
gradient = await ctx.createRadialGradient(36.3, 39.6, 0.0, 36.3, 39.6, 36.5);
console.log("after", gradient);

// before
// after Object {}

from react-native-canvas.

iddan avatar iddan commented on August 16, 2024

gradient should be an empty object

from react-native-canvas.

iddan avatar iddan commented on August 16, 2024

Does it render well?

from react-native-canvas.

trickeyd avatar trickeyd commented on August 16, 2024

from react-native-canvas.

iddan avatar iddan commented on August 16, 2024

Oh, will look into it

from react-native-canvas.

iddan avatar iddan commented on August 16, 2024

resolved in version 0.1.18

from react-native-canvas.

akiladevinda avatar akiladevinda commented on August 16, 2024

Still Having this issue. After set 'await' nothing will return

This is my code

async function resetCanvas(canv) {
  savedPoints = [];
  pointIndex = 1;
  toolState = 'none';
  linePath = [];
  annotations = [];

  pointIndex = 1;
  //axisX      = margin;
  //axisY      = titleHeight + margin;
  barWidth = 20;
  barY = axisY;
  axisHeight = height - titleHeight - subtitleHeight - 2 * margin;
  barHeight = axisHeight;
  axisWidth = width - 2 * margin - barWidth - 70;
  barX = axisX + axisWidth + margin;
  colors = [];
  for (let i = rgbGrd.length - 1; i >= 0; i--) {
    colors.push(
      'rgb(' + rgbGrd[i][0] + ',' + rgbGrd[i][1] + ',' + rgbGrd[i][2] + ')',
    );
  }
  grd = await canv.createLinearGradient(0, barY, 0, barY + barHeight);
  for (let i = 0; i < colors.length; i++) {
    grd.addColorStop(i / (colors.length - 1), colors[i]);
  }
  // document.getElementById("point").innerHTML =
  //   "Move mouse over scan to see height values.<br>Click to save a point in the form: (ID), Y, X, Z";
  canv.clearRect(0, 0, width, height);
  canv.fillStyle = 'white';
  canv.fillRect(0, 0, width, height);
  //canv.stroke();
  canv.beginPath();
  //   enableButtons(true);

  //canv.clearRect(0, 0, width, height);
  //canv.fillStyle="white";
  //canv.fillRect(0, 0, width-1, height-1);
  //canv.fillStyle="black";
  //canv.rect(0, 0, width, height);
  //canv.beginPath();
}

from react-native-canvas.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.