<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Wouter van den Broek</title>
    <description>The latest articles on DEV Community by Wouter van den Broek (@wbroek).</description>
    <link>https://dev.to/wbroek</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F56765%2Fa62f1bf5-ebd7-4ba7-8a69-ccf4a575eec9.png</url>
      <title>DEV Community: Wouter van den Broek</title>
      <link>https://dev.to/wbroek</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/wbroek"/>
    <language>en</language>
    <item>
      <title>Migrate from react-native-unimodules to Expo modules</title>
      <dc:creator>Wouter van den Broek</dc:creator>
      <pubDate>Tue, 16 Nov 2021 20:48:04 +0000</pubDate>
      <link>https://dev.to/wbroek/migrate-from-react-native-unimodules-to-expo-modules-25c6</link>
      <guid>https://dev.to/wbroek/migrate-from-react-native-unimodules-to-expo-modules-25c6</guid>
      <description>&lt;p&gt;Expo has upgraded their modules strategy, why you can &lt;a href="https://blog.expo.dev/whats-new-in-expo-modules-infrastructure-7a7cdda81ebc"&gt;read here&lt;/a&gt; and replace the package react-native-unimodules with expo package. In this article you can read how to migrate from the old react-native-unimodules to the brand new Expo modules wth the expo package.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note&lt;/em&gt; that the react-native-unimodules had some evolution in the past as well, some code changes could look a little but different. Your app name could be different; myapp is used in the examples below&lt;/p&gt;

