On every React Native project that I was involved, there was always a most-feared moment: checking if your app is running as expected (and as similar as possible to the UIs shared by the designer) on lots of smartphones and iOS/Android version.
By default Expo permits you to load open only one iOS Simulator via expo-cli ios or via the Expo developers tools, but it's really difficult to check if the layout is working as expected (and to check that the current fix isn't breaking anything else) when you have only one device
You can always open multiple instances of the iOS Simulator manually, install the Expo app on each one and then launch the app, but it's a waste of time if you need to do it everyday or if you press cmd+q by mistake.
Bash script to the rescue
To fix this problem, we can create a bash script that automatically starts the iOS simultators, installs the latest version of the Expo app and launches your app.
1. Find the IDs of the devices that you want to launch 👀
The best way is to open your terminal and launch
xcrun simctl list
That will outputs all the simulators available on your Mac. They are already sorted by iOS version and by device type.
We are going to launch 3 devices: a iPhone 5s, a iPhone 6s Plus and a iPhone 11 Pro Max. Let's copy their IDS (the alphanumeric characters after after the device name) and save for later.
5C023A36-BAF9–4417-AD44-E1A446081337
DD0B67AD-FFD2–408A-AB0B-556801E7B342
A232D839-BC4B-45DA-8B6C-F57DA8EB44DC
2. Find the latest version of the Expo app
We will need to know the latest version of the Expo app client that will be installed on the simulators (as of January 2020, this is the 2.14.1).
The app is already present on the Expo cache on your Mac, so we just need to go to this folder
~/.expo/ios-simulator-app-cache
And you will find all the app versions already downloaded by Expo.
3. Create the script👨💻
Create a file named start_simulators.sh (change the name as you want) and enter this code (I found this script on this StackOverflow answer, by Stephan Schlecht):
#!/bin/bash
declare -a simulators=("0FAE2F92-9EF7-4C4A-8F9D-097A056F8CC0" "BFCDD662-E4DE-4C08-9DF6-CAACA7C00CEC" "1A6959A0-C10F-474B-96C5-7E8955FBDD80")
for i in "${simulators[@]}"
do
xcrun instruments -w $i
xcrun simctl install $i ~/.expo/ios-simulator-app-cache/Exponent-2.14.1.app
xcrun simctl openurl $i exp://127.0.0.1:19000
done
As you can see, in this script you need to put both the simulators IDs (with quotes and space separated) both the latest version of the Expo App.
Now you need to make this script executable:
chmod 755 start_simulators.sh
4. Use it as much as you want ✨
Now you can enter in your terminal the command
./start_simulators.sh
And it will automatically start the selected simulators, as well as install the Expo app opening the Expo app on port 19000.
Now it's time to fix that UI bugs!
Top comments (0)