Skip to content

Commit

Permalink
expo: Migrate from "Unimodules" to "Expo modules", as requested
Browse files Browse the repository at this point in the history
Done by mostly following the changes to Expo's
templates/expo-template-bare-minimum/ in expo/expo@9781212eb.

Expo's description of the new infrastructure is at
  https://blog.expo.dev/whats-new-in-expo-modules-infrastructure-7a7cdda81ebc .

They gave a migration guide that suggested making changes similar to
these, but it didn't end up helping us understand why they were the
right changes to make or what would happen if we made them. That
guide is at
  https://github.com/expo/fyi/blob/main/expo-modules-migration.md .

We've cleared up some of the mystery; see
  zulip#5203 (comment)
and previous commits in this series.

In this commit:

- (Mostly follow expo/expo@9781212eb, as mentioned)

- Also, upgrade all our `expo-*` direct dependencies so that they
  work with the new system. (We upgrade them minimally, to minimize
  having to think about possible unrelated breaking changes right
  now.) Details at
    zulip#5203 (comment) .

- Remove
  android/app/src/main/java/com/zulipmobile/generated/BasePackageList.java,
  since its only import was removed. (Expo didn't have this file in
  version control, and the migration guide didn't mention the file.)

- The Expo commit assumes that our project has done special setup
  for `expo-updates`, `expo-constants`, and `expo-splash-screen`. It
  makes changes to that setup, which we ignore since we don't use
  any of those. If we need them in the future, we'll just look up
  their current setup instructions at the time.

- Don't add an empty Swift file. The migration guide says, "A blank
  Swift file must be created for native modules with Swift files to
  work correctly." With `find node_modules | grep .swift` in our
  project, I see that expo-modules-core and expo-web-browser have
  many Swift files in them, and I don't have any problems building
  or running the app without an empty Swift file. The template app
  doesn't add one either.

- Don't add a Podfile.properties.json file. Like the changes in
  expo/expo@dbd384b22, this would have us put certain config values
  in some new Expo-branded variables. We're happy keeping them
  inline.

- Update our value for `transformIgnorePatterns` in the Jest config,
  following an error when running Jest.

Fixes: zulip#5133
  • Loading branch information
chrisbobbe committed Jan 25, 2022
1 parent b2c3da9 commit 1c7941e
Show file tree
Hide file tree
Showing 16 changed files with 1,500 additions and 1,038 deletions.
7 changes: 0 additions & 7 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@ apply plugin: "com.android.application"
apply plugin: "kotlin-android"
apply plugin: "kotlin-android-extensions"

apply from: new File(
["node", "--print", "require.resolve('react-native-unimodules/package.json')"]
.execute(null, rootDir).text.trim(),
"../gradle.groovy"
)

import com.android.build.OutputFile

/**
Expand Down Expand Up @@ -303,7 +297,6 @@ dependencies {

implementation 'com.facebook.fresco:animated-gif:2.0.0' // For animated GIF support
implementation 'androidx.browser:browser:1.0.0'
addUnimodulesDependencies()

testImplementation 'junit:junit:4.12'
testImplementation 'org.junit.jupiter:junit-jupiter:5.4.0'
Expand Down
12 changes: 8 additions & 4 deletions android/app/src/main/java/com/zulipmobile/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.facebook.react.bridge.ReactContext
import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView;
import com.zulipmobile.notifications.*
import com.zulipmobile.sharing.handleSend
import expo.modules.ReactActivityDelegateWrapper;

// A convenience shortcut.
fun ReactApplication.tryGetReactContext(): ReactContext? =
Expand All @@ -35,11 +36,14 @@ open class MainActivity : ReactActivity() {
}

override fun createReactActivityDelegate(): ReactActivityDelegate {
return object : ReactActivityDelegate(this, mainComponentName) {
override fun createRootView(): ReactRootView {
return RNGestureHandlerEnabledRootView(this@MainActivity)
return ReactActivityDelegateWrapper(
this,
object : ReactActivityDelegate(this, mainComponentName) {
override fun createRootView(): ReactRootView {
return RNGestureHandlerEnabledRootView(this@MainActivity)
}
}
}
)
}

/* Returns true just if we did handle the intent. */
Expand Down
76 changes: 40 additions & 36 deletions android/app/src/main/java/com/zulipmobile/MainApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import android.app.Application;
import android.content.Context;
import android.content.res.Configuration;
import android.util.Log;
import androidx.annotation.NonNull;

import com.facebook.react.PackageList;
import com.facebook.hermes.reactexecutor.HermesExecutorFactory;
Expand All @@ -13,53 +15,48 @@
import com.facebook.react.ReactPackage;
import com.facebook.soloader.SoLoader;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.List;
import org.unimodules.adapters.react.ModuleRegistryAdapter;
import org.unimodules.adapters.react.ReactModuleRegistryProvider;
import org.unimodules.core.interfaces.SingletonModule;

import com.zulipmobile.generated.BasePackageList;
import expo.modules.ApplicationLifecycleDispatcher;
import expo.modules.ReactNativeHostWrapper;

import com.zulipmobile.notifications.NotificationUiManager;
import com.zulipmobile.notifications.NotificationsPackage;
import com.zulipmobile.sharing.SharingPackage;

public class MainApplication extends Application implements ReactApplication {
private final ReactModuleRegistryProvider mModuleRegistryProvider = new ReactModuleRegistryProvider(new BasePackageList().getPackageList(), null);
private final ReactNativeHost mReactNativeHost = new ReactNativeHostWrapper(
this,
new ReactNativeHost(this) {
@Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}

private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
@Override
protected List<ReactPackage> getPackages() {
// Autolinked packages.
//
// To check what's included, see the
// `getPackages` implementation, which is auto-generated
// (android/app/build/generated/rncli/src/main/java/com/facebook/react/PackageList.java):
@SuppressWarnings("UnnecessaryLocalVariable")
List<ReactPackage> packages = new PackageList(this).getPackages();

@Override
protected List<ReactPackage> getPackages() {
// Autolinked packages.
//
// To check what's included, see the
// `getPackages` implementation, which is auto-generated
// (android/app/build/generated/rncli/src/main/java/com/facebook/react/PackageList.java):
@SuppressWarnings("UnnecessaryLocalVariable")
List<ReactPackage> packages = new PackageList(this).getPackages();
// Packages that should be linked, but can't be with
// autolinking:
packages.add(new ZulipNativePackage());
packages.add(new NotificationsPackage());
packages.add(new SharingPackage());

// Packages that should be linked, but can't be with
// autolinking:
packages.add(new ZulipNativePackage());
packages.add(new NotificationsPackage());
packages.add(new SharingPackage());
return packages;
}

// Unimodules:
packages.add(new ModuleRegistryAdapter(mModuleRegistryProvider));

return packages;
}

@Override
protected String getJSMainModuleName() {
return "index";
}
};
@Override
protected String getJSMainModuleName() {
return "index";
}
});