&lt;h2&gt;
  
  
  Remove react-native-unimodules
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Remove react-native-unimodules from the package.json (&lt;code&gt;npm uninstall&lt;/code&gt; or &lt;code&gt;yarn remove&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  iOS
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Remove the import and use of react-native-unimodules in &lt;code&gt;ios/Podfile&lt;/code&gt; and run &lt;code&gt;npx pod-install&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt;&lt;span class="p"&gt;require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
&lt;/span&gt;&lt;span class="gd"&gt;- require_relative '../node_modules/react-native-unimodules/cocoapods.rb'
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt;&lt;span class="p"&gt;target 'MyApp' do
&lt;/span&gt;&lt;span class="gd"&gt;-  use_unimodules!
&lt;/span&gt;  config = use_native_modules!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Remove react-native-unimodules references from &lt;code&gt;ios/MyApp/AppDelegate.h&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt;&lt;span class="gd"&gt;- #import &amp;lt;UMCore/UMAppDelegateWrapper.h&amp;gt;
&lt;/span&gt;
- @interface AppDelegate : UMAppDelegateWrapper &amp;lt;UIApplicationDelegate, RCTBridgeDelegate, UNUserNotificationCenterDelegate&amp;gt;
&lt;span class="gi"&gt;+ @interface AppDelegate : UIResponder &amp;lt;UIApplicationDelegate, RCTBridgeDelegate, UNUserNotificationCenterDelegate&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Remove react-native-unimodules references from &lt;code&gt;ios/MyApp/AppDelegate.m&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt;&lt;span class="gd"&gt;- #import &amp;lt;UMCore/UMModuleRegistry.h&amp;gt;
- #import &amp;lt;UMReactNativeAdapter/UMNativeModulesProxy.h&amp;gt;
- #import &amp;lt;UMReactNativeAdapter/UMModuleRegistryAdapter.h&amp;gt;
&lt;/span&gt;
- @interface AppDelegate () &amp;lt;RCTBridgeDelegate&amp;gt;
&lt;span class="gd"&gt;-  @property (nonatomic, strong) UMModuleRegistryAdapter *moduleRegistryAdapter;
- @end
&lt;/span&gt;
@implementation AppDelegate
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
&lt;span class="err"&gt;{&lt;/span&gt;
- self.moduleRegistryAdapter = [[UMModuleRegistryAdapter alloc] initWithModuleRegistryProvider:[[UMModuleRegistryProvider alloc] init]];

- [super application:application didFinishLaunchingWithOptions:launchOptions];
  return YES;
&lt;span class="err"&gt;}&lt;/span&gt;

&lt;span class="gd"&gt;- - (NSArray&amp;lt;id&amp;lt;RCTBridgeModule&amp;gt;&amp;gt; *)extraModulesForBridge:(RCTBridge *)bridge
-{
-  NSArray&amp;lt;id&amp;lt;RCTBridgeModule&amp;gt;&amp;gt; *extraModules = [_moduleRegistryAdapter extraModulesForBridge:bridge];
-  // If you'd like to export some custom RCTBridgeModules that are not Expo modules, add them here!
-  return extraModules;
-}
&lt;/span&gt;
@end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Android
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Remove react-native-unimodules from &lt;code&gt;android/app/build.gradle&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt;&lt;span class="p"&gt;apply plugin: "com.android.application"
&lt;/span&gt;&lt;span class="gd"&gt;- apply from: '../../node_modules/react-native-unimodules/gradle.groovy'
&lt;/span&gt;
dependencies {

- addUnimodulesDependencies()

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Remove link to react-native-unimodules from &lt;code&gt;android/settings.gradle&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt;&lt;span class="p"&gt;rootProject.name = 'MyApp'
&lt;/span&gt;&lt;span class="gd"&gt;- apply from: '../node_modules/react-native-unimodules/gradle.groovy';
- includeUnimodulesProjects()
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Remove reference of react-native-unimodules in &lt;code&gt;android/app/src/main/java/com/myapp/MainApplication.java&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt;&lt;span class="gd"&gt;- import com.myapp.generated.BasePackageList;
&lt;/span&gt;
- import java.util.Arrays;

- import org.unimodules.adapters.react.ModuleRegistryAdapter;
&lt;span class="gd"&gt;- import org.unimodules.adapters.react.ReactModuleRegistryProvider;
&lt;/span&gt;
public class MainApplication extends Application implements ReactApplication {
&lt;span class="gd"&gt;-   private final ReactModuleRegistryProvider mModuleRegistryProvider = new ReactModuleRegistryProvider(new BasePackageList().getPackageList(), null);
&lt;/span&gt;
    private final ReactNativeHost mReactNativeHost =
      new ReactNativeHost(this) {

        @Override
        protected List&amp;lt;ReactPackage&amp;gt; getPackages() {
            @SuppressWarnings("UnnecessaryLocalVariable")
             List&amp;lt;ReactPackage&amp;gt; packages = new PackageList(this).getPackages();
            // Packages that cannot be autolinked yet can be added manually here, for example:
            // packages.add(new MyReactNativePackage());

-            // Add unimodules
&lt;span class="gd"&gt;-            List&amp;lt;ReactPackage&amp;gt; unimodules = Arrays.&amp;lt;ReactPackage&amp;gt;asList(
-                new ModuleRegistryAdapter(mModuleRegistryProvider)
-            );
-            packages.addAll(unimodules);
&lt;/span&gt;
            return packages;
        }

      };
&lt;span class="err"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Remove the generated package list file located at &lt;code&gt;android/app/src/main/java/com/myapp/generated/BasePackageList.java&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Update Expo SDK packages
&lt;/h2&gt;

&lt;p&gt;If you already have Expo SDK packages installed like &lt;code&gt;expo-calendar&lt;/code&gt;, as I had, you need to update those to the latest version as well. Check your &lt;code&gt;package.json&lt;/code&gt; to see which Expo SDK packages are there, set them to the latest version and run npm or yarn.&lt;/p&gt;

&lt;h2&gt;
  
  
  Add Expo modules
&lt;/h2&gt;

&lt;p&gt;Now we removed the old react-native-unimodules and updated the Expo SDK packages we can install the new Expo modules. &lt;/p&gt;

&lt;h3&gt;
  
  
  Automatic install
&lt;/h3&gt;

&lt;p&gt;Expo made a great tool to add the Expo package and adjust all the native files: &lt;code&gt;npx install-expo-modules&lt;/code&gt;&lt;br&gt;
I would recommend this to use for adding the Expo modules. Beacuse we removed the old react-native-unimodules it should work for most projects. If not and it fails or you cannot build the project you can try the manual instalation &lt;/p&gt;
&lt;h3&gt;
  
  
  Manual install
&lt;/h3&gt;

&lt;p&gt;Expo has an in &lt;a href="https://docs.expo.dev/bare/installing-expo-modules/#manual-installation"&gt;detailed description&lt;/a&gt; how to add Expo modules the manual way. Just modify all the named files and it should be ok.&lt;/p&gt;
&lt;h2&gt;
  
  
  Update imports in Typescript/Javascript
&lt;/h2&gt;

&lt;p&gt;The old react-native-unimodules, and the new Expo moduels as well, included some Expo SDK packages like &lt;code&gt;expo-application&lt;/code&gt;, &lt;code&gt;expo-constants&lt;/code&gt; and 'expo-file-system'.&lt;br&gt;
You need to migrate the one you imported from react-native-unimodules to now use the real Expo SDK package name and imports. For example if we used Expo constants we need to change the code below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt;&lt;span class="gd"&gt;- import { Constants } from 'react-native-unimodules';
&lt;/span&gt;&lt;span class="gi"&gt;+ import Constants from 'expo-constants';
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>reactnative</category>
      <category>expo</category>
    </item>
  </channel>
</rss>
