@@ -52,7 +52,8 @@ void HostPlatformViewEventEmitter::onKeyUp(const KeyEvent& keyEvent) const {
5252
5353#pragma mark - Mouse Events
5454
55- static jsi::Value mouseEventPayload (jsi::Runtime& runtime, const MouseEvent& event) {
55+ // Returns an Object instead of value as we read and modify it in dragEventPayload.
56+ static jsi::Object mouseEventPayload (jsi::Runtime& runtime, const MouseEvent& event) {
5657 auto payload = jsi::Object (runtime);
5758 payload.setProperty (runtime, " clientX" , event.clientX );
5859 payload.setProperty (runtime, " clientY" , event.clientY );
@@ -79,12 +80,14 @@ void HostPlatformViewEventEmitter::onMouseLeave(const MouseEvent& mouseEvent) co
7980
8081#pragma mark - Drag and Drop Events
8182
82- static jsi::Value dragEventPayload (jsi::Runtime& runtime, DragEvent const & event) {
83- auto filesArray = jsi::Array (runtime, event.dataTransferItems .size ());
84- auto itemsArray = jsi::Array (runtime, event.dataTransferItems .size ());
85- auto typesArray = jsi::Array (runtime, event.dataTransferItems .size ());
83+ static jsi::Value dataTransferPayload (
84+ jsi::Runtime& runtime,
85+ const std::vector<DataTransferItem>& dataTransferItems) {
86+ auto filesArray = jsi::Array (runtime, dataTransferItems.size ());
87+ auto itemsArray = jsi::Array (runtime, dataTransferItems.size ());
88+ auto typesArray = jsi::Array (runtime, dataTransferItems.size ());
8689 int i = 0 ;
87- for (auto const & transferItem : event. dataTransferItems ) {
90+ for (const auto & transferItem : dataTransferItems) {
8891 auto fileObject = jsi::Object (runtime);
8992 fileObject.setProperty (runtime, " name" , transferItem.name );
9093 fileObject.setProperty (runtime, " type" , transferItem.type );
@@ -99,25 +102,33 @@ static jsi::Value dragEventPayload(jsi::Runtime& runtime, DragEvent const& event
99102 fileObject.setProperty (runtime, " height" , *transferItem.height );
100103 }
101104 filesArray.setValueAtIndex (runtime, i, fileObject);
102-
105+
103106 auto itemObject = jsi::Object (runtime);
104107 itemObject.setProperty (runtime, " kind" , transferItem.kind );
105108 itemObject.setProperty (runtime, " type" , transferItem.type );
106109 itemsArray.setValueAtIndex (runtime, i, itemObject);
107-
110+
108111 typesArray.setValueAtIndex (runtime, i, transferItem.type );
109112 i++;
110113 }
111-
114+
112115 auto dataTransferObject = jsi::Object (runtime);
113116 dataTransferObject.setProperty (runtime, " files" , filesArray);
114117 dataTransferObject.setProperty (runtime, " items" , itemsArray);
115118 dataTransferObject.setProperty (runtime, " types" , typesArray);
116119
120+ return dataTransferObject;
121+ }
122+
123+ static jsi::Value dragEventPayload (
124+ jsi::Runtime& runtime,
125+ const DragEvent& event) {
117126 auto payload = mouseEventPayload (runtime, event);
127+ auto dataTransferObject =
128+ dataTransferPayload (runtime, event.dataTransferItems );
118129 payload.setProperty (runtime, " dataTransfer" , dataTransferObject);
119130 return payload;
120- };
131+ }
121132
122133void HostPlatformViewEventEmitter::onDragEnter (DragEvent const & dragEvent) const {
123134 dispatchEvent (" dragEnter" , [dragEvent](jsi::Runtime &runtime) {
@@ -137,4 +148,4 @@ void HostPlatformViewEventEmitter::onDrop(DragEvent const& dragEvent) const {
137148 });
138149}
139150
140- } // namespace facebook::react
151+ } // namespace facebook::react
0 commit comments