terrylinla / react-native-sketch-canvas

A React Native component for drawing by touching on both iOS and Android.
MIT License
697 stars 453 forks source link

TypeError: Undefined is not an object #158

Open delorali opened 4 years ago

delorali commented 4 years ago

Hi @terrylinla , I installed the package, and automatically linked it. However, when I try to run the example code in my project, I get the error Unhandled JS Exception: Error: Requiring module "node_modules/.../SketchCanvas.js", which threw an exception: TypeError: undefined is not an object (evaluating '_reactNative.UIManager.RNSketchCanvas.Constants')

Has anyone had experience dealing with this error before? Also, does someone know if this has to do with an automatically linking error?

Thanks

sadelbrid commented 4 years ago

Same issue here. I really hope this is fixed, because there aren't really any sketch components out there that are maintained.

dottd-admin commented 4 years ago

Same issue encountered here, can be fixed by swapping the following:

// SketchCanvas.MAIN_BUNDLE = Platform.OS === 'ios' ? UIManager.RNSketchCanvas.Constants.MainBundlePath : '';
// SketchCanvas.DOCUMENT = Platform.OS === 'ios' ? UIManager.RNSketchCanvas.Constants.NSDocumentDirectory : '';
// SketchCanvas.LIBRARY = Platform.OS === 'ios' ? UIManager.RNSketchCanvas.Constants.NSLibraryDirectory : '';
// SketchCanvas.CACHES = Platform.OS === 'ios' ? UIManager.RNSketchCanvas.Constants.NSCachesDirectory : '';

SketchCanvas.MAIN_BUNDLE = Platform.OS === 'ios' ? UIManager['getConstants'].MainBundlePath : '';
SketchCanvas.DOCUMENT = Platform.OS === 'ios' ? UIManager['getConstants'].NSDocumentDirectory : '';
SketchCanvas.LIBRARY = Platform.OS === 'ios' ? UIManager['getConstants'].NSLibraryDirectory : '';
SketchCanvas.CACHES = Platform.OS === 'ios' ? UIManager['getConstants'].NSCachesDirectory : '';
colelogan commented 3 years ago

@sadelbrid @delorali

this guy already forked the project and fixed those errors: https://github.com/terrylinla/react-native-sketch-canvas/pull/107/files

Andri-Hail commented 3 years ago

@colelogan @dottd-admin

I linked the repo following the instructions and am also getting this error. Where does that code snippet need to be changed? I don't see a src/SketchCanvas.js on my end, does that mean I linked it wrong?

raazatul7 commented 2 years ago

Any update on this? I'm using expo

xneyk commented 2 years ago

Any update on this? I'm using expo

I'm using expo too and having the same error

xneyk commented 2 years ago

SketchCanvas.MAIN_BUNDLE = Platform.OS === 'ios' ? UIManager['getConstants'].MainBundlePath : ''; SketchCanvas.DOCUMENT = Platform.OS === 'ios' ? UIManager['getConstants'].NSDocumentDirectory : ''; SketchCanvas.LIBRARY = Platform.OS === 'ios' ? UIManager['getConstants'].NSLibraryDirectory : ''; SketchCanvas.CACHES = Platform.OS === 'ios' ? UIManager['getConstants'].NSCachesDirectory : '';

This works for me, but now I have another error : requireNativeComponent: "RNSketchCanvas" was not found in the UIManager.

I'm using this component:

<View style={styles.container}>
    <View style={{ flex: 1, flexDirection: 'row' }}>
        <SketchCanvas
            style={{ flex: 1 }}
            strokeColor={'red'}
            strokeWidth={7}
        />
    </View>
</View>
hlinh88 commented 1 year ago

requireNativeComponent: "RNSketchCanvas" was not found in the UIManager.

I also face this problem using Expo