Kudo / react-native-HelloCxxModule

A sample of React Native CxxModule on Android

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Red screen after start

sebqq opened this issue · comments

Hello There!

First of all I would like to thank you so much for your article. Next week I'm going to try to implement my first C++ lib to do some heavy-lifting there, instead of JS thread.

Maybe I have not read the article carefully enough yet but I wanted to try it today and see if it is working as it is so I cloned the repo and installed node_modules. Afterwards I've run cd ios && pod install to install cocoapods deps.

Screenshot 2019-08-02 at 20 08 08

and after that I've tried to start the app but without success. I got red screen:

Screenshot 2019-08-02 at 20 06 39

I would like to ask you if there is anything that I've missed in article?

Thank you so so much once again!

My CxxModule sample code is only for Android because IMO interop between C++ and Obj-C is much easier than JNI.
If you are looking for iOS C++ native module, maybe you could check TurboModule. There are some good sample code already.
https://github.com/facebook/react-native/tree/master/ReactCommon/turbomodule/samples/platform/ios/

Oh :) thank you so much!

Well, just found that is not so difficult to add iOS support, so I added it last night.
1d9c0a4
However, still recommend TurbeModule IMO.

Hello @Kudo I'm finally getting to phase of my project when I need to make a decision about how to implement some heavy calculations. I would like to thank you very much for any answer.

I need to implement some x/y position/gps processing that includes:

  • load input data (height map, image screen size, etc.) based on location where the user is currently located at.
  • re-calculate X/Y position of sub-images (interactable objects placed at image) based on users real GPS location (these images can be moved manually too so there is a chance that some re-computations may happen too often lets say once per 50ms (depends on throttle's timer value).
  • to achieve position recomputation I will need to perform GPS(lat/lon) to UTM conversion.
  • read specific bits from binary file (height map) to recalculate height difference between two sub-images.

I would like to ask you if there is even small chance i could use CxxModule for that without loosing too much of ms's during bridge communication.

Code below shows How I think it should work:

  • I'm able tomj initialize custom NativeModule with some default data (which are based on current user's location using c++ module). To be more specific I would like to be able to do something like:
...
const {CxxRecomputingModule} = NativeModules;

class RecomputingComponnet extends Component {
    ...
 
    componentDidUpdate() {
        /**
        * get init values for current location (.hgh binary 
        * file's content, image size, ...). Even better would 
        * be if i could send just a path to binary file and read it 
        * directly from C++ but it is an implementation detail 
        * which I will look at and maybe solve later.
        */
        const initValues = this.props.initValues; 
        ...
        CxxRecomputingModule.setInitValues(initValues)
    }
  • Then I would like to use these initial values with every other call in order to skip too much of data sending through bridge with every new calculation, so lets say:
...
const {CxxRecomputingModule} = NativeModules;

class RecomputingComponnet extends Component {
   ...

    onPositionChanged = (newX, newY) => {
        /**
        * on the native side, recomputeNewValues() will use these 
        * two params and all values from `setInitValues()` method
        * from previous example.
        */
        CxxRecomputingModule.recomputeNewValues(newX, newY)
            .then((x, y) => {
                this.setState({newX: x, newY: y});
            });
    }

So I think I would implement something like C++ class which will hold default data in member variables and will re-use them with every other call of it's member's method.

Is something like this even possible using CxxModule? I'll be good even with one-word answer like: "Yes" or "No" 😸

Thank you so much once again!