-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Migrated packages/react-native-reanimated java->kotlin #9163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -150,6 +150,11 @@ if (project == rootProject) { | |||
| apply plugin: "com.android.library" | ||||
| apply plugin: "maven-publish" | ||||
| apply plugin: "de.undercouch.download" | ||||
| apply plugin: 'org.jetbrains.kotlin.android' | ||||
|
|
||||
| if (project != rootProject) { | ||||
| apply plugin: "org.jetbrains.kotlin.android" | ||||
| } | ||||
|
|
||||
| android { | ||||
| compileSdkVersion safeExtGet("compileSdkVersion", 36) | ||||
|
|
@@ -242,6 +247,14 @@ android { | |||
| sourceCompatibility JavaVersion.VERSION_17 | ||||
| targetCompatibility JavaVersion.VERSION_17 | ||||
| } | ||||
| kotlinOptions { | ||||
| jvmTarget = '17' | ||||
| } | ||||
| if (project != rootProject) { | ||||
| kotlinOptions { | ||||
| jvmTarget = '17' | ||||
| } | ||||
| } | ||||
|
Comment on lines
+250
to
+257
|
||||
| tasks.withType(ExternalNativeBuildJsonTask).tap { | ||||
| configureEach { compileTask -> | ||||
| compileTask.doLast { | ||||
|
|
@@ -334,6 +347,8 @@ dependencies { | |||
| implementation "androidx.core:core:1.15.0" | ||||
|
|
||||
| implementation "com.facebook.react:react-android" // version substituted by RNGP | ||||
| implementation "androidx.core:core-ktx:1.17.0" | ||||
|
||||
| implementation "androidx.core:core-ktx:1.17.0" |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package com.swmansion.common | ||
|
|
||
| interface GestureHandlerStateManager { | ||
| fun setGestureHandlerState(handlerTag: Int, newState: Int) | ||
| } |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| package com.swmansion.reanimated | ||
|
|
||
| import com.facebook.react.bridge.WritableArray | ||
| import com.facebook.react.bridge.WritableMap | ||
| import com.facebook.react.uimanager.events.Event | ||
| import com.facebook.react.uimanager.events.RCTEventEmitter | ||
|
|
||
| class CopiedEvent(event: Event<*>) { | ||
| var targetTag: Int = 0 | ||
| private set | ||
|
|
||
| var eventName: String = "" | ||
| private set | ||
|
|
||
| var payload: WritableMap? = null | ||
| private set | ||
|
|
||
| init { | ||
| event.dispatch( | ||
| object : RCTEventEmitter { | ||
| override fun receiveEvent(targetTag: Int, eventName: String, event: WritableMap?) { | ||
| this@CopiedEvent.targetTag = targetTag | ||
| this@CopiedEvent.eventName = eventName | ||
| this@CopiedEvent.payload = event?.copy() | ||
| } | ||
|
|
||
| override fun receiveTouches( | ||
| eventName: String, | ||
| touches: WritableArray, | ||
| changedIndices: WritableArray | ||
| ) { | ||
| // noop | ||
| } | ||
| }) | ||
| } | ||
| } |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package com.swmansion.reanimated | ||
|
|
||
| import com.facebook.react.ReactApplication | ||
| import com.facebook.react.bridge.ReactApplicationContext | ||
| import com.facebook.react.devsupport.interfaces.DevOptionHandler | ||
|
|
||
| object DevMenuUtils { | ||
| @JvmStatic | ||
| fun addDevMenuOption(context: ReactApplicationContext, handler: DevOptionHandler) { | ||
| // In Expo, `ApplicationContext` is not an instance of `ReactApplication` | ||
| if (context.applicationContext is ReactApplication) { | ||
| val devSupportManager = | ||
| (context.applicationContext as ReactApplication).reactHost!!.devSupportManager | ||
|
|
||
| if (devSupportManager != null) { | ||
| devSupportManager.addCustomDevOption("Toggle slow animations (Reanimated)", handler) | ||
| } else { | ||
| throw RuntimeException("[Reanimated] DevSupportManager is not available") | ||
| } | ||
| } | ||
| } | ||
| } |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| package com.swmansion.reanimated | ||
|
|
||
| import android.os.Handler | ||
| import android.os.Looper | ||
| import android.view.View | ||
| import android.view.ViewTreeObserver | ||
| import com.facebook.react.bridge.ReactApplicationContext | ||
| import com.facebook.react.bridge.UiThreadUtil | ||
|
|
||
| /** Tracks whether the current UI thread turn is inside a draw pass. */ | ||
| internal class DrawPassDetector(private val mContext: ReactApplicationContext) { | ||
| private val mHandler = Handler(Looper.getMainLooper()) | ||
| private val mClearRunnable = Runnable { mIsInDrawPass = false } | ||
| private var mIsInDrawPass = false | ||
| private var mDecorView: View? = null | ||
|
|
||
| private val mOnDrawListener = ViewTreeObserver.OnDrawListener { | ||
| mIsInDrawPass = true | ||
| mHandler.postAtFrontOfQueue(mClearRunnable) | ||
| } | ||
|
|
||
| fun initialize() { | ||
| val activity = mContext.currentActivity ?: return | ||
|
|
||
| val decorView = activity.window.decorView | ||
| if (decorView === mDecorView) { | ||
| return | ||
| } | ||
|
|
||
| // Decor view has changed (e.g. Activity recreated) — detach from the old one first. | ||
| mDecorView?.let { oldView -> | ||
| val oldObserver = oldView.viewTreeObserver | ||
| if (oldObserver.isAlive) { | ||
| oldObserver.removeOnDrawListener(mOnDrawListener) | ||
| } | ||
| mDecorView = null | ||
| } | ||
|
|
||
| val observer = decorView.viewTreeObserver | ||
| if (!observer.isAlive) { | ||
| return | ||
| } | ||
|
|
||
| mDecorView = decorView | ||
| observer.addOnDrawListener(mOnDrawListener) | ||
| } | ||
|
|
||
| fun isInDrawPass(): Boolean = mIsInDrawPass | ||
|
|
||
| fun invalidate() { | ||
| if (UiThreadUtil.isOnUiThread()) { | ||
| invalidateOnUiThread() | ||
| } else { | ||
| mHandler.post { invalidateOnUiThread() } | ||
| } | ||
| } | ||
|
|
||
| private fun invalidateOnUiThread() { | ||
| mDecorView?.let { view -> | ||
| val observer = view.viewTreeObserver | ||
| if (observer.isAlive) { | ||
| observer.removeOnDrawListener(mOnDrawListener) | ||
| } | ||
| mDecorView = null | ||
| } | ||
| mHandler.removeCallbacks(mClearRunnable) | ||
| mIsInDrawPass = false | ||
| } | ||
| } |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package com.swmansion.reanimated | ||
|
|
||
| import com.facebook.react.bridge.JSApplicationCausedNativeException | ||
| import com.facebook.react.bridge.NoSuchKeyException | ||
| import com.facebook.react.bridge.ReadableMap | ||
|
|
||
| object MapUtils { | ||
| @JvmStatic | ||
| fun getInt(map: ReadableMap, name: String, errorMsg: String): Int { | ||
| try { | ||
| return map.getInt(name) | ||
| } catch (e: NoSuchKeyException) { | ||
| throw JSApplicationCausedNativeException(errorMsg) | ||
| } | ||
| } | ||
|
|
||
| @JvmStatic | ||
| fun getString(map: ReadableMap, name: String, errorMsg: String): String? { | ||
| try { | ||
| return map.getString(name) | ||
| } catch (e: NoSuchKeyException) { | ||
| throw JSApplicationCausedNativeException(errorMsg) | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
org.jetbrains.kotlin.androidis applied unconditionally and then applied again for non-root projects. This differs from the pattern used inreact-native-worklets(only applied whenproject != rootProject) and can cause redundant plugin application / configuration warnings. Consider applying the Kotlin Android plugin only once (likely inside theproject != rootProjectbranch).