Skip to content

Commit

Permalink
fix(fabric, textinput): Move spelling and grammer props to TextInputM…
Browse files Browse the repository at this point in the history
…etrics
  • Loading branch information
Saadnajmi committed Nov 29, 2024
1 parent 7a84602 commit e4f0b98
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -486,21 +486,21 @@ - (void)textInputDidChangeSelection
#if TARGET_OS_OSX // [macOS
- (void)automaticSpellingCorrectionDidChange:(BOOL)enabled {
if (_eventEmitter) {
std::static_pointer_cast<TextInputEventEmitter const>(_eventEmitter)->onAutoCorrectChange({.enabled = static_cast<bool>(enabled)});
std::static_pointer_cast<TextInputEventEmitter const>(_eventEmitter)->onAutoCorrectChange({.autoCorrectEnabled = static_cast<bool>(enabled)});
}
}

- (void)continuousSpellCheckingDidChange:(BOOL)enabled
{
if (_eventEmitter) {
std::static_pointer_cast<TextInputEventEmitter const>(_eventEmitter)->onSpellCheckChange({.enabled = static_cast<bool>(enabled)});
std::static_pointer_cast<TextInputEventEmitter const>(_eventEmitter)->onSpellCheckChange({.spellCheckEnabled = static_cast<bool>(enabled)});
}
}

- (void)grammarCheckingDidChange:(BOOL)enabled
{
if (_eventEmitter) {
std::static_pointer_cast<TextInputEventEmitter const>(_eventEmitter)->onGrammarCheckChange({.enabled = static_cast<bool>(enabled)});
std::static_pointer_cast<TextInputEventEmitter const>(_eventEmitter)->onGrammarCheckChange({.grammarCheckEnabled = static_cast<bool>(enabled)});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,46 +172,52 @@ void TextInputEventEmitter::onScroll(const Metrics& textInputMetrics) const {
});
}

void TextInputEventEmitter::dispatchTextInputEvent(
const std::string& name,
#if TARGET_OS_OSX // [macOS
void TextInputEventEmitter::onAutoCorrectChange(
const Metrics& textInputMetrics) const {
dispatchEvent(name, [textInputMetrics](jsi::Runtime& runtime) {
return textInputMetricsPayload(runtime, textInputMetrics);
// dispatchTextInputEvent("autoCorrectChange", textInputMetrics);
dispatchEvent("spellCheckChange", [textInputMetrics](jsi::Runtime& runtime) {
auto payload = jsi::Object(runtime);
payload.setProperty(runtime, "enabled", textInputMetrics.autoCorrectEnabled);
return payload;
});
}

void TextInputEventEmitter::dispatchTextInputContentSizeChangeEvent(
const std::string& name,
void TextInputEventEmitter::onSpellCheckChange(
const Metrics& textInputMetrics) const {
dispatchEvent(name, [textInputMetrics](jsi::Runtime& runtime) {
return textInputMetricsContentSizePayload(runtime, textInputMetrics);
// dispatchTextInputEvent("spellCheckChange", textInputMetrics);
dispatchEvent("spellCheckChange", [textInputMetrics](jsi::Runtime& runtime) {
auto payload = jsi::Object(runtime);
payload.setProperty(runtime, "enabled", textInputMetrics.spellCheckEnabled);
return payload;
});
}

#if TARGET_OS_OSX // [macOS
void TextInputEventEmitter::onAutoCorrectChange(OnAutoCorrectChange event) const {
dispatchEvent("autoCorrectChange", [event=std::move(event)](jsi::Runtime &runtime) {
void TextInputEventEmitter::onGrammarCheckChange(
const Metrics& textInputMetrics) const {
// dispatchTextInputEvent("grammarCheckChange", textInputMetrics);
dispatchEvent("spellCheckChange", [textInputMetrics](jsi::Runtime& runtime) {
auto payload = jsi::Object(runtime);
payload.setProperty(runtime, "enabled", event.enabled);
payload.setProperty(runtime, "enabled", textInputMetrics.grammarCheckEnabled);
return payload;
});
}
#endif // macOS]

void TextInputEventEmitter::onSpellCheckChange(OnSpellCheckChange event) const {
dispatchEvent("spellCheckChange", [event=std::move(event)](jsi::Runtime &runtime) {
auto payload = jsi::Object(runtime);
payload.setProperty(runtime, "enabled", event.enabled);
return payload;
void TextInputEventEmitter::dispatchTextInputEvent(
const std::string& name,
const Metrics& textInputMetrics) const {
dispatchEvent(name, [textInputMetrics](jsi::Runtime& runtime) {
return textInputMetricsPayload(runtime, textInputMetrics);
});
}

void TextInputEventEmitter::onGrammarCheckChange(OnGrammarCheckChange event) const {
dispatchEvent("grammarCheckChange", [event=std::move(event)](jsi::Runtime &runtime) {
auto payload = jsi::Object(runtime);
payload.setProperty(runtime, "enabled", event.enabled);
return payload;
void TextInputEventEmitter::dispatchTextInputContentSizeChangeEvent(
const std::string& name,
const Metrics& textInputMetrics) const {
dispatchEvent(name, [textInputMetrics](jsi::Runtime& runtime) {
return textInputMetricsContentSizePayload(runtime, textInputMetrics);
});
}
#endif // macOS]

} // namespace facebook::react
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ class TextInputEventEmitter : public ViewEventEmitter {
int eventCount;
Size layoutMeasurement;
Float zoomScale;
#if TARGET_OS_OSX // [macOS
bool autoCorrectEnabled;
bool spellCheckEnabled;
bool grammarCheckEnabled;
#endif // macOS]
};

struct KeyPressMetrics {
Expand All @@ -43,23 +48,11 @@ class TextInputEventEmitter : public ViewEventEmitter {
void onSubmitEditing(const Metrics& textInputMetrics) const;
void onKeyPress(const KeyPressMetrics& keyPressMetrics) const;
void onScroll(const Metrics& textInputMetrics) const;

#if TARGET_OS_OSX // [macOS
struct OnAutoCorrectChange {
bool enabled;
};
void onAutoCorrectChange(OnAutoCorrectChange value) const;

struct OnSpellCheckChange {
bool enabled;
};
void onSpellCheckChange(OnSpellCheckChange value) const;

struct OnGrammarCheckChange {
bool enabled;
};
void onGrammarCheckChange(OnGrammarCheckChange value) const;
#endif // macOS]
#if TARGET_OS_OSX // [macOS
void onAutoCorrectChange(const Metrics& textInputMetrics) const;
void onSpellCheckChange(const Metrics& textInputMetrics) const;
void onGrammarCheckChange(const Metrics& textInputMetrics) const;
#endif // macOS]

private:
void dispatchTextInputEvent(
Expand Down

0 comments on commit e4f0b98

Please sign in to comment.