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

T3MarkdownTextShadowNode.h

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