Skip to content

Commit 9702a1a

Browse files
committed
Introduce PasteMetrics
1 parent c48adbe commit 9702a1a

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

packages/react-native/ReactCommon/react/renderer/components/textinput/TextInputEventEmitter.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,17 @@ static jsi::Value keyPressMetricsPayload(
132132
return payload;
133133
};
134134

135+
#if TARGET_OS_OSX // [macOS
136+
static jsi::Value pasteMetricsPayload(
137+
jsi::Runtime& runtime,
138+
const TextInputEventEmitter::PasteMetrics& pasteMetrics) {
139+
auto payload = jsi::Object(runtime);
140+
auto dataTransferObject = HostPlatformViewEventEmitter::dataTransferPayload(runtime, pasteMetrics.dataTransferItems);
141+
payload.setProperty(runtime, "dataTransfer", dataTransferObject);
142+
return payload;
143+
};
144+
#endif // macOS]
145+
135146
void TextInputEventEmitter::onFocus(const Metrics& textInputMetrics) const {
136147
dispatchTextInputEvent("focus", textInputMetrics);
137148
}
@@ -195,9 +206,9 @@ void TextInputEventEmitter::onGrammarCheckChange(
195206
}
196207

197208
void TextInputEventEmitter::onPaste(
198-
const Metrics& textInputMetrics) const {
199-
dispatchEvent("paste", [textInputMetrics](jsi::Runtime& runtime) {
200-
return dataTransferPayload(runtime, textInputMetrics.dataTransferItems);
209+
const PasteMetrics& pasteMetrics) const {
210+
dispatchEvent("paste", [pasteMetrics](jsi::Runtime& runtime) {
211+
return pasteMetricsPayload(runtime, pasteMetrics);
201212
});
202213
}
203214
#endif // macOS]

packages/react-native/ReactCommon/react/renderer/components/textinput/TextInputEventEmitter.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,19 @@ class TextInputEventEmitter : public ViewEventEmitter {
3232
bool autoCorrectEnabled;
3333
bool spellCheckEnabled;
3434
bool grammarCheckEnabled;
35-
std::vector<DataTransferItem> dataTransferItems;
3635
#endif // macOS]
3736
};
3837

3938
struct KeyPressMetrics {
4039
std::string text;
4140
int eventCount;
4241
};
42+
43+
#if TARGET_OS_OSX // [macOS
44+
struct PasteMetrics {
45+
std::vector<DataTransferItem> dataTransferItems;
46+
};
47+
#endif // macOS]
4348

4449
void onFocus(const Metrics& textInputMetrics) const;
4550
void onBlur(const Metrics& textInputMetrics) const;
@@ -54,7 +59,7 @@ class TextInputEventEmitter : public ViewEventEmitter {
5459
void onAutoCorrectChange(const Metrics& textInputMetrics) const;
5560
void onSpellCheckChange(const Metrics& textInputMetrics) const;
5661
void onGrammarCheckChange(const Metrics& textInputMetrics) const;
57-
void onPaste(const Metrics& textInputMetrics) const;
62+
void onPaste(const PasteMetrics& pasteMetrics) const;
5863
#endif // macOS]
5964

6065
private:

0 commit comments

Comments
 (0)