Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read property 'style' of undefined #196

Closed
minhhho2 opened this issue Oct 27, 2020 · 10 comments · Fixed by #222
Closed

TypeError: Cannot read property 'style' of undefined #196

minhhho2 opened this issue Oct 27, 2020 · 10 comments · Fixed by #222
Labels

Comments

@minhhho2
Copy link

minhhho2 commented Oct 27, 2020

I am trying use the library to render a basic canvas with a shape as per example code in the git repo. However, i am getting library errors and cant seem to resolve it.

I've added the example code to a boiler plate expo project with the minimal typescript setup with no additional code (just the boiler plate project).

I am getting the following error ...
image

The only custom code that is added is the example code which is added to the TabOneScreen.
image

@iddan iddan added the bug label Oct 27, 2020
@GoChartingAdmin
Copy link

Any update on this?

@iddan
Copy link
Owner

iddan commented Nov 20, 2020

Sorry, I could not find time for this yet

@cre-mer
Copy link

cre-mer commented Dec 26, 2020

I'm having the same issue. I create a new project with expo init myProject.
Bildschirmfoto 2020-12-26 um 09 07 22

I didn't even add custom code. I only imported Canvas like so import { Canvas } from 'react-native-canvas'; and it immediately threw the error.

Here is my package.json

{
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web",
    "eject": "expo eject"
  },
  "dependencies": {
    "expo": "~40.0.0",
    "expo-status-bar": "~1.0.3",
    "react": "16.13.1",
    "react-dom": "16.13.1",
    "react-native": "https://github.com/expo/react-native/archive/sdk-40.0.1.tar.gz",
    "react-native-canvas": "^0.1.37",
    "react-native-web": "~0.13.12",
    "react-native-webview": "^11.0.2"
  },
  "devDependencies": {
    "@babel/core": "~7.9.0"
  },
  "private": true
}

I only added react-native-webview and canvas.

@iddan
Copy link
Owner

iddan commented Dec 26, 2020

Sorry, I could not find time for this yet

@cre-mer
Copy link

cre-mer commented Dec 26, 2020

I wanted to contribute and try to fix the problem. But when I git clone and try to install, I get this:
Bildschirmfoto 2020-12-26 um 23 03 24

@JosephKastier
Copy link

having the same issue :(

@Oderjunkie
Copy link

having this issue too!

@qurben
Copy link
Contributor

qurben commented Jul 25, 2021

react-native seems to have removed propTypes from most of their components, in favor of flow/typescript. react-native-web already has removed them (breaking react-native-canvas for web). Maybe it's an idea to also remove propTypes here. At some point react-native might also remove these propTypes.

qurben added a commit to qurben/react-native-canvas that referenced this issue Jul 25, 2021
@qurben
Copy link
Contributor

qurben commented Jul 25, 2021

So after removing the propTypes it still didn't work, but the solution is actually quite simple. With react-native-web there is no reason to use react-native-webview (it isn't even supported), and also no reason to use react-native-canvas.

Just using a plain <canvas> tag for web works exactly the same as this project does on the other platforms.

if (Platform.OS === "web") {
    return <canvas style={{width, height}} ref={handleCanvas} />
}

return (
    <Canvas style={{ width, height }} ref={handleCanvas} />
);

The object passed to ref is (nearly) the same in both cases.


It might be a good idea to document that web is not supported by this project, or to add this check in the project itself.

@qurben
Copy link
Contributor

qurben commented Jul 25, 2021

This is related to #184, in this issue web is also used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants