@@ -5,22 +5,16 @@ import android.view.View
5
5
import android.view.ViewGroup
6
6
import android.view.ViewStructure
7
7
import android.view.accessibility.AccessibilityEvent
8
+ import com.facebook.react.bridge.Arguments
8
9
import com.facebook.react.bridge.LifecycleEventListener
9
10
import com.facebook.react.bridge.UiThreadUtil
11
+ import com.facebook.react.bridge.WritableMap
10
12
import com.facebook.react.uimanager.ThemedReactContext
11
13
import com.facebook.react.uimanager.UIManagerHelper
12
14
import com.facebook.react.uimanager.events.EventDispatcher
13
15
import com.google.android.material.bottomsheet.BottomSheetBehavior
14
16
import com.lodev09.truesheet.core.RootSheetView
15
17
import com.lodev09.truesheet.core.Utils
16
- import com.lodev09.truesheet.events.ContainerSizeChangeEvent
17
- import com.lodev09.truesheet.events.DismissEvent
18
- import com.lodev09.truesheet.events.DragBeginEvent
19
- import com.lodev09.truesheet.events.DragChangeEvent
20
- import com.lodev09.truesheet.events.DragEndEvent
21
- import com.lodev09.truesheet.events.MountEvent
22
- import com.lodev09.truesheet.events.PresentEvent
23
- import com.lodev09.truesheet.events.SizeChangeEvent
24
18
25
19
class TrueSheetView (context : Context ) :
26
20
ViewGroup (context),
@@ -78,7 +72,10 @@ class TrueSheetView(context: Context) :
78
72
// Configure Sheet Dialog
79
73
sheetDialog.apply {
80
74
setOnSizeChangeListener { w, h ->
81
- eventDispatcher?.dispatchEvent(ContainerSizeChangeEvent (surfaceId, id, Utils .toDIP(w.toFloat()), Utils .toDIP(h.toFloat())))
75
+ val data = Arguments .createMap()
76
+ data.putDouble(" width" , Utils .toDIP(w.toFloat()).toDouble())
77
+ data.putDouble(" height" , Utils .toDIP(h.toFloat()).toDouble())
78
+ dispatchEvent(TrueSheetEvent .CONTAINER_SIZE_CHANGE , data)
82
79
}
83
80
84
81
// Setup listener when the dialog has been presented.
@@ -100,7 +97,7 @@ class TrueSheetView(context: Context) :
100
97
}
101
98
102
99
// Dispatch onPresent event
103
- eventDispatcher?. dispatchEvent(PresentEvent (surfaceId, id, sheetDialog.getSizeInfoForIndex(currentSizeIndex)))
100
+ dispatchEvent(TrueSheetEvent . PRESENT , sizeInfoData( sheetDialog.getSizeInfoForIndex(currentSizeIndex)))
104
101
}
105
102
106
103
// Setup listener when the dialog has been dismissed.
@@ -114,7 +111,7 @@ class TrueSheetView(context: Context) :
114
111
}
115
112
116
113
// Dispatch onDismiss event
117
- eventDispatcher?. dispatchEvent(DismissEvent (surfaceId, id) )
114
+ dispatchEvent(TrueSheetEvent . DISMISS )
118
115
}
119
116
120
117
// Configure sheet behavior events
@@ -130,7 +127,7 @@ class TrueSheetView(context: Context) :
130
127
val sizeInfo = SizeInfo (currentSizeIndex, Utils .toDIP(height.toFloat()))
131
128
132
129
// Dispatch drag change event
133
- eventDispatcher?. dispatchEvent(DragChangeEvent (surfaceId, id, sizeInfo))
130
+ dispatchEvent(TrueSheetEvent . DRAG_CHANGE , sizeInfoData( sizeInfo))
134
131
}
135
132
136
133
else -> { }
@@ -159,7 +156,7 @@ class TrueSheetView(context: Context) :
159
156
// When changed to dragging, we know that the drag has started
160
157
BottomSheetBehavior .STATE_DRAGGING -> {
161
158
// Dispatch drag started event
162
- eventDispatcher?. dispatchEvent(DragBeginEvent (surfaceId, id, currentSizeInfo))
159
+ dispatchEvent(TrueSheetEvent . DRAG_BEGIN , sizeInfoData( currentSizeInfo))
163
160
164
161
// Flag sheet is being dragged
165
162
isDragging = true
@@ -176,7 +173,7 @@ class TrueSheetView(context: Context) :
176
173
val sizeInfo = getSizeInfoForState(newState)
177
174
sizeInfo?.let {
178
175
// Dispatch drag ended after dragging
179
- eventDispatcher?. dispatchEvent(DragEndEvent (surfaceId, id, it))
176
+ dispatchEvent(TrueSheetEvent . DRAG_END , sizeInfoData( it))
180
177
if (it.index != currentSizeIndex) {
181
178
// Invoke promise when sheet resized programmatically
182
179
presentPromise?.let { promise ->
@@ -188,7 +185,7 @@ class TrueSheetView(context: Context) :
188
185
setupDimmedBackground(it.index)
189
186
190
187
// Dispatch onSizeChange event
191
- eventDispatcher?. dispatchEvent(SizeChangeEvent (surfaceId, id, it))
188
+ dispatchEvent(TrueSheetEvent . SIZE_CHANGE , sizeInfoData( it))
192
189
}
193
190
}
194
191
@@ -248,7 +245,7 @@ class TrueSheetView(context: Context) :
248
245
}
249
246
250
247
// Dispatch onMount event
251
- eventDispatcher?. dispatchEvent(MountEvent (surfaceId, id) )
248
+ dispatchEvent(TrueSheetEvent . MOUNT )
252
249
}
253
250
}
254
251
}
@@ -295,6 +292,18 @@ class TrueSheetView(context: Context) :
295
292
sheetDialog.dismiss()
296
293
}
297
294
295
+ private fun sizeInfoData (sizeInfo : SizeInfo ): WritableMap {
296
+ val data = Arguments .createMap()
297
+ data.putInt(" index" , sizeInfo.index)
298
+ data.putDouble(" value" , sizeInfo.value.toDouble())
299
+
300
+ return data
301
+ }
302
+
303
+ private fun dispatchEvent (name : String , data : WritableMap ? = null) {
304
+ eventDispatcher?.dispatchEvent(TrueSheetEvent (surfaceId, id, name, data))
305
+ }
306
+
298
307
private fun configureIfShowing () {
299
308
if (sheetDialog.isShowing) {
300
309
sheetDialog.configure()
@@ -384,7 +393,7 @@ class TrueSheetView(context: Context) :
384
393
// For consistency with IOS, we are not waiting
385
394
// for the state to change before dispatching onSizeChange event.
386
395
val sizeInfo = sheetDialog.getSizeInfoForIndex(sizeIndex)
387
- eventDispatcher?. dispatchEvent(SizeChangeEvent (surfaceId, id, sizeInfo))
396
+ dispatchEvent(TrueSheetEvent . SIZE_CHANGE , sizeInfoData( sizeInfo))
388
397
389
398
promiseCallback()
390
399
} else {
0 commit comments