Skip to content

Commit

Permalink
Migrate to the new vendoring mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
tsapeta committed Oct 5, 2022
1 parent 4691d47 commit ef1d278
Show file tree
Hide file tree
Showing 55 changed files with 504 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.uimanager.ViewManager
import com.shopify.reactnative.flash_list.ReactNativeFlashListPackage
import com.shopify.reactnative.skia.RNSkiaPackage
import com.swmansion.gesturehandler.RNGestureHandlerPackage
import com.swmansion.gesturehandler.react.RNGestureHandlerModule
import expo.modules.adapters.react.ReactModuleRegistryProvider
import expo.modules.core.interfaces.Package
import expo.modules.core.interfaces.SingletonModule
Expand All @@ -26,8 +28,6 @@ import org.json.JSONException
import versioned.host.exp.exponent.modules.api.*
import versioned.host.exp.exponent.modules.api.cognito.RNAWSCognitoModule
import versioned.host.exp.exponent.modules.api.components.datetimepicker.RNDateTimePickerPackage
import versioned.host.exp.exponent.modules.api.components.gesturehandler.react.RNGestureHandlerModule
import versioned.host.exp.exponent.modules.api.components.gesturehandler.RNGestureHandlerPackage
import versioned.host.exp.exponent.modules.api.components.lottie.LottiePackage
import versioned.host.exp.exponent.modules.api.components.maps.MapsPackage
import versioned.host.exp.exponent.modules.api.components.maskedview.RNCMaskedViewPackage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
import com.facebook.react.turbomodule.core.CallInvokerHolderImpl;
import com.facebook.react.uimanager.UIManagerModule;
import com.facebook.react.uimanager.events.RCTEventEmitter;
import versioned.host.exp.exponent.modules.api.components.gesturehandler.GestureHandlerStateManager;
import com.swmansion.common.GestureHandlerStateManager;

import versioned.host.exp.exponent.modules.api.reanimated.layoutReanimation.AnimationsManager;
import versioned.host.exp.exponent.modules.api.reanimated.layoutReanimation.LayoutAnimations;
import versioned.host.exp.exponent.modules.api.reanimated.layoutReanimation.NativeMethodsHolder;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
import groovy.json.JsonSlurper
import java.nio.file.Paths

buildscript {
def kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : project.properties['RNGH_kotlinVersion']

repositories {
mavenCentral()
}

dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version")
}
}

def isNewArchitectureEnabled() {
// To opt-in for the New Architecture, you can either:
// - Set `newArchEnabled` to true inside the `gradle.properties` file
// - Invoke gradle with `-newArchEnabled=true`
// - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true`
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
}

static def findNodeModulePath(baseDir, packageName) {
def basePath = baseDir.toPath().normalize()
// Node's module resolution algorithm searches up to the root directory,
// after which the base path will be null
while (basePath) {
def candidatePath = Paths.get(basePath.toString(), "node_modules", packageName)
if (candidatePath.toFile().exists()) {
return candidatePath.toString()
}
basePath = basePath.getParent()
}
return null
}

def findNodeModulePath(packageName) {
// Don't start in the project dir, as its path ends with node_modules/react-native-gesture-handler/android
// we want to go two levels up, so we end up in the first_node modules and eventually
// search upwards if the package is not found there
return findNodeModulePath(projectDir.toPath().parent.parent.toFile(), packageName)
}

if (isNewArchitectureEnabled()) {
apply plugin: 'com.facebook.react'
}
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

// Check whether Reanimated 2.3 or higher is installed alongside Gesture Handler
def shouldUseCommonInterfaceFromReanimated() {
def reanimated = rootProject.subprojects.find { it.name == 'react-native-reanimated' }
if (reanimated != null) {
def inputFile = new File(reanimated.projectDir, '../package.json')
def json = new JsonSlurper().parseText(inputFile.text)
def reanimatedVersion = json.version as String
def (major, minor, patch) = reanimatedVersion.tokenize('.')
return (Integer.parseInt(major) == 2 && Integer.parseInt(minor) >= 3) || Integer.parseInt(major) == 3
} else {
return false
}
}

def reactNativeArchitectures() {
def value = project.getProperties().get("reactNativeArchitectures")
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
}

def shouldAssertNoMultipleInstances() {
if (rootProject.hasProperty("disableMultipleInstancesCheck")) {
return rootProject.property("disableMultipleInstancesCheck") != "true"
} else {
return true
}
}

