t3-code-android-nightly/apps/mobile/modules/t3-markdown-text/ios/T3MarkdownTextShadowNode.h
Chris Deeming 4fed6cfb35
feat: add inline file previews and attachment chips across surfaces (#11265)
Co-authored-by: Julius Marminge <51714798+juliusmarminge@users.noreply.github.com>
2026-09-11 23:58:12 -07:00

82 lines
2.3 KiB
C++

#pragma once
#include <react/renderer/components/T3MarkdownTextSpec/EventEmitters.h>
#include <react/renderer/components/T3MarkdownTextSpec/Props.h>
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
#include <react/renderer/textlayoutmanager/TextLayoutManager.h>
#include <react/renderer/core/LayoutContext.h>
#include <react/renderer/core/ShadowNode.h>
#include <string>
#include <vector>
namespace facebook::react {
extern const char T3MarkdownTextComponentName[];
struct T3MarkdownTextParagraphStyleRange {
size_t location;
size_t length;
Float firstLineHeadIndent;
Float headIndent;
Float paragraphSpacing;
};
struct T3MarkdownTextAttachmentRange {
size_t location;
size_t length;
std::string imageUri;
/// Recolor the loaded image with the run's foreground color, like `sf:` symbols.
bool tintWithForeground;
Float chipWidth = 0;
Float chipHeight = 0;
};
inline Float T3MarkdownTextAttachmentSize(const T3MarkdownTextAttachmentRange &) {
return 14;
}
inline Float T3MarkdownTextAttachmentBaselineOffset(
const T3MarkdownTextAttachmentRange &) {
return -2;
}
class T3MarkdownTextStateReal final {
public:
AttributedString attributedString;
std::vector<T3MarkdownTextParagraphStyleRange> paragraphStyleRanges;
std::vector<T3MarkdownTextAttachmentRange> attachmentRanges;
};
class T3MarkdownTextShadowNode final : public ConcreteViewShadowNode<
T3MarkdownTextComponentName,
T3MarkdownTextProps,
T3MarkdownTextEventEmitter,
T3MarkdownTextStateReal> {
public:
using ConcreteViewShadowNode::ConcreteViewShadowNode;
T3MarkdownTextShadowNode(
const ShadowNode& sourceShadowNode,
const ShadowNodeFragment& fragment
);
static ShadowNodeTraits BaseTraits() {
auto traits = ConcreteViewShadowNode::BaseTraits();
traits.set(ShadowNodeTraits::Trait::LeafYogaNode);
traits.set(ShadowNodeTraits::Trait::MeasurableYogaNode);
return traits;
}
void layout(LayoutContext layoutContext) override;
Size measureContent(
const LayoutContext& layoutContext,
const LayoutConstraints& layoutConstraints) const override;
private:
mutable AttributedString _attributedString;
mutable std::vector<T3MarkdownTextParagraphStyleRange> _paragraphStyleRanges;
mutable std::vector<T3MarkdownTextAttachmentRange> _attachmentRanges;
};
} // namespace facebook::React