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 @@ -2,8 +2,8 @@

#include "MarkdownContainerMeasurementManager.h"
#include "MarkdownContainerShadowNode.h"
#include "MarkdownInputMeasurementManager.h"
#include "MarkdownInputShadowNode.h"
#include "MarkdownTextInputMeasurementManager.h"
#include "MarkdownTextInputShadowNode.h"
#include "MarkdownTextMeasurementManager.h"
#include "MarkdownTextShadowNode.h"

Expand Down Expand Up @@ -44,20 +44,21 @@ class EnrichedMarkdownTextComponentDescriptor final : public ConcreteComponentDe
const std::shared_ptr<MarkdownTextMeasurementManager> measurementsManager_;
};

class EnrichedMarkdownTextInputComponentDescriptor final : public ConcreteComponentDescriptor<MarkdownInputShadowNode> {
class EnrichedMarkdownTextInputComponentDescriptor final
: public ConcreteComponentDescriptor<MarkdownTextInputShadowNode> {
public:
EnrichedMarkdownTextInputComponentDescriptor(const ComponentDescriptorParameters &parameters)
: ConcreteComponentDescriptor(parameters),
measurementsManager_(std::make_shared<MarkdownInputMeasurementManager>(contextContainer_)) {}
measurementsManager_(std::make_shared<MarkdownTextInputMeasurementManager>(contextContainer_)) {}

void adopt(ShadowNode &shadowNode) const override {
ConcreteComponentDescriptor::adopt(shadowNode);
auto &inputShadowNode = static_cast<MarkdownInputShadowNode &>(shadowNode);
auto &inputShadowNode = static_cast<MarkdownTextInputShadowNode &>(shadowNode);
inputShadowNode.setMeasurementsManager(measurementsManager_);
}

private:
const std::shared_ptr<MarkdownInputMeasurementManager> measurementsManager_;
const std::shared_ptr<MarkdownTextInputMeasurementManager> measurementsManager_;
};

void EnrichedMarkdownTextSpec_registerComponentDescriptorsFromCodegen(
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "MarkdownInputMeasurementManager.h"
#include "MarkdownTextInputMeasurementManager.h"
#include "conversions.h"

#include <fbjni/fbjni.h>
Expand All @@ -9,9 +9,9 @@ using namespace facebook::jni;

namespace facebook::react {

Size MarkdownInputMeasurementManager::measure(SurfaceId surfaceId, int viewTag,
const EnrichedMarkdownTextInputProps &props,
LayoutConstraints layoutConstraints) const {
Size MarkdownTextInputMeasurementManager::measure(SurfaceId surfaceId, int viewTag,
const EnrichedMarkdownTextInputProps &props,
LayoutConstraints layoutConstraints) const {
const jni::global_ref<jobject> &fabricUIManager = contextContainer_->at<jni::global_ref<jobject>>("FabricUIManager");

static const auto measure =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

namespace facebook::react {

class MarkdownInputMeasurementManager {
class MarkdownTextInputMeasurementManager {
public:
MarkdownInputMeasurementManager(const std::shared_ptr<const ContextContainer> &contextContainer)
MarkdownTextInputMeasurementManager(const std::shared_ptr<const ContextContainer> &contextContainer)
: contextContainer_(contextContainer) {}

Size measure(SurfaceId surfaceId, int viewTag, const EnrichedMarkdownTextInputProps &props,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#include "MarkdownInputShadowNode.h"
#include "MarkdownTextInputShadowNode.h"

#include <react/renderer/core/LayoutContext.h>

namespace facebook::react {

extern const char MarkdownInputComponentName[] = "EnrichedMarkdownTextInput";
extern const char MarkdownTextInputComponentName[] = "EnrichedMarkdownTextInput";

void MarkdownInputShadowNode::setMeasurementsManager(
const std::shared_ptr<MarkdownInputMeasurementManager> &measurementsManager) {
void MarkdownTextInputShadowNode::setMeasurementsManager(
const std::shared_ptr<MarkdownTextInputMeasurementManager> &measurementsManager) {
ensureUnsealed();
measurementsManager_ = measurementsManager;
}

void MarkdownInputShadowNode::dirtyLayoutIfNeeded() {
void MarkdownTextInputShadowNode::dirtyLayoutIfNeeded() {
const auto state = this->getStateData();
const auto counter = state.getForceHeightRecalculationCounter();

Expand All @@ -22,8 +22,8 @@ void MarkdownInputShadowNode::dirtyLayoutIfNeeded() {
}
}

Size MarkdownInputShadowNode::measureContent(const LayoutContext &layoutContext,
const LayoutConstraints &layoutConstraints) const {
Size MarkdownTextInputShadowNode::measureContent(const LayoutContext &layoutContext,
const LayoutConstraints &layoutConstraints) const {
return measurementsManager_->measure(getSurfaceId(), getTag(), getConcreteProps(), layoutConstraints);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
#pragma once

#include "MarkdownInputMeasurementManager.h"
#include "MarkdownInputState.h"
#include "MarkdownTextInputMeasurementManager.h"
#include "MarkdownTextInputState.h"

#include <react/renderer/components/EnrichedMarkdownTextSpec/EventEmitters.h>
#include <react/renderer/components/EnrichedMarkdownTextSpec/Props.h>
#include <react/renderer/components/view/ConcreteViewShadowNode.h>

namespace facebook::react {

JSI_EXPORT extern const char MarkdownInputComponentName[];
JSI_EXPORT extern const char MarkdownTextInputComponentName[];

class MarkdownInputShadowNode final
: public ConcreteViewShadowNode<MarkdownInputComponentName, EnrichedMarkdownTextInputProps,
EnrichedMarkdownTextInputEventEmitter, MarkdownInputState> {
class MarkdownTextInputShadowNode final
: public ConcreteViewShadowNode<MarkdownTextInputComponentName, EnrichedMarkdownTextInputProps,
EnrichedMarkdownTextInputEventEmitter, MarkdownTextInputState> {
public:
using ConcreteViewShadowNode::ConcreteViewShadowNode;

MarkdownInputShadowNode(ShadowNode const &sourceShadowNode, ShadowNodeFragment const &fragment)
MarkdownTextInputShadowNode(ShadowNode const &sourceShadowNode, ShadowNodeFragment const &fragment)
: ConcreteViewShadowNode(sourceShadowNode, fragment) {
dirtyLayoutIfNeeded();
}
Expand All @@ -29,15 +29,15 @@ class MarkdownInputShadowNode final
return traits;
}

void setMeasurementsManager(const std::shared_ptr<MarkdownInputMeasurementManager> &measurementsManager);
void setMeasurementsManager(const std::shared_ptr<MarkdownTextInputMeasurementManager> &measurementsManager);

void dirtyLayoutIfNeeded();

Size measureContent(const LayoutContext &layoutContext, const LayoutConstraints &layoutConstraints) const override;

private:
int forceHeightRecalculationCounter_{0};
std::shared_ptr<MarkdownInputMeasurementManager> measurementsManager_;
std::shared_ptr<MarkdownTextInputMeasurementManager> measurementsManager_;
};

} // namespace facebook::react
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "MarkdownTextInputState.h"

namespace facebook::react {

int MarkdownTextInputState::getForceHeightRecalculationCounter() const {
return forceHeightRecalculationCounter_;
}

} // namespace facebook::react
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

namespace facebook::react {

class MarkdownInputState {
class MarkdownTextInputState {
public:
MarkdownInputState() : forceHeightRecalculationCounter_(0) {}
MarkdownTextInputState() : forceHeightRecalculationCounter_(0) {}

MarkdownInputState(MarkdownInputState const &previousState, folly::dynamic data)
MarkdownTextInputState(MarkdownTextInputState const &previousState, folly::dynamic data)
: forceHeightRecalculationCounter_((int)data["forceHeightRecalculationCounter"].getInt()) {}

folly::dynamic getDynamic() const {
Expand Down
2 changes: 1 addition & 1 deletion ios/input/ENRMInputTextView.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
NS_ASSUME_NONNULL_BEGIN

@interface ENRMInputTextView : ENRMPlatformTextView
@property (nonatomic, weak, nullable) EnrichedMarkdownTextInput *markdownInput;
@property (nonatomic, weak, nullable) EnrichedMarkdownTextInput *markdownTextInput;
@end

NS_ASSUME_NONNULL_END
24 changes: 12 additions & 12 deletions ios/input/ENRMInputTextView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ - (void)copy:(id)sender
}

NSString *plainText = [self.text substringWithRange:selection];
NSString *markdown = [self.markdownInput markdownForSelectedRange];
NSString *markdown = [self.markdownTextInput markdownForSelectedRange];

UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
NSMutableDictionary *items = [NSMutableDictionary dictionary];
Expand Down Expand Up @@ -49,8 +49,8 @@ - (void)paste:(id)sender
markdown = [[NSString alloc] initWithData:markdownValue encoding:NSUTF8StringEncoding];
}

if (markdown.length > 0 && self.markdownInput != nil) {
[self.markdownInput pasteMarkdown:markdown];
if (markdown.length > 0 && self.markdownTextInput != nil) {
[self.markdownTextInput pasteMarkdown:markdown];
return;
}

Expand All @@ -74,8 +74,8 @@ - (BOOL)canPerformAction:(SEL)action withSender:(id)sender
- (void)layoutSubviews
{
[super layoutSubviews];
if (self.markdownInput != nil) {
[self.markdownInput scheduleRelayoutIfNeeded];
if (self.markdownTextInput != nil) {
[self.markdownTextInput scheduleRelayoutIfNeeded];
}
}

Expand All @@ -93,7 +93,7 @@ - (void)copy:(id)sender
}

NSString *plainText = [self.string substringWithRange:selection];
NSString *markdown = [self.markdownInput markdownForSelectedRange];
NSString *markdown = [self.markdownTextInput markdownForSelectedRange];

NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
[pasteboard clearContents];
Expand Down Expand Up @@ -121,8 +121,8 @@ - (void)paste:(id)sender
NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];

NSString *markdown = [pasteboard stringForType:kENRMMarkdownPasteboardType];
if (markdown.length > 0 && self.markdownInput != nil) {
[self.markdownInput pasteMarkdown:markdown];
if (markdown.length > 0 && self.markdownTextInput != nil) {
[self.markdownTextInput pasteMarkdown:markdown];
return;
}

Expand Down Expand Up @@ -158,17 +158,17 @@ - (void)mouseDown:(NSEvent *)event
- (NSMenu *)menuForEvent:(NSEvent *)event
{
NSMenu *menu = [super menuForEvent:event];
if (self.markdownInput != nil) {
return [self.markdownInput enrichedMenuForEvent:event defaultMenu:menu textView:self];
if (self.markdownTextInput != nil) {
return [self.markdownTextInput enrichedMenuForEvent:event defaultMenu:menu textView:self];
}
return menu;
}

- (void)layout
{
[super layout];
if (self.markdownInput != nil) {
[self.markdownInput scheduleRelayoutIfNeeded];
if (self.markdownTextInput != nil) {
[self.markdownTextInput scheduleRelayoutIfNeeded];
}
}

Expand Down
4 changes: 2 additions & 2 deletions ios/input/EnrichedMarkdownTextInput.mm
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ - (void)setupTextView
#else
ENRMInputTextView *inputTextView = [[ENRMInputTextView alloc] initWithFrame:CGRectZero];
#endif
inputTextView.markdownInput = self;
inputTextView.markdownTextInput = self;
_textView = inputTextView;
ENRMConfigureMarkdownInputTextView(_textView);
ENRMConfigureMarkdownTextInputTextView(_textView);
#if !TARGET_OS_OSX
_textView.adjustsFontForContentSizeCategory = YES;
_textView.delegate = self;
Expand Down
2 changes: 1 addition & 1 deletion ios/utils/ENRMUIKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ static inline void ENRMSetDefaultTypingAttributes(ENRMPlatformTextView *textView
/// Applies shared configuration to a text view used for markdown input editing.
/// Handles platform differences: scroll indicators, text container insets,
/// drawsBackground (macOS). Sets editable=YES, scrollEnabled=YES.
static inline void ENRMConfigureMarkdownInputTextView(ENRMPlatformTextView *textView)
static inline void ENRMConfigureMarkdownTextInputTextView(ENRMPlatformTextView *textView)
{
textView.font = [UIFont systemFontOfSize:16.0];
textView.backgroundColor = [RCTUIColor clearColor];
Expand Down
Loading