What is the best way to integrate a react-native application into another react-native application? - react-native

I've implemented a react-native application and now I want to enhance it by adding along side it another different react-native application.
What i want to achieve is to keep the two application separated in order to continue to implement them as two separate application, and avoid to rewrite them completely as a single application.
Both application are using react-redux to handle their states. The first brutal approach which I have tried is to wrap one of the two application into a npm package and add it as a dependence of the other one. Then I've just added a tab to the main application which when clicked navigate to the second application. This approach seems to work, but I don't think is the best way to do it.
Do you think there could be any sort of problem doing so? Is there a more intelligent and elegant way to do it? I know it is kinda a generic question, so I would accept also an article/link about this argument.

You can create a git tag of your second application and can add it as a dependency in your first application.
You can also add it as a git sub-module.
P.S. i prefer the first one.

I think the best way to do it would be Linking as described here: Basic usage. So, you can easily pass needed parameters to the other app you want to open and also read them as app opens. Check this simple example:
Caller app:
Linking.openURL('calleeApp://app?param1=test&param2=test2')
Callee app:
componentDidMount() {
Linking.getInitialURL().then((url) => {
if (url) {
console.log('Initial url is: ' + url);
}
}).catch(err => console.error('An error occurred', err));
}
do not forget to import it first:
import { Linking } from "react-native";
Let me know if it worked for you!

Related

React Native App Working in Development, 'Error: 'undefined' is not a function' in Production

I have completed an app that builds on both Android and iOS. It works as expected when I build the app from the CLI or when I build it via XCode / Android Studio. However, on TestFlight, it gets errors that simply do NOT exist when I build it locally. These errors only appear on TestFlight, and thus I have little to no idea on how to go finding them down or even resolving them. Does anyone have better expertise in this area?
I'm not sure how common an issue this is-- I've never heard of it before to be honest, but the components that were not working were components that utilized ({props}) in a component. For example, any component wthat utilized the following declarations did NOT work
function Example({props}){
// stuff
}
// OR //
const Example = ({props}) => {
// stuff
}
all of the values inside of props were unreadable. I fixed this by simply moving EVERYTHING into a recoil state instead and that mitigated any errors. For example...
navigation.navigate("path",{prop1: value})
// AND //
return (<Example prop={value} prop={value})
would not work unless the prop was a single value-- a string, an int, a bool, these would work. Objects and Arrays did NOT properly carry over.
Hope this helps someone in the future.

Fast refresh in react native always fully reload the app

This question has been asked several times here(here the most relevant,Another example), but no solution has been proposed in any of them. So I have 2 questions to you guys:
Any idea why it wouldn't work in a large project? I mean, there are any know issues with fast refresh related to the size of the project or the packages he includes that will make fast refresh stop working? There is any way to fix it?
Is there a convenient way to edit an internal page in the app without using a fast refresh (without running the page independently, since it depends on all the logic of the app)?
This bug really makes the development really difficult for me, and I find it hard to believe that professional developers have not found a way around this problem, Please help!
I'm using expo-cli(v3.26.2 - Expo SDK 38 that using react-native v0.62)
TLDR;
using default export with no name ALWAYS resulted in a full reload of the app without hot reload!
Details
So after a lot of months of pain, I accidentally found a strangely enough effect:
I usually write my react components in this syntax:
export default ({ ...props }) => {
...
};
and for some reason, changing a module that exports that way ALWAYS resulted in a full reload of the app without hot reload!
after months of pain, accidentally i found out that changing the export to:
const Test = ({ ...props }) => {
...
};
export default Test;
completely fixed the issue and now hot reload works perfectly fine!
I did not saw this effect mentioned in a single place on the internet!
From react-refresh-webpack-plugin troubleshoot section
Un-named/non-pascal-case-named components
See this tweet for drawbacks of not giving component proper names.
They are impossible to support because we have no ways to statically
determine they are React-related. This issue also exist for other
React developer tools, like the hooks ESLint plugin. Internal
components in HOCs also have to conform to this rule.
// Wont work
export default () => <div />;
export default function () {
return <div />;
}
export default function divContainer() {
return <div />;
}
There is an other way to obtain this weird behavior.
When you export a simple function:
//if we export this function in the entry file of the app,
//it will break the hot reload feature without any warnings.
export function someName() {
};
from the entry file of your app (with typescript template expo init nameApp the file is App.tsx)
It will exactly produce a full reload of the app rather than a hot reload.
This is vicious because on ios simulator it full reloads the app without the modification whereas in android it full reloads the app WITH the modification. So you'll take some time to realize that this is not a hot reload in android but a full reload.
IDK why ios don't display the modification like android does..
But when you think at the problem, we shouldn't export multiple things from the entry point of an app. This sounds weird isn't it ?
TLDR;
During development, I had your problem with the infinity "Refreshing..." message. As well as incomprehensible errors like "unknow resolve module 2" and "bundle error..."
Details
the solution turned out to be unexpected, I changed "require()" to "import" in the main index.js file
before
const module = require('some-module')
after
import module from 'some-module';

How to make an vpn app using react native

I Searched a lot about how to make an l2tp or pptp vpn app using react-native
but i didn't find anything
anyone has solution?
Example projects:
react-native-vpn-app
react-native-vpn-app forks
vpn-app
You can fork them on github and make the changes you want to.
[EDIT]
You can use react-native-ip-sec-vpn now!
Use it like as follow:
import {prepare, connect} from "react-native-ip-sec-vpn";
...
useEffect(() => {
prepare();
}); /// or use componentDidmount in case of a class component
...
connect(address, username, password)

SystemJS with React native

I want to use systemjs inside react-native.
When I use following code in the browser systemjs register itself with global/window.
fetch('https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.18.17/system.src.js')
.then(response => response.text())
.then(txt => {
eval(txt);
})
.catch(ex => {
console.log(ex);
});
I executed same code in expo AwesomeProject on the homescreen component and the above code does not throw any exceptions, but when I try to render all the globally registered objects I don't see SystemJs/System.
First question I have - Is it even possible to register systemjs and use it with react-native?
If the answer to first question is yes, then is it the correct way to eval(Systemjs)?
If not is there any other method I can use to access system js?
I have seen couple of projects on github like react-native-eval and react auto updater, but that is not what I want.
Anyone can give me some insight?
I will answer my own question.
Yes it is possible to load systemjs in React native.
Simple eval will evaluate the systemjs code, but you might get some errors. I am not an expert in the internals of systemjs but it seems it tries to run in some context, either a browser or in some cases a node server.
I received an error in following code.
var vmModule = 'vm';
var vm = require(vmModule);
I had to tweak my code a little bit and supply a fake require function and I was able to load systemjs.

Is there a oficial plugin or SDK to use MercadoPago in React-Native for iOS?

The problem here is that I need call MercadoPago in mi Application using React-Native, but i can not find the way,
I found this wrapper for use in React-Native,
https://github.com/shovelapps/react-native-mercadopago
but when I am trying to call it I have an error in startCheckOut method,
I am using in this way the Wrapper
import RNMercadopago from 'react-native-mercadopago';
and I am calling the method in a click event using this line:
RNMercadopago.startCheckout(publicKey, prefId, null, false, (payment) => { this._success(payment)}, (error) => { this._failure(error) });
but I am getting the bellow error,
undefined is not an object (evaluating 'RNMercadopago.startCheckout)
all this code is in the index.ios.js
best regards
you may use react-native-mercadopago-checkout. It allows you to implement MercadoPago checkout in two diferent ways (both of them are documented).
It's a new implementation that is working in a production app. Even, if you find a bug, you could open an Issue and be sure that it will be resolved!