Answer the question
In order to leave comments, you need to log in
How to properly adapt regular JS code to the requirements of React Native? What should be considered?
There is a JS code that works on a page opened in WebView and operates with data about location, speed, etc. For some reason, this code needs to be translated directly into React Native itself. As far as I can see, React Native has a slightly different syntax. What should be considered in such a transition?
Answer the question
In order to leave comments, you need to log in
Somewhat blurry.
What would I do.
The task is to preserve the code as much as possible in the form in which it is written under the Web.
1) If you need to transfer the UI, then this part will have to be rewritten.
2) Geolocation. Let's imagine that the access to it differs greatly in syntax and the data is returned in a different form.
Then we include the library in a separate file and write a wrapper class that will make the necessary requests and return the answer in the right form for the code from the web.
Hypothetical example.
On the Web the syntax is:
GEO.getLocation(function(result){
});
let geo = await System.getGeo();
let location = await geo.getLocation();
class Geo {
static async getLocation(callback) {
try {
let geo = await System.getGeo();
callback(await geo.getLocation());
} catch(e) {}
geo = null;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question