Get the current App Version with Expo and React Native
July 7, 2021
Hey! Just a note, this has been pulled from my old site so, while this site is being built, some things may not work correctly or look right during the migration.
An updated version of this post is up here: Get the App Version with Expo and React Native
This one will be short and sweet.
Most apps show the version number somewhere in the app, usually in the About or Settings screen. I recently wanted to add the ability for my users to see this version number too.
To start with you'll need to install expo-constants which, as the docs state, provides system information that remains constant throughout the lifetime of your app's install.
You can install this by running:
expo install expo-constants
Then importing it wherever you need, probably in the Settings Screen file by adding:
import Constants from "expo-constants"
And then you can access the App Version wherever you want by using:
const version = Constants.manifest.version
For example, you can grab a Text element and slap the version variable in there like so:
Congrats! You can now access the app version from anywhere within your app.
Just a warning, while testing your app through Expo Go, it will show you the version of Expo Go. This is a common mistake people make which can lead to a little confusion as it seems the constant isn't working properly. I'm totally not saying this just because it confused me for a moment.
expo-constants also contains a few other useful things such as getting the platform your app is running on and the status bar height. You can read more about it here: https://docs.expo.io/versions/latest/sdk/constants/
I do quite a bit of programming and only now getting into mobile development with Expo and React Native. You can see some of my stuff with Unreal Engine on this site with posts such as Controlling What Happens on Fell Out Of World and Taking In-Game Screenshots with UI in Unreal Engine.
And if this helped you, consider buying me a coffee on Ko-Fi at https://ko-fi.com/rhyce.