@lodev09/react-native-true-sheet 0.11.3 → 0.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetDialog.kt +26 -15
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetView.kt +56 -16
- package/android/src/main/java/com/lodev09/truesheet/TrueSheetViewManager.kt +26 -3
- package/android/src/main/java/com/lodev09/truesheet/core/KeyboardManager.kt +2 -2
- package/android/src/main/java/com/lodev09/truesheet/core/RootSheetView.kt +26 -15
- package/android/src/main/java/com/lodev09/truesheet/events/DismissEvent.kt +16 -0
- package/android/src/main/java/com/lodev09/truesheet/events/MountEvent.kt +16 -0
- package/android/src/main/java/com/lodev09/truesheet/events/PresentEvent.kt +23 -0
- package/android/src/main/java/com/lodev09/truesheet/events/SizeChangeEvent.kt +23 -0
- package/ios/TrueSheetView.swift +71 -19
- package/ios/TrueSheetViewManager.m +3 -0
- package/lib/commonjs/TrueSheet.js +12 -0
- package/lib/commonjs/TrueSheet.js.map +1 -1
- package/lib/commonjs/{types.js → TrueSheet.types.js} +1 -1
- package/lib/commonjs/TrueSheet.types.js.map +1 -0
- package/lib/commonjs/index.js +8 -8
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/TrueSheet.js +12 -0
- package/lib/module/TrueSheet.js.map +1 -1
- package/lib/module/TrueSheet.types.js +2 -0
- package/lib/module/TrueSheet.types.js.map +1 -0
- package/lib/module/index.js +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/TrueSheet.d.ts +2 -1
- package/lib/typescript/src/TrueSheet.d.ts.map +1 -1
- package/lib/typescript/src/{types.d.ts → TrueSheet.types.d.ts} +27 -1
- package/lib/typescript/src/TrueSheet.types.d.ts.map +1 -0
- package/lib/typescript/src/TrueSheetFooter.d.ts +1 -1
- package/lib/typescript/src/TrueSheetFooter.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +1 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/TrueSheet.tsx +14 -1
- package/src/{types.ts → TrueSheet.types.ts} +30 -0
- package/src/TrueSheetFooter.tsx +1 -1
- package/src/index.ts +1 -1
- package/android/src/main/java/com/lodev09/truesheet/core/Events.kt +0 -51
- package/lib/commonjs/types.js.map +0 -1
- package/lib/module/types.js +0 -2
- package/lib/module/types.js.map +0 -1
- package/lib/typescript/src/types.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
The true native bottom sheet experience for your React Native Apps. 💩
|
|
8
8
|
|
|
9
|
-
<img alt="React Native True Sheet" src="docs/static/img/preview.gif" width="
|
|
9
|
+
<img alt="React Native True Sheet - IOS" src="docs/static/img/preview.gif" width="300" height="600" /><img alt="React Native True Sheet - Android" src="docs/static/img/preview-2.gif" width="300" height="600" />
|
|
10
10
|
|
|
11
11
|
## Features
|
|
12
12
|
|
|
@@ -19,6 +19,8 @@ class TrueSheetDialog(private val reactContext: ThemedReactContext, private val
|
|
|
19
19
|
BottomSheetDialog(reactContext) {
|
|
20
20
|
|
|
21
21
|
private var keyboardManager = KeyboardManager(reactContext)
|
|
22
|
+
private var sheetView: ViewGroup
|
|
23
|
+
private var windowAnimation: Int = 0
|
|
22
24
|
|
|
23
25
|
/**
|
|
24
26
|
* Specify whether the sheet background is dimmed.
|
|
@@ -53,19 +55,15 @@ class TrueSheetDialog(private val reactContext: ThemedReactContext, private val
|
|
|
53
55
|
|
|
54
56
|
var sizes: Array<Any> = arrayOf("medium", "large")
|
|
55
57
|
|
|
56
|
-
private var sheetView: ViewGroup
|
|
57
|
-
|
|
58
58
|
init {
|
|
59
59
|
setContentView(rootSheetView)
|
|
60
60
|
sheetView = rootSheetView.parent as ViewGroup
|
|
61
61
|
sheetView.setBackgroundColor(Color.TRANSPARENT)
|
|
62
62
|
|
|
63
|
-
// Setup window params to adjust layout based on Keyboard state
|
|
63
|
+
// Setup window params to adjust layout based on Keyboard state
|
|
64
64
|
window?.apply {
|
|
65
|
-
//
|
|
66
|
-
|
|
67
|
-
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
|
|
68
|
-
)
|
|
65
|
+
// Store current windowAnimation value to toggle later
|
|
66
|
+
windowAnimation = attributes.windowAnimations
|
|
69
67
|
}
|
|
70
68
|
|
|
71
69
|
// Update the usable sheet height
|
|
@@ -107,10 +105,16 @@ class TrueSheetDialog(private val reactContext: ThemedReactContext, private val
|
|
|
107
105
|
}
|
|
108
106
|
}
|
|
109
107
|
|
|
108
|
+
fun resetAnimation() {
|
|
109
|
+
window?.apply {
|
|
110
|
+
setWindowAnimations(windowAnimation)
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
110
114
|
/**
|
|
111
115
|
* Present the sheet.
|
|
112
116
|
*/
|
|
113
|
-
fun present(sizeIndex: Int) {
|
|
117
|
+
fun present(sizeIndex: Int, animated: Boolean = true) {
|
|
114
118
|
setupDimmedBackground(sizeIndex)
|
|
115
119
|
if (isShowing) {
|
|
116
120
|
setStateForSizeIndex(sizeIndex)
|
|
@@ -118,7 +122,12 @@ class TrueSheetDialog(private val reactContext: ThemedReactContext, private val
|
|
|
118
122
|
configure()
|
|
119
123
|
setStateForSizeIndex(sizeIndex)
|
|
120
124
|
|
|
121
|
-
|
|
125
|
+
if (!animated) {
|
|
126
|
+
// Disable animation
|
|
127
|
+
window?.setWindowAnimations(0)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
show()
|
|
122
131
|
}
|
|
123
132
|
}
|
|
124
133
|
|
|
@@ -178,10 +187,7 @@ class TrueSheetDialog(private val reactContext: ThemedReactContext, private val
|
|
|
178
187
|
else -> (maxScreenHeight * 0.5).toInt()
|
|
179
188
|
}
|
|
180
189
|
|
|
181
|
-
return
|
|
182
|
-
null -> height
|
|
183
|
-
else -> minOf(height, maxSheetHeight ?: maxScreenHeight)
|
|
184
|
-
}
|
|
190
|
+
return maxSheetHeight?.let { minOf(height, it, maxScreenHeight) } ?: minOf(height, maxScreenHeight)
|
|
185
191
|
}
|
|
186
192
|
|
|
187
193
|
/**
|
|
@@ -216,7 +222,7 @@ class TrueSheetDialog(private val reactContext: ThemedReactContext, private val
|
|
|
216
222
|
* Also update footer's Y position.
|
|
217
223
|
*/
|
|
218
224
|
fun registerKeyboardManager() {
|
|
219
|
-
keyboardManager.registerKeyboardListener(object : KeyboardManager.
|
|
225
|
+
keyboardManager.registerKeyboardListener(object : KeyboardManager.OnKeyboardChangeListener {
|
|
220
226
|
override fun onKeyboardStateChange(isVisible: Boolean, visibleHeight: Int?) {
|
|
221
227
|
maxScreenHeight = when (isVisible) {
|
|
222
228
|
true -> visibleHeight ?: 0
|
|
@@ -228,6 +234,10 @@ class TrueSheetDialog(private val reactContext: ThemedReactContext, private val
|
|
|
228
234
|
})
|
|
229
235
|
}
|
|
230
236
|
|
|
237
|
+
fun setOnSizeChangeListener(listener: RootSheetView.OnSizeChangeListener) {
|
|
238
|
+
rootSheetView.setOnSizeChangeListener(listener)
|
|
239
|
+
}
|
|
240
|
+
|
|
231
241
|
/**
|
|
232
242
|
* Remove keyboard listener.
|
|
233
243
|
*/
|
|
@@ -263,7 +273,8 @@ class TrueSheetDialog(private val reactContext: ThemedReactContext, private val
|
|
|
263
273
|
isFitToContents = false
|
|
264
274
|
|
|
265
275
|
setPeekHeight(getSizeHeight(sizes[0]), isShowing)
|
|
266
|
-
|
|
276
|
+
|
|
277
|
+
halfExpandedRatio = minOf(getSizeHeight(sizes[1]).toFloat() / maxScreenHeight.toFloat(), 1.0f)
|
|
267
278
|
maxHeight = getSizeHeight(sizes[2])
|
|
268
279
|
}
|
|
269
280
|
}
|
|
@@ -11,10 +11,11 @@ import com.facebook.react.uimanager.ThemedReactContext
|
|
|
11
11
|
import com.facebook.react.uimanager.UIManagerHelper
|
|
12
12
|
import com.facebook.react.uimanager.events.EventDispatcher
|
|
13
13
|
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
|
14
|
-
import com.lodev09.truesheet.core.DismissEvent
|
|
15
|
-
import com.lodev09.truesheet.core.PresentEvent
|
|
16
14
|
import com.lodev09.truesheet.core.RootSheetView
|
|
17
|
-
import com.lodev09.truesheet.
|
|
15
|
+
import com.lodev09.truesheet.events.DismissEvent
|
|
16
|
+
import com.lodev09.truesheet.events.MountEvent
|
|
17
|
+
import com.lodev09.truesheet.events.PresentEvent
|
|
18
|
+
import com.lodev09.truesheet.events.SizeChangeEvent
|
|
18
19
|
|
|
19
20
|
class TrueSheetView(context: Context) :
|
|
20
21
|
ViewGroup(context),
|
|
@@ -27,6 +28,9 @@ class TrueSheetView(context: Context) :
|
|
|
27
28
|
private val surfaceId: Int
|
|
28
29
|
get() = UIManagerHelper.getSurfaceId(this)
|
|
29
30
|
|
|
31
|
+
var initialIndex: Int = -1
|
|
32
|
+
var initialIndexAnimated: Boolean = true
|
|
33
|
+
|
|
30
34
|
/**
|
|
31
35
|
* Current activeIndex.
|
|
32
36
|
*/
|
|
@@ -52,11 +56,6 @@ class TrueSheetView(context: Context) :
|
|
|
52
56
|
*/
|
|
53
57
|
private val rootSheetView: RootSheetView
|
|
54
58
|
|
|
55
|
-
/**
|
|
56
|
-
* 2nd child of the container view.
|
|
57
|
-
*/
|
|
58
|
-
private var footerView: ViewGroup? = null
|
|
59
|
-
|
|
60
59
|
init {
|
|
61
60
|
reactContext.addLifecycleEventListener(this)
|
|
62
61
|
eventDispatcher = UIManagerHelper.getEventDispatcherForReactTag(reactContext, id)
|
|
@@ -77,13 +76,16 @@ class TrueSheetView(context: Context) :
|
|
|
77
76
|
positionFooter()
|
|
78
77
|
}
|
|
79
78
|
|
|
79
|
+
// Re-enable animation
|
|
80
|
+
resetAnimation()
|
|
81
|
+
|
|
80
82
|
// Resolve the present promise
|
|
81
83
|
presentPromise?.let { promise ->
|
|
82
84
|
promise()
|
|
83
85
|
presentPromise = null
|
|
84
86
|
}
|
|
85
87
|
|
|
86
|
-
//
|
|
88
|
+
// Dispatch onPresent event
|
|
87
89
|
eventDispatcher?.dispatchEvent(PresentEvent(surfaceId, id, sheetDialog.getSizeInfoForIndex(currentSizeIndex)))
|
|
88
90
|
}
|
|
89
91
|
|
|
@@ -97,10 +99,17 @@ class TrueSheetView(context: Context) :
|
|
|
97
99
|
dismissPromise = null
|
|
98
100
|
}
|
|
99
101
|
|
|
100
|
-
//
|
|
102
|
+
// Dispatch onDismiss event
|
|
101
103
|
eventDispatcher?.dispatchEvent(DismissEvent(surfaceId, id))
|
|
102
104
|
}
|
|
103
105
|
|
|
106
|
+
// Configure when showing and size changed
|
|
107
|
+
setOnSizeChangeListener(object : RootSheetView.OnSizeChangeListener {
|
|
108
|
+
override fun onSizeChange(width: Int, height: Int) {
|
|
109
|
+
maxScreenHeight = height
|
|
110
|
+
}
|
|
111
|
+
})
|
|
112
|
+
|
|
104
113
|
// Configure sheet behavior events
|
|
105
114
|
behavior.addBottomSheetCallback(
|
|
106
115
|
object : BottomSheetBehavior.BottomSheetCallback() {
|
|
@@ -132,7 +141,7 @@ class TrueSheetView(context: Context) :
|
|
|
132
141
|
currentSizeIndex = sizeInfo.index
|
|
133
142
|
setupDimmedBackground(sizeInfo.index)
|
|
134
143
|
|
|
135
|
-
//
|
|
144
|
+
// Dispatch onSizeChange event
|
|
136
145
|
eventDispatcher?.dispatchEvent(SizeChangeEvent(surfaceId, id, sizeInfo))
|
|
137
146
|
}
|
|
138
147
|
}
|
|
@@ -164,13 +173,28 @@ class TrueSheetView(context: Context) :
|
|
|
164
173
|
visibility = GONE
|
|
165
174
|
|
|
166
175
|
(child as ViewGroup).let {
|
|
167
|
-
// Container View's first child is the Content View
|
|
168
|
-
footerView = it.getChildAt(1) as ViewGroup
|
|
169
|
-
|
|
170
|
-
sheetDialog.footerView = footerView
|
|
171
|
-
|
|
172
176
|
// rootView's first child is the Container View
|
|
173
177
|
rootSheetView.addView(it, index)
|
|
178
|
+
|
|
179
|
+
// Initialize content
|
|
180
|
+
UiThreadUtil.runOnUiThread {
|
|
181
|
+
// 1st child is the content view
|
|
182
|
+
val contentView = it.getChildAt(0) as ViewGroup
|
|
183
|
+
setContentHeight(contentView.height)
|
|
184
|
+
|
|
185
|
+
// 2nd child is the footer view
|
|
186
|
+
val footerView = it.getChildAt(1) as ViewGroup
|
|
187
|
+
sheetDialog.footerView = footerView
|
|
188
|
+
setFooterHeight(footerView.height)
|
|
189
|
+
|
|
190
|
+
if (initialIndex >= 0) {
|
|
191
|
+
currentSizeIndex = initialIndex
|
|
192
|
+
sheetDialog.present(initialIndex, initialIndexAnimated)
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// Dispatch onMount event
|
|
196
|
+
eventDispatcher?.dispatchEvent(MountEvent(surfaceId, id))
|
|
197
|
+
}
|
|
174
198
|
}
|
|
175
199
|
}
|
|
176
200
|
|
|
@@ -224,21 +248,29 @@ class TrueSheetView(context: Context) :
|
|
|
224
248
|
}
|
|
225
249
|
|
|
226
250
|
fun setMaxHeight(height: Int) {
|
|
251
|
+
if (sheetDialog.maxSheetHeight == height) return
|
|
252
|
+
|
|
227
253
|
sheetDialog.maxSheetHeight = height
|
|
228
254
|
configureIfShowing()
|
|
229
255
|
}
|
|
230
256
|
|
|
231
257
|
fun setContentHeight(height: Int) {
|
|
258
|
+
if (sheetDialog.contentHeight == height) return
|
|
259
|
+
|
|
232
260
|
sheetDialog.contentHeight = height
|
|
233
261
|
configureIfShowing()
|
|
234
262
|
}
|
|
235
263
|
|
|
236
264
|
fun setFooterHeight(height: Int) {
|
|
265
|
+
if (sheetDialog.footerHeight == height) return
|
|
266
|
+
|
|
237
267
|
sheetDialog.footerHeight = height
|
|
238
268
|
configureIfShowing()
|
|
239
269
|
}
|
|
240
270
|
|
|
241
271
|
fun setDimmed(dimmed: Boolean) {
|
|
272
|
+
if (sheetDialog.dimmed == dimmed) return
|
|
273
|
+
|
|
242
274
|
sheetDialog.dimmed = dimmed
|
|
243
275
|
if (sheetDialog.isShowing) {
|
|
244
276
|
sheetDialog.setupDimmedBackground(currentSizeIndex)
|
|
@@ -246,12 +278,20 @@ class TrueSheetView(context: Context) :
|
|
|
246
278
|
}
|
|
247
279
|
|
|
248
280
|
fun setDimmedIndex(index: Int) {
|
|
281
|
+
if (sheetDialog.dimmedIndex == index) return
|
|
282
|
+
|
|
249
283
|
sheetDialog.dimmedIndex = index
|
|
250
284
|
if (sheetDialog.isShowing) {
|
|
251
285
|
sheetDialog.setupDimmedBackground(currentSizeIndex)
|
|
252
286
|
}
|
|
253
287
|
}
|
|
254
288
|
|
|
289
|
+
fun setSoftInputMode(mode: Int) {
|
|
290
|
+
sheetDialog.window?.apply {
|
|
291
|
+
this.setSoftInputMode(mode)
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
255
295
|
fun setDismissible(dismissible: Boolean) {
|
|
256
296
|
sheetDialog.dismissible = dismissible
|
|
257
297
|
}
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
package com.lodev09.truesheet
|
|
2
2
|
|
|
3
3
|
import android.util.Log
|
|
4
|
+
import android.view.WindowManager
|
|
4
5
|
import com.facebook.react.bridge.ReadableArray
|
|
5
6
|
import com.facebook.react.bridge.ReadableType
|
|
6
7
|
import com.facebook.react.common.MapBuilder
|
|
7
8
|
import com.facebook.react.uimanager.ThemedReactContext
|
|
8
9
|
import com.facebook.react.uimanager.ViewGroupManager
|
|
9
10
|
import com.facebook.react.uimanager.annotations.ReactProp
|
|
10
|
-
import com.lodev09.truesheet.core.DismissEvent
|
|
11
|
-
import com.lodev09.truesheet.core.PresentEvent
|
|
12
|
-
import com.lodev09.truesheet.core.SizeChangeEvent
|
|
13
11
|
import com.lodev09.truesheet.core.Utils
|
|
12
|
+
import com.lodev09.truesheet.events.DismissEvent
|
|
13
|
+
import com.lodev09.truesheet.events.MountEvent
|
|
14
|
+
import com.lodev09.truesheet.events.PresentEvent
|
|
15
|
+
import com.lodev09.truesheet.events.SizeChangeEvent
|
|
14
16
|
|
|
15
17
|
class TrueSheetViewManager : ViewGroupManager<TrueSheetView>() {
|
|
16
18
|
override fun getName() = TAG
|
|
@@ -24,6 +26,7 @@ class TrueSheetViewManager : ViewGroupManager<TrueSheetView>() {
|
|
|
24
26
|
|
|
25
27
|
override fun getExportedCustomDirectEventTypeConstants(): MutableMap<String, Any>? =
|
|
26
28
|
MapBuilder.builder<String, Any>()
|
|
29
|
+
.put(MountEvent.EVENT_NAME, MapBuilder.of("registrationName", "onMount"))
|
|
27
30
|
.put(PresentEvent.EVENT_NAME, MapBuilder.of("registrationName", "onPresent"))
|
|
28
31
|
.put(DismissEvent.EVENT_NAME, MapBuilder.of("registrationName", "onDismiss"))
|
|
29
32
|
.put(SizeChangeEvent.EVENT_NAME, MapBuilder.of("registrationName", "onSizeChange"))
|
|
@@ -44,6 +47,26 @@ class TrueSheetViewManager : ViewGroupManager<TrueSheetView>() {
|
|
|
44
47
|
view.setDimmed(dimmed)
|
|
45
48
|
}
|
|
46
49
|
|
|
50
|
+
@ReactProp(name = "initialIndex")
|
|
51
|
+
fun setInitialIndex(view: TrueSheetView, index: Int) {
|
|
52
|
+
view.initialIndex = index
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
@ReactProp(name = "initialIndexAnimated")
|
|
56
|
+
fun setInitialIndexAnimated(view: TrueSheetView, animate: Boolean) {
|
|
57
|
+
view.initialIndexAnimated = animate
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
@ReactProp(name = "keyboardMode")
|
|
61
|
+
fun setKeyboardMode(view: TrueSheetView, mode: String) {
|
|
62
|
+
val softInputMode = when (mode) {
|
|
63
|
+
"pan" -> WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN
|
|
64
|
+
else -> WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
view.setSoftInputMode(softInputMode)
|
|
68
|
+
}
|
|
69
|
+
|
|
47
70
|
@ReactProp(name = "dimmedIndex")
|
|
48
71
|
fun setDimmedIndex(view: TrueSheetView, index: Int) {
|
|
49
72
|
view.setDimmedIndex(index)
|
|
@@ -7,7 +7,7 @@ import android.view.inputmethod.InputMethodManager
|
|
|
7
7
|
import com.facebook.react.bridge.ReactContext
|
|
8
8
|
|
|
9
9
|
class KeyboardManager(reactContext: ReactContext) {
|
|
10
|
-
interface
|
|
10
|
+
interface OnKeyboardChangeListener {
|
|
11
11
|
fun onKeyboardStateChange(isVisible: Boolean, visibleHeight: Int?)
|
|
12
12
|
}
|
|
13
13
|
|
|
@@ -20,7 +20,7 @@ class KeyboardManager(reactContext: ReactContext) {
|
|
|
20
20
|
contentView = activity?.findViewById(android.R.id.content)
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
fun registerKeyboardListener(listener:
|
|
23
|
+
fun registerKeyboardListener(listener: OnKeyboardChangeListener?) {
|
|
24
24
|
contentView?.apply {
|
|
25
25
|
unregisterKeyboardListener()
|
|
26
26
|
|
|
@@ -26,21 +26,26 @@ import com.facebook.react.views.view.ReactViewGroup
|
|
|
26
26
|
* styleHeight on the LayoutShadowNode to be the window size. This is done through the
|
|
27
27
|
* UIManagerModule, and will then cause the children to layout as if they can fill the window.
|
|
28
28
|
*/
|
|
29
|
-
class RootSheetView(context: Context?) :
|
|
29
|
+
class RootSheetView(private val context: Context?) :
|
|
30
30
|
ReactViewGroup(context),
|
|
31
31
|
RootView {
|
|
32
32
|
private var hasAdjustedSize = false
|
|
33
33
|
private var viewWidth = 0
|
|
34
34
|
private var viewHeight = 0
|
|
35
35
|
|
|
36
|
-
private val
|
|
37
|
-
private var
|
|
36
|
+
private val jSTouchDispatcher = JSTouchDispatcher(this)
|
|
37
|
+
private var jSPointerDispatcher: JSPointerDispatcher? = null
|
|
38
|
+
private var sizeChangeListener: OnSizeChangeListener? = null
|
|
38
39
|
|
|
39
40
|
var eventDispatcher: EventDispatcher? = null
|
|
40
41
|
|
|
42
|
+
interface OnSizeChangeListener {
|
|
43
|
+
fun onSizeChange(width: Int, height: Int)
|
|
44
|
+
}
|
|
45
|
+
|
|
41
46
|
init {
|
|
42
47
|
if (ReactFeatureFlags.dispatchPointerEvents) {
|
|
43
|
-
|
|
48
|
+
jSPointerDispatcher = JSPointerDispatcher(this)
|
|
44
49
|
}
|
|
45
50
|
}
|
|
46
51
|
|
|
@@ -50,6 +55,12 @@ class RootSheetView(context: Context?) :
|
|
|
50
55
|
viewWidth = w
|
|
51
56
|
viewHeight = h
|
|
52
57
|
updateFirstChildView()
|
|
58
|
+
|
|
59
|
+
sizeChangeListener?.onSizeChange(w, h)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
fun setOnSizeChangeListener(listener: OnSizeChangeListener) {
|
|
63
|
+
sizeChangeListener = listener
|
|
53
64
|
}
|
|
54
65
|
|
|
55
66
|
private fun updateFirstChildView() {
|
|
@@ -88,15 +99,15 @@ class RootSheetView(context: Context?) :
|
|
|
88
99
|
get() = context as ThemedReactContext
|
|
89
100
|
|
|
90
101
|
override fun onInterceptTouchEvent(event: MotionEvent): Boolean {
|
|
91
|
-
|
|
92
|
-
|
|
102
|
+
jSTouchDispatcher.handleTouchEvent(event, eventDispatcher)
|
|
103
|
+
jSPointerDispatcher?.handleMotionEvent(event, eventDispatcher, true)
|
|
93
104
|
return super.onInterceptTouchEvent(event)
|
|
94
105
|
}
|
|
95
106
|
|
|
96
107
|
@SuppressLint("ClickableViewAccessibility")
|
|
97
108
|
override fun onTouchEvent(event: MotionEvent): Boolean {
|
|
98
|
-
|
|
99
|
-
|
|
109
|
+
jSTouchDispatcher.handleTouchEvent(event, eventDispatcher)
|
|
110
|
+
jSPointerDispatcher?.handleMotionEvent(event, eventDispatcher, false)
|
|
100
111
|
super.onTouchEvent(event)
|
|
101
112
|
|
|
102
113
|
// In case when there is no children interested in handling touch event, we return true from
|
|
@@ -105,28 +116,28 @@ class RootSheetView(context: Context?) :
|
|
|
105
116
|
}
|
|
106
117
|
|
|
107
118
|
override fun onInterceptHoverEvent(event: MotionEvent): Boolean {
|
|
108
|
-
|
|
119
|
+
jSPointerDispatcher?.handleMotionEvent(event, eventDispatcher, true)
|
|
109
120
|
return super.onHoverEvent(event)
|
|
110
121
|
}
|
|
111
122
|
|
|
112
123
|
override fun onHoverEvent(event: MotionEvent): Boolean {
|
|
113
|
-
|
|
124
|
+
jSPointerDispatcher?.handleMotionEvent(event, eventDispatcher, false)
|
|
114
125
|
return super.onHoverEvent(event)
|
|
115
126
|
}
|
|
116
127
|
|
|
117
128
|
@Deprecated("Deprecated in Java")
|
|
118
129
|
override fun onChildStartedNativeGesture(ev: MotionEvent?) {
|
|
119
|
-
|
|
130
|
+
jSTouchDispatcher.onChildStartedNativeGesture(ev, eventDispatcher)
|
|
120
131
|
}
|
|
121
132
|
|
|
122
133
|
override fun onChildStartedNativeGesture(childView: View, ev: MotionEvent) {
|
|
123
|
-
|
|
124
|
-
|
|
134
|
+
jSTouchDispatcher.onChildStartedNativeGesture(ev, eventDispatcher)
|
|
135
|
+
jSPointerDispatcher?.onChildStartedNativeGesture(childView, ev, eventDispatcher)
|
|
125
136
|
}
|
|
126
137
|
|
|
127
138
|
override fun onChildEndedNativeGesture(childView: View, ev: MotionEvent) {
|
|
128
|
-
|
|
129
|
-
|
|
139
|
+
jSTouchDispatcher.onChildEndedNativeGesture(ev, eventDispatcher)
|
|
140
|
+
jSPointerDispatcher?.onChildEndedNativeGesture()
|
|
130
141
|
}
|
|
131
142
|
|
|
132
143
|
override fun requestDisallowInterceptTouchEvent(disallowIntercept: Boolean) {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
package com.lodev09.truesheet.events
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.Arguments
|
|
4
|
+
import com.facebook.react.bridge.WritableMap
|
|
5
|
+
import com.facebook.react.uimanager.events.Event
|
|
6
|
+
|
|
7
|
+
// onDismiss
|
|
8
|
+
class DismissEvent(surfaceId: Int, viewId: Int) : Event<DismissEvent>(surfaceId, viewId) {
|
|
9
|
+
override fun getEventName() = EVENT_NAME
|
|
10
|
+
|
|
11
|
+
override fun getEventData(): WritableMap = Arguments.createMap()
|
|
12
|
+
|
|
13
|
+
companion object {
|
|
14
|
+
const val EVENT_NAME = "dismiss"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
package com.lodev09.truesheet.events
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.Arguments
|
|
4
|
+
import com.facebook.react.bridge.WritableMap
|
|
5
|
+
import com.facebook.react.uimanager.events.Event
|
|
6
|
+
|
|
7
|
+
// onMount
|
|
8
|
+
class MountEvent(surfaceId: Int, viewId: Int) : Event<MountEvent>(surfaceId, viewId) {
|
|
9
|
+
override fun getEventName() = EVENT_NAME
|
|
10
|
+
|
|
11
|
+
override fun getEventData(): WritableMap = Arguments.createMap()
|
|
12
|
+
|
|
13
|
+
companion object {
|
|
14
|
+
const val EVENT_NAME = "ready"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
package com.lodev09.truesheet.events
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.Arguments
|
|
4
|
+
import com.facebook.react.bridge.WritableMap
|
|
5
|
+
import com.facebook.react.uimanager.events.Event
|
|
6
|
+
import com.lodev09.truesheet.SizeInfo
|
|
7
|
+
|
|
8
|
+
// onPresent
|
|
9
|
+
class PresentEvent(surfaceId: Int, viewId: Int, private val sizeInfo: SizeInfo) : Event<PresentEvent>(surfaceId, viewId) {
|
|
10
|
+
override fun getEventName() = EVENT_NAME
|
|
11
|
+
|
|
12
|
+
override fun getEventData(): WritableMap {
|
|
13
|
+
val data = Arguments.createMap()
|
|
14
|
+
data.putInt("index", sizeInfo.index)
|
|
15
|
+
data.putDouble("value", sizeInfo.value.toDouble())
|
|
16
|
+
|
|
17
|
+
return data
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
companion object {
|
|
21
|
+
const val EVENT_NAME = "present"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
package com.lodev09.truesheet.events
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.Arguments
|
|
4
|
+
import com.facebook.react.bridge.WritableMap
|
|
5
|
+
import com.facebook.react.uimanager.events.Event
|
|
6
|
+
import com.lodev09.truesheet.SizeInfo
|
|
7
|
+
|
|
8
|
+
// onSizeChange
|
|
9
|
+
class SizeChangeEvent(surfaceId: Int, viewId: Int, private val sizeInfo: SizeInfo) : Event<SizeChangeEvent>(surfaceId, viewId) {
|
|
10
|
+
override fun getEventName() = EVENT_NAME
|
|
11
|
+
|
|
12
|
+
override fun getEventData(): WritableMap {
|
|
13
|
+
val data = Arguments.createMap()
|
|
14
|
+
data.putInt("index", sizeInfo.index)
|
|
15
|
+
data.putDouble("value", sizeInfo.value.toDouble())
|
|
16
|
+
|
|
17
|
+
return data
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
companion object {
|
|
21
|
+
const val EVENT_NAME = "sizeChange"
|
|
22
|
+
}
|
|
23
|
+
}
|