Comments (23)
We're having some issues on Android in the current version. Will dig into it when I'll have a chance as this might affect my projects as well.
from react-native-canvas.
yes, sure , fighting with one :)))
from react-native-canvas.
Please try to img.addEventListener
to be before img.src =
from react-native-canvas.
@iddan nope i had updated the latest version and switch addEventListner
before img.src
still no luck
from react-native-canvas.
Can you make it work on the web in a codepen? https://codepen.io/pen/?editors=1010
from react-native-canvas.
@iddan I had try to draw canvas using webview and apparently the onload/load event still not trigger in android. This bug had been mention in react-native quite some time but not sure had they manage to fixed it.
https://github.com/facebook/react-native/issues/4704
https://github.com/facebook/react-native/issues/13763
Can i know what version is your react-native ? Did onLoad get callback when you testing for android ?
from react-native-canvas.
Can you please try the latest version?
from react-native-canvas.
still no luck, works on IOS but android still not calling event callback. I am using react-native : 0.48.4
from react-native-canvas.
Can you please provide your Android OS version and device specs you were testing on?
from react-native-canvas.
@iddan
I am using this device for testing:
http://www.gsmarena.com/asus_zenfone_2_ze551ml-6917.php (4gb ram)
Android version : 6.0.1
from react-native-canvas.
Can you reproduce the issue on an emulator?
from react-native-canvas.
import React, { Component } from 'react'
import {Dimensions, Text, WebView,NativeModules} from 'react-native'
import Canvas, {Image as CanvasImage} from 'react-native-canvas'
import Paint from '../../component/Test'
import { Col, Row, Grid } from 'react-native-easy-grid'
import { Container } from 'native-base'
import RNCanvas from 'react-native-canvas';
const ToastExample = NativeModules.ToastExample;
class Puzzle extends Component {
constructor () {
super()
this.splitImage = this.splitImage.bind(this)
this.state = {
chunkImage: [],
test: 'something',
mount: ''
}
this.chunkRow = []
}
splitImage (canvas, x, y, rows, cols) {
const {height, width} = Dimensions.get('screen')
this.setState({ test: 'enter' })
const CanvasXSize = width / cols - 2
const CanvasYSize = (height / 2) / rows
canvas.width = CanvasXSize
console.log('CanvasXSize',CanvasXSize);
canvas.height = CanvasYSize
const ctx = canvas.getContext('2d')
const img = new CanvasImage(canvas)
img.addEventListener('load', () => {
this.setState({ test: 'load' })
const imgW = img.width
console.log('imgW', imgW)
const imgH = img.height
const chunkWidth = imgW / cols
console.log('chunkWidth', chunkWidth)
const chunkHeight = imgH / rows
ctx.drawImage(
img,
x * chunkWidth,
y * chunkHeight,
chunkWidth,
chunkHeight,
0,
0,
CanvasXSize,
CanvasYSize
)
})
img.src = 'https://scontent-sin6-2.cdninstagram.com/t51.2885-15/s640x640/sh0.08/e35/21820297_280457069027480_5332287299113713664_n.jpg'
}
componentWillMount () {
this.setState({ mount: 'mount' })
const rows = 3
const cols = 3
const tempChunkImage = this.state.chunkImage
for (let y = 0; y < rows; y++) {
const tempChunkCol = []
for (let x = 0; x < cols; x++) {
tempChunkCol.push(
<Col key={y + x} style={{overflow: 'hidden'}}>
<Canvas
ref={(canvas) => this.splitImage(canvas, x, y, rows, cols)}
style={{ padding: 2, borderRadius: 10, overflow: 'hidden' }} />
</Col>
)
}
tempChunkImage.push(
<Row key={y} style={{overflow: 'hidden'}}>
{tempChunkCol}
</Row>
)
}
this.setState({chunkImage: tempChunkImage})
}
render () {
return (
<Container>
<Row size={50}>
<Text style={{marginTop: 20}}>{this.state.test}</Text>
</Row>
<Row size={50}>
<Grid style={{overflow: 'hidden'}}>
{this.state.chunkImage}
</Grid>
</Row>
</Container>
)
}
}
export default Puzzle
This is my full code, i had try to run in android emulator and still the same problem.
from react-native-canvas.
have the same issue, any progress with this ? seems it happens only on Android with 4.4... version
from react-native-canvas.
Can you provide some example code?
from react-native-canvas.
nothing special , I've just use your example code http://prntscr.com/hmh6n2
from react-native-canvas.
Is there an error event emitted?
from react-native-canvas.
no error, try to use emulator with Android 4.4...
http://prntscr.com/hmhcp2
from react-native-canvas.
I'll try to find the time to test it. If you discover something please let us know! 😄
from react-native-canvas.
seems old devices with Android 4.4.. don't support canvas at all ;
http://www.mobilexweb.com/blog/android-4-4-kitkat-browser-chrome-webview
https://caniuse.com/#search=canvas
that's the main problem , because it doesn't support even simply canvas.fill(), canvas.fillrect()
from react-native-canvas.
from react-native-canvas.
How can I see that?
from react-native-canvas.
@alphasp I had the same issue so I added to the baseUrl: '' to the WebView source and it worked.
I created a fork which is working for me on Android.
https://github.com/mauriciomassaia/react-native-canvas/
@iddan i didnt make a PR because i couldnt make it build properly. I was having issues with the object spread on build-html.js so I re-wrote it to copy the object properties.
Cheers
seems it helps . at least I can use canvas.fillRect() with this in old devices
from react-native-canvas.
Okay, cool.
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.