Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.facebook.react.bridge.WritableMap
/**
* Direct event for CameraGestureObserver -> onMapSteady
* JS registrationName: onMapSteady
* Native event name (key): topOnMapSteady
* Native event name (key): onMapSteady
*/
class MapSteadyEvent(
view: View?,
Expand All @@ -16,7 +16,7 @@ class MapSteadyEvent(
private val lastGestureType: String?
) : AbstractEvent(view, "mapSteady") {
override val key: String
get() = "topOnMapSteady"
get() = "onMapSteady"

override val payload: WritableMap
get() = Arguments.createMap().apply {
Expand All @@ -34,6 +34,12 @@ class MapSteadyEvent(
putDouble("timestamp", System.currentTimeMillis().toDouble())
}

override fun toJSON(): WritableMap {
val map = Arguments.createMap()
map.merge(payload)
return map
}

override fun canCoalesce(): Boolean {
// Do not coalesce - each steady/timeout event is significant
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class RNMBXCameraGestureObserver(
private var lastTransitionEndedAtMs: Double? = null
private var quietRunnable: Runnable? = null
private var timeoutRunnable: Runnable? = null
private var emittedForCurrentActivity: Boolean = false

private val quietMs: Double get() = quietPeriodMs ?: 200.0
private val maxMs: Double? get() = maxIntervalMs
Expand Down Expand Up @@ -84,9 +83,9 @@ class RNMBXCameraGestureObserver(
}

private fun scheduleQuietCheck() {
cancelQuietTimer()
val delay = quietMs
if (delay <= 0) {
cancelQuietTimer()
maybeEmitSteady()
return
}
Expand All @@ -99,16 +98,17 @@ class RNMBXCameraGestureObserver(
}

private fun scheduleTimeout() {
if (timeoutRunnable != null) return
val delay = maxMs ?: return
val runnable = Runnable {
timeoutRunnable = null
emitTimeout()
}
timeoutRunnable = scheduleTimer(delay, runnable)
}

private fun markActivity(gestureType: String? = null) {
if (gestureType != null) lastGestureType = gestureType
emittedForCurrentActivity = false
scheduleQuietCheck()
scheduleTimeout()
}
Expand All @@ -122,7 +122,6 @@ class RNMBXCameraGestureObserver(
}

private fun emitSteady(idleDurationMs: Double) {
if (emittedForCurrentActivity) return
cancelQuietTimer()
cancelTimeoutTimer()
val gesture = lastGestureType
Expand All @@ -131,7 +130,6 @@ class RNMBXCameraGestureObserver(
MapSteadyEvent.make(this, "steady", idleDurationMs, gesture)
)
lastGestureType = null
emittedForCurrentActivity = true
}

private fun emitTimeout() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class RNMBXCameraGestureObserverManager(private val mContext: ReactApplicationCo

// Map the native event name to the JS registration name for direct events
override fun customEvents(): Map<String, String> = mapOf(
"topOnMapSteady" to "onMapSteady"
"onMapSteady" to "onMapSteady"
)

companion object {
Expand Down
Loading