Skip to content

V3 to V4 Migration Guide

Mike Hardy edited this page Oct 11, 2019 · 1 revision

Welcome to V4!

Introduction / Background

Thank you for your patience during the transition from v2 through v3 onto v4

V3 was intended to have performance benefits (via moving from constants to an async API) without affecting anyone. It was intended to be low impact. V3 maintained an xxxSync() API set so that if you did not want to be async, you didn't have to be.

I did take the opportunity to clean up API naming - breaking change but easy, and I took the opportunity to remove community duplication by moving a couple APIs to react-native-localize. Neither of those turned out to be big deals.

So, no problem right? v3 must have been great!

Hooboy! Turns out doing things sync without using constants breaks the Chrome debugger. That was unexpected. It was certainly not intentional. And I recognize it was disruptive while people really needed to move to v3 because of App Store UIWebView requirements.

So here we are. For v4 I have set the design where some constants are allowed again - those that are the most needed during bootstrap where pure-async is hard - but the rest is still async with a sync API for emergencies.

It is an attempt to strike a balance which means it may not be perfect for everyone, but that's the state of mobile development.

If there is an API that you really would like as a constant, please file an issue report and we'll see what we can do. But be patience with us just as you would with any co-worker, but especially since we are volunteers.

Thanks -

  • @mikehardy

Device Info Constants

These items are now constants and may be accessed safely (even under the debugger) synchronously, per the example/App.js:

getConstantDeviceInfo() {
    let deviceJSON = {};

    deviceJSON.uniqueId = DeviceInfo.getUniqueId();
    deviceJSON.deviceId = DeviceInfo.getDeviceId();
    deviceJSON.bundleId = DeviceInfo.getBundleId();
    deviceJSON.systemName = DeviceInfo.getSystemName();
    deviceJSON.systemVersion = DeviceInfo.getSystemVersion();
    deviceJSON.version = DeviceInfo.getVersion();
    deviceJSON.readableVersion = DeviceInfo.getReadableVersion();
    deviceJSON.buildNumber = DeviceInfo.getBuildNumber();
    deviceJSON.isTablet = DeviceInfo.isTablet();
    deviceJSON.appName = DeviceInfo.getApplicationName();
    deviceJSON.brand = DeviceInfo.getBrand();
    deviceJSON.model = DeviceInfo.getModel();

    return deviceJSON;
  }

How to Migrate

  • Typescript users: type imports may be different now, as the repo is in Typescript. An example
import DeviceInfo from 'react-native-device-info';

let model = DeviceInfo.getModel();
  • getDeviceType() returns 'unknown' now instead of 'Unknown' (matches rest of APIs that may return 'unknown' as string default
  • rename getCameraPresence to isCameraPresent (standard boolean accessor API naming)

That's it for breaking change.

Conclusion

The goal for this version is a tiny amount of breaking change and a great big fix for those using the debugger. Hopefully it works well for everyone.

Huge thanks to @acoates-ms, @santiagofm and @JensDebergh for helping me mop up the chrome debugger mess, and to @Johan-dutoit for the typescript conversion.