Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

T3MarkdownTextShadowNode.h

82 lines2.3 KB

1#pragma once
2​
3#include <react/renderer/components/T3MarkdownTextSpec/EventEmitters.h>
4#include <react/renderer/components/T3MarkdownTextSpec/Props.h>
5#include <react/renderer/components/view/ConcreteViewShadowNode.h>
6#include <react/renderer/textlayoutmanager/TextLayoutManager.h>
7#include <react/renderer/core/LayoutContext.h>
8#include <react/renderer/core/ShadowNode.h>
9​
10#include <string>
11#include <vector>
12​
13namespace facebook::react {
14​
15extern const char T3MarkdownTextComponentName[];
16​
17struct T3MarkdownTextParagraphStyleRange {
18 size_t location;
19 size_t length;
20 Float firstLineHeadIndent;
21 Float headIndent;
22 Float paragraphSpacing;
23};
24​
25struct T3MarkdownTextAttachmentRange {
26 size_t location;
27 size_t length;
28 std::string imageUri;
29 /// Recolor the loaded image with the run's foreground color, like `sf:` symbols.
30 bool tintWithForeground;
31 Float chipWidth = 0;
32 Float chipHeight = 0;
33};
34​
35inline Float T3MarkdownTextAttachmentSize(const T3MarkdownTextAttachmentRange &) {
36 return 14;
38​
39inline Float T3MarkdownTextAttachmentBaselineOffset(
40 const T3MarkdownTextAttachmentRange &) {
41 return -2;
43​
44class T3MarkdownTextStateReal final {
45 public:
46 AttributedString attributedString;
47 std::vector<T3MarkdownTextParagraphStyleRange> paragraphStyleRanges;
48 std::vector<T3MarkdownTextAttachmentRange> attachmentRanges;
49};
50​
51class T3MarkdownTextShadowNode final : public ConcreteViewShadowNode<
52T3MarkdownTextComponentName,
53T3MarkdownTextProps,
54T3MarkdownTextEventEmitter,
55T3MarkdownTextStateReal> {
56public:
57 using ConcreteViewShadowNode::ConcreteViewShadowNode;
58​
59 T3MarkdownTextShadowNode(
60 const ShadowNode& sourceShadowNode,
61 const ShadowNodeFragment& fragment
62 );
63​
64 static ShadowNodeTraits BaseTraits() {
65 auto traits = ConcreteViewShadowNode::BaseTraits();
66 traits.set(ShadowNodeTraits::Trait::LeafYogaNode);
67 traits.set(ShadowNodeTraits::Trait::MeasurableYogaNode);
68 return traits;
69 }
70​
71 void layout(LayoutContext layoutContext) override;
72​
73 Size measureContent(
74 const LayoutContext& layoutContext,
75 const LayoutConstraints& layoutConstraints) const override;
76​
77private:
78 mutable AttributedString _attributedString;
79 mutable std::vector<T3MarkdownTextParagraphStyleRange> _paragraphStyleRanges;
80 mutable std::vector<T3MarkdownTextAttachmentRange> _attachmentRanges;
81};
82} // namespace facebook::React