@Override
public ReactNativeHost getReactNativeHost() {
Expand All @@ -72,6 +69,13 @@ public void onCreate() {
NotificationUiManager.createNotificationChannel(this);
SoLoader.init(this, /* native exopackage */ false);
initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
ApplicationLifecycleDispatcher.onApplicationCreate(this);
}

@Override
public void onConfigurationChanged(@NonNull Configuration newConfig) {
super.onConfigurationChanged(newConfig);
ApplicationLifecycleDispatcher.onConfigurationChanged(this, newConfig);
}

/**
Expand Down

This file was deleted.

2 changes: 2 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ buildscript {
}
repositories {
google()
mavenCentral()
jcenter()
}
dependencies {
Expand Down Expand Up @@ -59,6 +60,7 @@ allprojects {
}

google()
mavenCentral()
jcenter()
}
}
Expand Down
6 changes: 3 additions & 3 deletions android/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
rootProject.name = 'ZulipMobile'

apply from: new File(
["node", "--print", "require.resolve('react-native-unimodules/package.json')"]
["node", "--print", "require.resolve('expo/package.json')"]
.execute(null, rootDir).text.trim(),
"../gradle.groovy"
"../scripts/autolinking.gradle"
);
includeUnimodulesProjects()
useExpoModules()

apply from: new File(
["node", "--print", "require.resolve('@react-native-community/cli-platform-android/package.json')"]
Expand Down
26 changes: 26 additions & 0 deletions flow-typed/expo-apple-authentication_vx.x.x.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,36 @@ declare module 'expo-apple-authentication/build/AppleAuthentication' {

declare module 'expo-apple-authentication/build/AppleAuthentication.types' {
declare export type AppleAuthenticationButtonProps = {
// TODO: `View`'s props and…

/**
* The method to call when the user presses the button. You should call
* [`AppleAuthentication.signInAsync`](#isavailableasync) in here.
*/
onPress: () => void | Promise<void>,

/**
* The type of button text to display ("Sign In with Apple" vs.
* "Continue with Apple").
*/
buttonType: $Values<typeof AppleAuthenticationButtonType>,

/**
* The Apple-defined color scheme to use to display the button.
*/
buttonStyle: $Values<typeof AppleAuthenticationButtonStyle>,

/**
* The border radius to use when rendering the button. This works
* similarly to ` style.borderRadius` in other Views.
*/
cornerRadius?: number,

/**
* The custom style to apply to the button. Should not include
* `backgroundColor` or `borderRadius` properties.
*/
// TODO: implement
style?: mixed,
...
};
Expand Down
Loading

0 comments on commit 1c7941e

Please sign in to comment.