react-native-view-shot: Cannot read property 'captureRef' of undefined at captureRef
feature request
bug report
Version & Platform
npm ls react-native react-native-view-shot #<- PASTE CMD RESULT IN HERE
Platform: iOS? Android?
Expected behavior
Actual behavior
Steps to reproduce the behavior
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 4
- Comments: 37 (9 by maintainers)
After spending 3 hours on this with my Android build I went back to basics, react-native unlink react-native-view-shot and then react-native link react-native-view-shot
iOS linked with no errors, Android threw an error "It seems something went wrong while linking. Error: ENOENT: no such file or directory, open ‘android/app/src/main/java/com/abc/def/MainApplication.java’.
My directory structure is android/app/src/main/java/com/abc.def/MainApplication.java subtle difference.
So… all I needed to do was add
import fr.greweb.reactnativeviewshot.RNViewShotPackage; // <- this
and
to MainApplication.java and it worked!
Hope this helps someone.
Don’t really understand the mechanics, but I was running into the same error as @macelii (after having run
react-native link react-native-view-shot) and found that runningpod installfixed itI missed an output from console, it seems that the component is not linked correctly: NativeModules.RNViewShot is undefined. Make sure the library is linked on the native side. Despite I’ve already run react-native link react-native-view-shot
Can someone update the read me to show manual linking with Android and iOS?
same issue on android, linked manually with:
app/build.gradle : compile project(':react-native-view-shot')and in settings.gradle:how to resolve this ?
@gre - ah we should update this in sdk22! totally slipped my mind. I’ll add to things to do
thanks for investigating.
I’ve added this comment in the README: Make sure react-native-view-shot is correctly linked in XCode (might require a manual installation, refer to React Native doc).
going to close this issue now 😃
For those who have similar issue: Manually link the component solved the problem.
the main recent changes are:
captureRef. but it does not look like it was even in Expo’s takeSnapshotAsyncreleaseCapture(that allows to “free” a previously captured image – useful to not leak files when an app usecase is to capture a lot of things).captureScreen, a new method to capture the entire screen (not a given view)see https://github.com/gre/react-native-view-shot/releases/tag/v2.0.0
(
<ViewShot>component is just a helper on top of the imperative APIs)@serdarde mmh I suspect it’s a version mismatch between react-native-view-shot and the current Expo native code of react-native-view-shot. maybe @brentvatne can help? I’m not sure where to look at in Expo source code to see which version of this library should be used.
If you use Expo, maybe try with the v1 (that have different API, refer to readme)
now i’m not sure if @xiaoyongchen were using Expo too?