11package com.ease
22
3+ import com.facebook.react.bridge.Arguments
4+ import com.facebook.react.bridge.ReadableArray
5+ import com.facebook.react.bridge.WritableMap
6+ import com.facebook.react.common.MapBuilder
37import com.facebook.react.module.annotations.ReactModule
8+ import com.facebook.react.uimanager.PixelUtil
49import com.facebook.react.uimanager.ThemedReactContext
10+ import com.facebook.react.uimanager.UIManagerHelper
511import com.facebook.react.uimanager.annotations.ReactProp
12+ import com.facebook.react.uimanager.events.Event
613import com.facebook.react.views.view.ReactViewGroup
714import com.facebook.react.views.view.ReactViewManager
815
@@ -11,8 +18,17 @@ class EaseViewManager : ReactViewManager() {
1118
1219 override fun getName (): String = NAME
1320
14- override fun createViewInstance (context : ThemedReactContext ): EaseView =
15- EaseView (context)
21+ override fun createViewInstance (context : ThemedReactContext ): EaseView {
22+ val view = EaseView (context)
23+ view.onTransitionEnd = { property, finished ->
24+ val eventDispatcher = UIManagerHelper .getEventDispatcherForReactTag(context, view.id)
25+ val surfaceId = UIManagerHelper .getSurfaceId(context)
26+ eventDispatcher?.dispatchEvent(
27+ TransitionEndEvent (surfaceId, view.id, property, finished)
28+ )
29+ }
30+ return view
31+ }
1632
1733 // --- Animate value setters ---
1834
@@ -23,12 +39,12 @@ class EaseViewManager : ReactViewManager() {
2339
2440 @ReactProp(name = " animateTranslateX" , defaultFloat = 0f )
2541 fun setAnimateTranslateX (view : EaseView , value : Float ) {
26- view.pendingTranslateX = value
42+ view.pendingTranslateX = PixelUtil .toPixelFromDIP( value)
2743 }
2844
2945 @ReactProp(name = " animateTranslateY" , defaultFloat = 0f )
3046 fun setAnimateTranslateY (view : EaseView , value : Float ) {
31- view.pendingTranslateY = value
47+ view.pendingTranslateY = PixelUtil .toPixelFromDIP( value)
3248 }
3349
3450 @ReactProp(name = " animateScale" , defaultFloat = 1f )
@@ -50,12 +66,12 @@ class EaseViewManager : ReactViewManager() {
5066
5167 @ReactProp(name = " initialAnimateTranslateX" , defaultFloat = 0f )
5268 fun setInitialAnimateTranslateX (view : EaseView , value : Float ) {
53- view.initialAnimateTranslateX = value
69+ view.initialAnimateTranslateX = PixelUtil .toPixelFromDIP( value)
5470 }
5571
5672 @ReactProp(name = " initialAnimateTranslateY" , defaultFloat = 0f )
5773 fun setInitialAnimateTranslateY (view : EaseView , value : Float ) {
58- view.initialAnimateTranslateY = value
74+ view.initialAnimateTranslateY = PixelUtil .toPixelFromDIP( value)
5975 }
6076
6177 @ReactProp(name = " initialAnimateScale" , defaultFloat = 1f )
@@ -112,6 +128,20 @@ class EaseViewManager : ReactViewManager() {
112128 view.useHardwareLayer = value
113129 }
114130
131+ // --- Prevent BaseViewManager from resetting animated properties ---
132+
133+ override fun setTransformProperty (
134+ view : ReactViewGroup ,
135+ transforms : ReadableArray ? ,
136+ transformOrigin : ReadableArray ?
137+ ) {
138+ // No-op: we manage translationX/Y, scaleX/Y, rotation ourselves via animations.
139+ }
140+
141+ override fun setOpacity (view : ReactViewGroup , opacity : Float ) {
142+ // No-op: we manage opacity ourselves via animations.
143+ }
144+
115145 // --- Lifecycle ---
116146
117147 override fun onAfterUpdateTransaction (view : ReactViewGroup ) {
@@ -124,6 +154,25 @@ class EaseViewManager : ReactViewManager() {
124154 (view as ? EaseView )?.cleanup()
125155 }
126156
157+ override fun getExportedCustomDirectEventTypeConstants (): Map <String , Any >? {
158+ return MapBuilder .builder<String , Any >()
159+ .put(" onTransitionEnd" , MapBuilder .of(" registrationName" , " onTransitionEnd" ))
160+ .build()
161+ }
162+
163+ private class TransitionEndEvent (
164+ surfaceId : Int ,
165+ viewId : Int ,
166+ private val property : String ,
167+ private val finished : Boolean
168+ ) : Event<TransitionEndEvent>(surfaceId, viewId) {
169+ override fun getEventName () = " onTransitionEnd"
170+ override fun getEventData (): WritableMap = Arguments .createMap().apply {
171+ putString(" property" , property)
172+ putBoolean(" finished" , finished)
173+ }
174+ }
175+
127176 companion object {
128177 const val NAME = " EaseView"
129178 }
0 commit comments