Coder Social home page Coder Social logo

Comments (23)

iddan avatar iddan commented on August 16, 2024 2

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.

Mactub07 avatar Mactub07 commented on August 16, 2024 1

yes, sure , fighting with one :)))

from react-native-canvas.

iddan avatar iddan commented on August 16, 2024

Please try to img.addEventListener to be before img.src =

from react-native-canvas.

lsping8 avatar lsping8 commented on August 16, 2024

@iddan nope i had updated the latest version and switch addEventListner before img.src still no luck

from react-native-canvas.

iddan avatar iddan commented on August 16, 2024

Can you make it work on the web in a codepen? https://codepen.io/pen/?editors=1010

from react-native-canvas.

lsping8 avatar lsping8 commented on August 16, 2024

@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.

iddan avatar iddan commented on August 16, 2024

Can you please try the latest version?

from react-native-canvas.

lsping8 avatar lsping8 commented on August 16, 2024

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.

iddan avatar iddan commented on August 16, 2024

Can you please provide your Android OS version and device specs you were testing on?

from react-native-canvas.

lsping8 avatar lsping8 commented on August 16, 2024

@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.

iddan avatar iddan commented on August 16, 2024

Can you reproduce the issue on an emulator?

from react-native-canvas.

lsping8 avatar lsping8 commented on August 16, 2024
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.

Mactub07 avatar Mactub07 commented on August 16, 2024

have the same issue, any progress with this ? seems it happens only on Android with 4.4... version

from react-native-canvas.

iddan avatar iddan commented on August 16, 2024

Can you provide some example code?

from react-native-canvas.

Mactub07 avatar Mactub07 commented on August 16, 2024

nothing special , I've just use your example code http://prntscr.com/hmh6n2

from react-native-canvas.

iddan avatar iddan commented on August 16, 2024

Is there an error event emitted?

from react-native-canvas.

Mactub07 avatar Mactub07 commented on August 16, 2024

no error, try to use emulator with Android 4.4...
http://prntscr.com/hmhcp2

from react-native-canvas.

iddan avatar iddan commented on August 16, 2024

I'll try to find the time to test it. If you discover something please let us know! 😄

from react-native-canvas.

Mactub07 avatar Mactub07 commented on August 16, 2024

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.

iddan avatar iddan commented on August 16, 2024

screen shot 2017-12-12 at 17 20 34

from react-native-canvas.

iddan avatar iddan commented on August 16, 2024

How can I see that?

from react-native-canvas.

Mactub07 avatar Mactub07 commented on August 16, 2024

@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.

iddan avatar iddan commented on August 16, 2024

Okay, cool.

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.