I am currently trying to import ReactNativeHeading into a Hello World Viro App for android and after following these instructions, all I get is undefined. The following code can be run in both App.js
and node_modules/@zsajjad/react-native-heading/ReactNativeHeading.js
with the same result:
import { NativeModules } from 'react-native';
console.log(NativeModules) // {}
console.log(NativeModules.ReactNativeHeading) // undefined
The reason why I even tried to log NativeModules.ReactNativeHeading
is because it seemed to be the solution of this similar question.
Every NativeModule I have come across tells you to insert certain lines of code into your MainApplication.java
, which leads me to believe that the contents of the MainApplication.java
play a role for your app. So, I tried writing jibberish into the file and expected a Syntax Error (because I thought the ReactNative CLI takes care of compiling everything) but got nothing.
My conclusion was that the ReactNative CLI does not compile the android project (or at least does not compile anything containing the MainApplication.java
) and so I tried compiling it myself (after removing the jibberish, of course). It compiles successfully now but that still hasn't fixed my problem.
I'm really running out of ideas, especially because I have next to no experience with Java and this is my first ReactNative project. If you could give me any advice whatsoever (even if it's just something a little more specific to type into Google), I'd really appreciate it!