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

T3MarkdownTextShadowNode.h

80 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};
32​
33inline Float T3MarkdownTextAttachmentSize(const T3MarkdownTextAttachmentRange &) {
34 return 14;
36​
37inline Float T3MarkdownTextAttachmentBaselineOffset(
38 const T3MarkdownTextAttachmentRange &) {
39 return -2;
41​
42class T3MarkdownTextStateReal final {
43 public:
44 AttributedString attributedString;
45 std::vector<T3MarkdownTextParagraphStyleRange> paragraphStyleRanges;
46 std::vector<T3MarkdownTextAttachmentRange> attachmentRanges;
47};
48​
49class T3MarkdownTextShadowNode final : public ConcreteViewShadowNode<
50T3MarkdownTextComponentName,
51T3MarkdownTextProps,
52T3MarkdownTextEventEmitter,
53T3MarkdownTextStateReal> {
54public:
55 using ConcreteViewShadowNode::ConcreteViewShadowNode;
56​
57 T3MarkdownTextShadowNode(
58 const ShadowNode& sourceShadowNode,
59 const ShadowNodeFragment& fragment
60 );
61​
62 static ShadowNodeTraits BaseTraits() {
63 auto traits = ConcreteViewShadowNode::BaseTraits();
64 traits.set(ShadowNodeTraits::Trait::LeafYogaNode);
65 traits.set(ShadowNodeTraits::Trait::MeasurableYogaNode);
66 return traits;
67 }
68​
69 void layout(LayoutContext layoutContext) override;
70​
71 Size measureContent(
72 const LayoutContext& layoutContext,
73 const LayoutConstraints& layoutConstraints) const override;
74​
75private:
76 mutable AttributedString _attributedString;
77 mutable std::vector<T3MarkdownTextParagraphStyleRange> _paragraphStyleRanges;
78 mutable std::vector<T3MarkdownTextAttachmentRange> _attachmentRanges;
79};
80} // namespace facebook::React