Comments (14)
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.
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.
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.
Will look into it
from react-native-canvas.
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.
(Thanks BTW - I'm sure you're busy)
from react-native-canvas.
I will try it later today
from react-native-canvas.
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.
gradient should be an empty object
from react-native-canvas.
Does it render well?
from react-native-canvas.
from react-native-canvas.
Oh, will look into it
from react-native-canvas.
resolved in version 0.1.18
from react-native-canvas.
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)
- New architecture support for fabric HOT 1
- require cycle node_modules\react-native-canvas HOT 1
- canvas.loadFromJSON missing in react-native-canvas
- Error: Unable to resolve module ./CanvasRenderingContext2D HOT 1
- Not able to add fontFamily with font
- Application gets hang after 10 mins due to drawing on canvas continuously
- Can't draw image greater than 2048x2048 HOT 1
- Virtual/In-Memory Canvas HOT 1
- Can't draw Image on release HOT 1
- Doesn't work at all with Expo HOT 5
- Does not work with Expo 50 HOT 1
- `clearRect()` crashes in Expo 49 HOT 1
- does not work in react-native-windows
- How to draw local image on canvas using react-native-canvas HOT 1
- Setting width/height of canvas doesn't work HOT 2
- Error: Unable to resolve module `react/jsx-runtime` from `node_modules/react-native-canvas/dist/Canvas.js HOT 2
- The text truncates and doesn't show in multiline HOT 1
- getting an Object instead of Boolean by using isPointInStroke HOT 3
- getting an Object instead of Boolean by using isPointInStroke
- The return value has a large deviation by using isPointInStroke HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-canvas.