Create own dependency in react native for iOS - ios

I'm creating first react-native dependency for both android and iOS. I have done coding part for android but now I'm stuck in iOS. Where to write code for my library and how to test.

React Native uses CocoaPods to manage iOS project dependencies and most React Native libraries follow this same convention.
Run pod install in our ios directory in order to link it to our native iOS project. A shortcut for doing this without switching to the ios directory is to run npx pod-install.
Once this is complete, re-build the app binary to start using your new library:
npx react-native run-ios.
For testing the code you could use Jest testing framework.
go onto the ReactNative for more guidance.

Related

How to open an Expo React Native project in Xcode in order to create a build

I have an expo react native app's project and xcode simply denies to open it. I looked up for the solutions on internet but it says it can be done through podfile but there is no such file or ios folder in an expo react native project. How can I open it in xcode
If you dont have the ios and android folders then it sounds you have a managed work flow expo project. This is a react native project where all the code you write is pure javascript and all of the native side code is managed by expo. If this is what you want then you just need to use expo build tools. If you must build with xcode then eject your project and open the ios folder in xcode and build from there

Does iOS support the react native library

I am developing a iOS application where I need to develop the functionality like a react native library is this possible I am using react native library in my native application.
$ npm install --save
use this command to automatically add all the react native libraries be it an android application or an IOS application.
In case you want to do it manually,
please refer the link below which gives you the step by step pictorial representation on how to do it-
https://facebook.github.io/react-native/docs/linking-libraries-ios

Use Expo iOS app to test pure react native code

I want to be able to test an app created with react-native init through the expo app downloaded from the app store. How can I do this?
I'm trying to use pure react native (no expo at all) and want to test my code on my iOS device. A while ago, I was able to do this through the expo app simply by running npm start. However, now when I run npm start I only see Running Metro Bundler on port 8081..
You cannot run a project created with react-native init with the Expo app. However, you can use https://snack.expo.io/ to test plain React Native code in either the browser emulator or on your device (which will open through the Expo app) by pointing your iOS camera app at the QR code they display for you. The caveat to this is that you cannot use native modules within a Snack.
Depending on the size of your app, you can port your code over from react-native init into a freshly created expo project. I have managed to do this on several projects in the past with great success. The process can be tedious depending on the age of your dependencies however.

Integrating React-Native to an existing App

I'd like to integrate react-native modules in already existing iOS App but keeping both solutions separately.
Instead of doing this https://facebook.github.io/react-native/docs/integration-with-existing-apps.html which modifies the existing solution, I would like to have a standalone react-native solution and somehow import the Xcode project of the react-native app into my already existing app.
This allows me to continue developing the already existing app without being affected by the RN solution which installs and add libraries to the Xcode project.
Basically the concepto would be to export the react-native solution as a bundle or static library and import it in my already existing iOS App. After that interact with this library from the already existing iOS App and also allow the React-Native Solution library interact with the already existing app. There should be a way to communicate from the already existing app to the RN Solution library and also from the RN solution library with the already existing (i.e. for launching modules from the already existing iOS app and also from the RN solution be able to launch views of the already existing app)
Is this possible?
You can do most of the things you are referring. Excuse me if a miss something...
Runninig as standalone
If you don't have ios and android folders in your RN directory, you must run react-native eject from CLI.
React-native application can be started as a standalone native app using the CLI commands below:
react-native run-ios (only on MacOS)
react-native run-android
Add --port #### if the default is being used.
Both commands will start something like a sandbox native app which will load the JS inside. It will also start the Metro bundler which will serve the js bundle as well.
Loading RN into existing app
You need to add the native RN libraries for Android and iOS as dependencies, so you can use them to load either the JS bundle from the Dev server or insert the JS bundle within the native build.
To use the dev server run react-native start.
To build the JS as a file which will be added to the native package you must run:
react-native bundle ios
Followed by couple of options
--dev false or true
--entry-file index.ios.js change this to match your entry file. It may be just index.js. Be carefull to match the name inside Java/Obj-C code.
--bundle-output ../YOUR-EXISTING-IOS-APP/main.jsbundle
--assets-dest ../YOUR-EXISTING-IOS-APP
Communication
This happens over the RCTBridge.
Check this page for a explanation and examples how to access native functionality from the RN environment.

Mixing cordova web and native iOS code

I have inherited a Cordova project that mixes web code with native code.
I'm using cordova CLI 6.3.1 and the cordova ios platform version is 3.9.2.
Whilst working I come across this warning in the console.
Using this version of Cordova with older version of cordova-ios is
being deprecated. Consider upgrading to cordova-ios#4.0.0 or newer.
However, when I try updating the ios platform version using cordova platform update ios --save it completely wipes out all files in the "platforms" folder - which currently includes all the custom iOS project files, i.e. custom classes and what not.
Is there something fundamentally wrong with our project setup?
What is the recommended way to mix and match cordova web and native iOS code so that updating the cordova ios platform doesn't nuke everything?
Generally, the files under /platforms are generated on the fly based on changes that are made in /www. Running cordova prepare ios, cordova build ios, cordova platform update ios, or cordova run ios, will always nuke the platforms/ios folder and retreat it based on /www.
You mentioned your project has custom native code. Is that native code built as a cordova plugin? If so then you should be good following the standard workflow. Work in /www. Test your project cordova run ios.
If not, you might want to consider refactoring the native code you have as a plugin.
Look at this plugin's code structure as an example.
Follow this guide on how to start developing a plugin.

Resources