Lock React Native version in xcode IOS - ios

I have been using React Native for the past 4 of months working both on Android and IOS. According to React Native Docs there will be an updated version of React Native every month. So, I keep updating it every month which is good, but the problem is I am using a couple of npm packages which is getting outdated due to react-native update which in-turn causes errors in my project.
For Android, we can lock the react-native version by specifying the version number in gradle. And for the Javascript part we can lock it in package.json. But for IOS I am not able to find anything like that.
So, is there way to lock the react-native version in IOS xcode?

Yes, make your package.json file at root path - react-native version to fixed number. for example:
"dependencies": {
"react-native": "0.50.4",
}
So every time you do npm install, that given version will be installed. without postfix ^ it will never be upgraded.
The react-native version of iOS is just a project / static library import from node_module/react-native/Libraries folder, via react-native link.
Update 1:
Take RCTAnimation.xcodeproj in project for example,
you can find it locate at node_modules/react-native/Libraries/NativeAnimation/RCTAnimation.xcodeproj.

Related

Upgrading React Native plugin to support autolinking and React Native versions 0.6>=

I am fairly new to React Native but am helping manage a React Native plugin and would like some guidance for upgrading it so that it is compatible with auto linking and React Native versions 0.60 and up in iOS.
Our plugin currently only works with React Native up to and including 0.59.x through the react-native link command and sometimes involves manually dragging our xcodeproj and .a binary inside Xcode.
When trying to instrument our plugin with a blank hello world React Native app of version 0.60.5, after react-native link and dragging in Xcode, we get an error saying rctbridgemodule.h not found and have to add React.xcodeproj too. This however doesn’t work on some apps we’ve tried. Furthermore the issue is in newer versions of React eg 0.61.4, the React.xcodeproj file is no longer in the React folder in node_modules. 

I’ve had a look at the What do I need to have in my package to make it work? Section in this link: https://github.com/react-native-community/cli/blob/master/docs/autolinking.md
But to me its not very clear how we should be configuring a pod spec in the root of our repo. Our package is scoped also. I’m assuming that there shouldn’t need to be any changes to the actual code of our plugin but rather just some modifications to our pod spec and package configuration. Any guidance in how this works and how to upgrade our plugin to support versions 0.6 and above would be greatly appreciated. Thanks!

Renaming a React Native project

I have a working react native app (without expo), running and compiling in both Android and iOS devices. Now I'm trying to rename the app, but I'm having problems with that.
Steps followed:
I have deleted both ios and android directories.
Changed the project name in my app.json
Regenerated the android and ios directories with react-native upgrade --legacy (cause eject is not working anymore)
Updated my podfile with the need
Pod install
When i tried to compile my app via xcode, I got "null is not an object (evaluating '_RNGestureHandlerModule.default.Direction')
I guessed that was due to the autolinking when you install some react native third party components. So I deleted node_modules, and installed all react native navigation again. Then I ran react-native link. The previous error went away.
Now, I'm stuck with:
Target 'cjlrnneTests' has target dependency on Target 'cjlrnne'
That command depends on command in Target 'cjlrnne': script phase “[CP] Copy Pods Resources”
Honestly, I don't know what else more to do / look for.
Can anyone please provide with some clue, or the steps to change a RN app's name?
Thanks!
You can try this package for renaming the app.
react-native-rename
https://www.npmjs.com/package/react-native-rename
react-native-rename <newName>
It will automatically configure all the things.

React Native project version upgrade error: v0.56 to v0.60, iOS fails

I'm currently upgrading one of my projects built in React Native v0.56 to latest v0.60. Created a new project with version v0.60 and updated all the packages used in previous version of app, but now facing weird errors.
I've already tried all the possible solutions mentioned in Git and Stack overflow. None of them worked for me. I've also tried to remove plugins one by one and then adding them but not able to find cause of the error.
iOS:
In iOS, all the packages by default autolinks as per v0.60, but I got error of linking in very first package, I've tried manual linking too, not working.
After manual linking do cd ios and then pod install. This will not be done by autolinking and you have to do it yourself. On iOS on my project i had to manual link on iOS almost every library and almost all of them needed a pod install
use upgrade helper from react native community Upgrade Helper

RN 0.38.0 React/RCTBridgeModule.h' file not found

This is a long shot, but I've taken over a project done in RN v .38 and I need to update a library and resolve the build issues without updating the version of react native. I'm trying to update the react-native-aws-cognito-js library and while it looks to be compatible with the formatting change of import statements, I'm still not able to get it to build on IOS. Android is fine.
To reproduce my issue I did the following:
react-native init sample --version 0.38.0
cd sample
npm install react-native-aws-cognito-js
react-native link react-native-aws-cognito-js
react-native run-ios
Which fails with:
/node_modules/react-native-aws-cognito-js/ios/RNAWSCognito.h:4:9:
fatal error: 'React/RCTBridgeModule.h' file not found #import
Mobile and RN development is not my wheelhouse, but I'm hoping there is some sort of xcode configuration or tricks I can do to get this working and avoid a major overhaul. Running an upgrade to >.40 would probably take too long and also cause other compatibility issues that I don't have the time to resolve.
Note: I have tried the suggestions in `React/RCTBridgeModule.h` file not found

How to install SafeAreaView to my project with react-native version 0.48.0?

Here is the problem:
I want to install SafeAreaView to my project to adapt iPhone X screen, and I do not want to upgrade react-native version to 0.50.1 which contains the SafeAreaView component, now my react-native version is 0.48.0, there is also a JS only version that is available as an npm module, react-native-safe-area-view.
https://github.com/react-community/react-native-safe-area-view
I installed it with
npm install react-native-safe-area-view --save
then I run my project with xcode, It shows errors
Here is the errors:
error: bundling failed: ambiguous resolution: module /Users/dongfanggouwu-xiong/WebstormProjects/untitled/index.js tries to require react-native, but there are several files providing this module. You can delete or fix them:
/Users/dongfanggouwu-xiong/WebstormProjects/untitled/node_modules/react-native-safe-area-view/node_modules/react-native/package.json
/Users/dongfanggouwu-xiong/WebstormProjects/untitled/node_modules/react-native/package.json
there are two react-native module, one is in react-native-safe-area-view, and I don't know how to fix it, I have wasted much time on it, and tried a lot ways to find a solution.
So is there anyone who has the same problem about iPhone X adaption in react-native with me?
Finally, I found a solution.
If you’re not on React Native 0.50+ yet, you can use react-navigation’s SafeAreaView.
import { SafeAreaView } from 'react-navigation'
and the react-navigation version must be the newer version which contains SafeAreaView, as far as i know, react-navigation version has to at least 1.00#beta 16, so maybe you need to upgrade your react-natigation to a newer version.

Resources