Skip to content

Commit

Permalink
Make onBlankAreaEvent work on Android
Browse files Browse the repository at this point in the history
  • Loading branch information
j-piasecki committed Aug 21, 2022
1 parent 0fb43ad commit 22fbea7
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 13 deletions.
1 change: 1 addition & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ android {

if (isNewArchitectureEnabled()) {
main.java.srcDirs += ["${project.buildDir}/generated/source/codegen/java"]
main.java.srcDirs += ["src/fabric/java"]
} else {
main.java.srcDirs += ['src/paper/java']
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.shopify.reactnative.flash_list

import com.facebook.react.bridge.ReactContext
import com.facebook.react.fabric.FabricUIManager
import com.facebook.react.uimanager.UIManagerHelper
import com.facebook.react.uimanager.common.UIManagerType
import com.facebook.react.bridge.WritableMap

fun ReactContext.dispatchEvent(nativeTag: Int, eventName: String, event: WritableMap) {
val fabricUIManager = UIManagerHelper.getUIManager(this, UIManagerType.FABRIC) as FabricUIManager
fabricUIManager.receiveEvent(nativeTag, eventName, event)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@ package com.shopify.reactnative.flash_list

import android.content.Context
import android.graphics.Canvas
import android.util.DisplayMetrics
import android.util.Log
import android.view.View
import android.view.ViewGroup
import android.widget.HorizontalScrollView
import android.widget.ScrollView
import com.facebook.react.bridge.Arguments
import com.facebook.react.bridge.ReactContext
import com.facebook.react.bridge.WritableMap
import com.facebook.react.uimanager.events.RCTEventEmitter
import com.facebook.react.views.view.ReactViewGroup


Expand Down Expand Up @@ -142,9 +139,8 @@ class AutoLayoutView(context: Context) : ReactViewGroup(context) {
val event: WritableMap = Arguments.createMap()
event.putDouble("offsetStart", alShadow.blankOffsetAtStart / pixelDensity)
event.putDouble("offsetEnd", alShadow.blankOffsetAtEnd / pixelDensity)

val reactContext = context as ReactContext
reactContext
.getJSModule(RCTEventEmitter::class.java)
.receiveEvent(id, "onBlankAreaEvent", event)
reactContext.dispatchEvent(id, "onBlankAreaEvent", event)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,10 @@ class AutoLayoutViewManager: ViewGroupManager<AutoLayoutView>(), AutoLayoutViewM
return AutoLayoutView(context).also { it.pixelDensity = context.resources.displayMetrics.density.toDouble() }
}

override fun getExportedCustomDirectEventTypeConstants(): MutableMap<String, Any> {
return MapBuilder.builder<String, Any>().put(
"onBlankAreaEvent",
MapBuilder.of(
"registrationName", "onBlankAreaEvent")
).build();
}
override fun getExportedCustomDirectEventTypeConstants() = mutableMapOf(
"onBlankAreaEvent" to mutableMapOf("registrationName" to "onBlankAreaEvent"),
"topOnBlankAreaEvent" to mutableMapOf("registrationName" to "onBlankAreaEvent"),
)

@ReactProp(name = "horizontal")
override fun setHorizontal(view: AutoLayoutView, isHorizontal: Boolean) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.shopify.reactnative.flash_list

import com.facebook.react.bridge.ReactContext
import com.facebook.react.uimanager.events.RCTEventEmitter
import com.facebook.react.bridge.WritableMap

fun ReactContext.dispatchEvent(nativeTag: Int, eventName: String, event: WritableMap) {
this.getJSModule(RCTEventEmitter::class.java)
.receiveEvent(nativeTag, eventName, event)
}

0 comments on commit 22fbea7

Please sign in to comment.