def noMultipleInstancesAssertion() {
Set<File> files = fileTree(rootDir.parent) {
include "node_modules/**/react-native-gesture-handler/package.json"
exclude "**/.yarn/**"
}.files

if (files.size() > 1) {
String parsedLocation = files.stream().map({ File file -> "- " + file.toString().replace("/package.json", "") }).collect().join("\n")
String exceptionMessage = "\n[Gesture Handler] Multiple instances of Gesture Handler were detected. Only one instance of react-native-gesture-handler can be installed in a project. You need to resolve the conflict manually. Check out the documentation: https://docs.swmansion.com/react-native-gesture-handler/docs/troubleshooting#multiple-instances-of-gesture-handler-were-detected \n\nConflict between: \n" + parsedLocation + "\n";
throw new Exception(exceptionMessage);
}
}

def REACT_NATIVE_DIR = findNodeModulePath("react-native")

def assertionTask = task assertNoMultipleInstances {
onlyIf { shouldAssertNoMultipleInstances() }
doFirst {
noMultipleInstancesAssertion()
}
}

tasks.preBuild {
dependsOn assertionTask
}

repositories {
mavenCentral()
}

android {
compileSdkVersion safeExtGet("compileSdkVersion", 28)

// Used to override the NDK path/version on internal CI or by allowing
// users to customize the NDK path/version from their root project (e.g. for M1 support)
if (rootProject.hasProperty("ndkPath")) {
ndkPath rootProject.ext.ndkPath
}
if (rootProject.hasProperty("ndkVersion")) {
ndkVersion rootProject.ext.ndkVersion
}

defaultConfig {
minSdkVersion safeExtGet('minSdkVersion', 16)
targetSdkVersion safeExtGet('targetSdkVersion', 28)
versionCode 1
versionName "1.0"
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
if (isNewArchitectureEnabled()) {
var appProject = rootProject.allprojects.find {it.plugins.hasPlugin('com.android.application')}
externalNativeBuild {
cmake {
cppFlags "-O2 -frtti -fexceptions -Wall -Wno-unused-variable -fstack-protector-all"
arguments "-DAPP_BUILD_DIR=${appProject.buildDir}",
"-DREACT_NATIVE_DIR=${REACT_NATIVE_DIR}",
"-DANDROID_STL=c++_shared"
abiFilters (*reactNativeArchitectures())
}
}
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

if (isNewArchitectureEnabled()) {
externalNativeBuild {
cmake {
path "src/main/jni/CMakeLists.txt"
}
}
}

packagingOptions {
// For some reason gradle only complains about the duplicated version of libreact_render libraries
// while there are more libraries copied in intermediates folder of the lib build directory, we exclude
// only the ones that make the build fail (ideally we should only include libgesturehandler but we
// are only allowed to specify exclude patterns)
exclude "**/libreact_render*.so"
}

// Include "lib/" as sources, unfortunately react-native link can't handle
// setting up alternative gradle modules. We still have "lib" defined as a
// standalone gradle module just to be used in AndroidNativeExample
sourceSets.main {
java {
srcDirs += 'lib/src/main/java'

// Include "common/" only when it's not provided by Reanimated to mitigate
// multiple definitions of the same class preventing build
if (shouldUseCommonInterfaceFromReanimated()) {
srcDirs += 'reanimated/src/main/java'
} else {
srcDirs += 'common/src/main/java'
srcDirs += 'noreanimated/src/main/java'
}

if (isNewArchitectureEnabled()) {
srcDirs += 'src/fabric/java'
} else {
// this folder also includes files from codegen so the library can compile with
// codegen turned off
srcDirs += 'src/paper/java'
}
}
}
}

def kotlin_version = safeExtGet('kotlinVersion', project.properties['RNGH_kotlinVersion'])

dependencies {
//noinspection GradleDynamicVersion
if (isNewArchitectureEnabled()) {
implementation project(':ReactAndroid')
} else {
implementation 'com.facebook.react:react-native:+'
}

if (shouldUseCommonInterfaceFromReanimated()) {
// Include Reanimated as dependency to load the common interface
implementation (rootProject.subprojects.find { it.name == 'react-native-reanimated' }) {
exclude group:'com.facebook.fbjni' // resolves "Duplicate class com.facebook.jni.CppException"
}
}

implementation 'androidx.appcompat:appcompat:1.2.0'
implementation "androidx.core:core-ktx:1.6.0"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}

if (isNewArchitectureEnabled()) {
// Resolves "LOCAL_SRC_FILES points to a missing file, Check that libfb.so exists or that its path is correct".
tasks.whenTaskAdded { task ->
if (task.name.contains("configureCMakeDebug")) {
rootProject.getTasksByName("packageReactNdkDebugLibs", true).forEach {
task.dependsOn(it)
}
}
// We want to add a dependency for both configureCMakeRelease and configureCMakeRelWithDebInfo
if (task.name.contains("configureCMakeRel")) {
rootProject.getTasksByName("packageReactNdkReleaseLibs", true).forEach {
task.dependsOn(it)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package versioned.host.exp.exponent.modules.api.components.gesturehandler
package com.swmansion.common

interface GestureHandlerStateManager {
fun setGestureHandlerState(handlerTag: Int, newState: Int)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Project-wide Gradle settings.

# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.

# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
RNGH_kotlinVersion=1.6.21
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.swmansion.gesturehandler">
</manifest>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package versioned.host.exp.exponent.modules.api.components.gesturehandler
package com.swmansion.gesturehandler

import com.facebook.react.bridge.ReactContext
import com.facebook.react.modules.core.DeviceEventManagerModule
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package versioned.host.exp.exponent.modules.api.components.gesturehandler
package com.swmansion.gesturehandler

import android.os.Handler
import android.os.Looper
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package versioned.host.exp.exponent.modules.api.components.gesturehandler
import host.exp.expoview.BuildConfig
package com.swmansion.gesturehandler

import android.app.Activity
import android.content.Context
Expand All @@ -15,7 +14,7 @@ import com.facebook.react.bridge.Arguments
import com.facebook.react.bridge.UiThreadUtil
import com.facebook.react.bridge.WritableArray
import com.facebook.react.uimanager.PixelUtil
import versioned.host.exp.exponent.modules.api.components.gesturehandler.react.RNGestureHandlerTouchEvent
import com.swmansion.gesturehandler.react.RNGestureHandlerTouchEvent
import java.lang.IllegalStateException
import java.util.*

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package versioned.host.exp.exponent.modules.api.components.gesturehandler
package com.swmansion.gesturehandler

interface GestureHandlerInteractionController {
fun shouldWaitForHandlerFailure(handler: GestureHandler<*>, otherHandler: GestureHandler<*>): Boolean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package versioned.host.exp.exponent.modules.api.components.gesturehandler
package com.swmansion.gesturehandler

import android.graphics.Matrix
import android.graphics.PointF
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package versioned.host.exp.exponent.modules.api.components.gesturehandler
package com.swmansion.gesturehandler

import android.view.View
import java.util.*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package versioned.host.exp.exponent.modules.api.components.gesturehandler
package com.swmansion.gesturehandler

import android.view.MotionEvent

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package versioned.host.exp.exponent.modules.api.components.gesturehandler
package com.swmansion.gesturehandler

import android.content.Context
import android.os.Handler
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package versioned.host.exp.exponent.modules.api.components.gesturehandler
package com.swmansion.gesturehandler

import android.view.MotionEvent

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package versioned.host.exp.exponent.modules.api.components.gesturehandler
package com.swmansion.gesturehandler

import android.os.SystemClock
import android.view.MotionEvent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package versioned.host.exp.exponent.modules.api.components.gesturehandler
package com.swmansion.gesturehandler

import android.view.MotionEvent

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package versioned.host.exp.exponent.modules.api.components.gesturehandler
package com.swmansion.gesturehandler

import android.content.Context
import android.os.Handler
import android.os.Looper
import android.view.MotionEvent
import android.view.VelocityTracker
import android.view.ViewConfiguration
import versioned.host.exp.exponent.modules.api.components.gesturehandler.GestureUtils.getLastPointerX
import versioned.host.exp.exponent.modules.api.components.gesturehandler.GestureUtils.getLastPointerY
import com.swmansion.gesturehandler.GestureUtils.getLastPointerX
import com.swmansion.gesturehandler.GestureUtils.getLastPointerY

class PanGestureHandler(context: Context?) : GestureHandler<PanGestureHandler>() {
var velocityX = 0f
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package versioned.host.exp.exponent.modules.api.components.gesturehandler
package com.swmansion.gesturehandler

import android.graphics.PointF
import android.view.MotionEvent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package versioned.host.exp.exponent.modules.api.components.gesturehandler
package com.swmansion.gesturehandler

enum class PointerEventsConfig {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package versioned.host.exp.exponent.modules.api.components.gesturehandler
package com.swmansion.gesturehandler

import android.view.MotionEvent
import kotlin.math.atan2
Expand Down

0 comments on commit ef1d278

Please sign in to comment.