@expensify/react-native-live-markdown 0.1.254 → 0.1.256
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/RNLiveMarkdown.podspec +2 -0
- package/android/src/main/java/com/expensify/livemarkdown/LiveMarkdownModule.java +0 -10
- package/android/src/main/java/com/expensify/livemarkdown/MarkdownTextInputDecoratorView.java +5 -28
- package/android/src/main/java/com/expensify/livemarkdown/MarkdownTextInputDecoratorViewManagerSpec.java +3 -3
- package/android/src/main/new_arch/CMakeLists.txt +2 -1
- package/android/src/main/new_arch/react/renderer/components/RNLiveMarkdownSpec/MarkdownTextInputDecoratorShadowNode.cpp +135 -0
- package/android/src/main/new_arch/react/renderer/components/RNLiveMarkdownSpec/MarkdownTextInputDecoratorShadowNode.h +75 -0
- package/apple/LiveMarkdownModule.mm +1 -53
- package/apple/MarkdownTextInputDecoratorComponentView.mm +6 -36
- package/apple/MarkdownTextInputDecoratorShadowNode.h +67 -0
- package/apple/MarkdownTextInputDecoratorShadowNode.mm +271 -0
- package/apple/RCTMarkdownUtils.mm +6 -0
- package/apple/RCTTextInputComponentView+Markdown.mm +0 -16
- package/cpp/react/renderer/components/RNLiveMarkdownSpec/MarkdownTextInputDecoratorState.h +3 -16
- package/lib/commonjs/MarkdownTextInput.js +7 -9
- package/lib/commonjs/MarkdownTextInput.js.map +1 -1
- package/lib/module/MarkdownTextInput.js +7 -9
- package/lib/module/MarkdownTextInput.js.map +1 -1
- package/lib/typescript/src/MarkdownTextInput.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/MarkdownTextInput.tsx +8 -11
- package/android/src/main/java/com/expensify/livemarkdown/NativeProxy.java +0 -24
- package/android/src/main/new_arch/MarkdownCommitHook.cpp +0 -192
- package/android/src/main/new_arch/MarkdownCommitHook.h +0 -58
- package/android/src/main/new_arch/NativeProxy.cpp +0 -40
- package/android/src/main/new_arch/NativeProxy.h +0 -39
- package/android/src/main/new_arch/OnLoad.cpp +0 -8
- package/apple/MarkdownCommitHook.h +0 -46
- package/apple/MarkdownCommitHook.mm +0 -303
- package/cpp/react/renderer/components/RNLiveMarkdownSpec/MarkdownShadowFamilyRegistry.cpp +0 -60
- package/cpp/react/renderer/components/RNLiveMarkdownSpec/MarkdownShadowFamilyRegistry.h +0 -38
- package/cpp/react/renderer/components/RNLiveMarkdownSpec/MarkdownTextInputDecoratorShadowNode.cpp +0 -33
- package/cpp/react/renderer/components/RNLiveMarkdownSpec/MarkdownTextInputDecoratorShadowNode.h +0 -46
- package/cpp/react/renderer/components/RNLiveMarkdownSpec/OwningShadowNodeFragment.h +0 -28
|
@@ -1,303 +0,0 @@
|
|
|
1
|
-
#include <React/RCTUtils.h>
|
|
2
|
-
#include <react/renderer/core/ComponentDescriptor.h>
|
|
3
|
-
#include <react/renderer/textlayoutmanager/RCTAttributedTextUtils.h>
|
|
4
|
-
#include <react/utils/ManagedObjectWrapper.h>
|
|
5
|
-
|
|
6
|
-
#include "MarkdownCommitHook.h"
|
|
7
|
-
#include "MarkdownShadowFamilyRegistry.h"
|
|
8
|
-
#include "RCTMarkdownStyle.h"
|
|
9
|
-
|
|
10
|
-
using namespace facebook::react;
|
|
11
|
-
|
|
12
|
-
namespace expensify {
|
|
13
|
-
namespace livemarkdown {
|
|
14
|
-
|
|
15
|
-
MarkdownCommitHook::MarkdownCommitHook(
|
|
16
|
-
const std::shared_ptr<UIManager> &uiManager)
|
|
17
|
-
: uiManager_(uiManager) {
|
|
18
|
-
uiManager_->registerCommitHook(*this);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
MarkdownCommitHook::~MarkdownCommitHook() noexcept {
|
|
22
|
-
uiManager_->unregisterCommitHook(*this);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
RCTMarkdownUtils *MarkdownCommitHook::getMarkdownUtils(
|
|
26
|
-
const MarkdownTextInputDecoratorShadowNode &decorator) {
|
|
27
|
-
const auto decoratorState = std::static_pointer_cast<
|
|
28
|
-
const ConcreteState<MarkdownTextInputDecoratorState>>(
|
|
29
|
-
decorator.getState());
|
|
30
|
-
const auto memoizedUtils = (RCTMarkdownUtils *)unwrapManagedObject(
|
|
31
|
-
decoratorState->getData().markdownUtils);
|
|
32
|
-
return memoizedUtils;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
RCTMarkdownUtils *MarkdownCommitHook::getOrCreateMarkdownUtils(
|
|
36
|
-
const MarkdownTextInputDecoratorShadowNode &decorator) {
|
|
37
|
-
const auto memoizedUtils = MarkdownCommitHook::getMarkdownUtils(decorator);
|
|
38
|
-
|
|
39
|
-
if (memoizedUtils != nullptr) {
|
|
40
|
-
return memoizedUtils;
|
|
41
|
-
} else {
|
|
42
|
-
return [[RCTMarkdownUtils alloc] init];
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
RootShadowNode::Unshared MarkdownCommitHook::shadowTreeWillCommit(
|
|
47
|
-
ShadowTree const &, RootShadowNode::Shared const &,
|
|
48
|
-
RootShadowNode::Unshared const &newRootShadowNode) noexcept {
|
|
49
|
-
auto rootNode = newRootShadowNode->ShadowNode::clone(ShadowNodeFragment{});
|
|
50
|
-
|
|
51
|
-
// A preface to why we do the weird thing below:
|
|
52
|
-
// On the new architecture there are two ways of measuring text on iOS: by
|
|
53
|
-
// value and by pointer. When done by value, the attributed string to be
|
|
54
|
-
// measured is created on the c++ side. We cannot modify this process as we do
|
|
55
|
-
// not extend TextInputShadowNode. We also cannot really change the layout
|
|
56
|
-
// manager used to do this, since it's a private field (ok, we can but in a
|
|
57
|
-
// not very nice way). But also, the logic for parsing and applying markdown
|
|
58
|
-
// is written in JS/ObjC and we really wouldn't want to reimplement it in c++.
|
|
59
|
-
//
|
|
60
|
-
// Nice thing is that it can also be done by pointer to NSAttributedString,
|
|
61
|
-
// which is the platform's way to handle styled text, and is also used by Live
|
|
62
|
-
// Markdown. On this path, the measurement is done by the OS APIs. The thing
|
|
63
|
-
// we want to make sure of, is that markdown-decorated text input always uses
|
|
64
|
-
// this path and uses a pointer to a string with markdown styles applied.
|
|
65
|
-
// Thankfully, RN provides nice utility functions that allow to convert
|
|
66
|
-
// between the RN's AttributedString and iOS's NSAttributedString. The logic
|
|
67
|
-
// below does exactly that.
|
|
68
|
-
|
|
69
|
-
// In order to properly apply markdown formatting to the text input, we need
|
|
70
|
-
// to update the TextInputShadowNode's state with styled string, but we only
|
|
71
|
-
// have access to the ShadowNodeFamilies of the decorator components. We also
|
|
72
|
-
// know that a markdown decorator is always preceded with the TextInput to
|
|
73
|
-
// decorate, so we need to take the sibling.
|
|
74
|
-
std::vector<MarkdownTextInputDecoratorPair> nodesToUpdate;
|
|
75
|
-
MarkdownShadowFamilyRegistry::runForEveryFamily([&rootNode, &nodesToUpdate](
|
|
76
|
-
ShadowNodeFamily::Shared
|
|
77
|
-
family) {
|
|
78
|
-
// get the path from the root to the node from the decorator family
|
|
79
|
-
const auto ancestors = family->getAncestors(*rootNode);
|
|
80
|
-
|
|
81
|
-
if (!ancestors.empty()) {
|
|
82
|
-
auto &parentNode = ancestors.back().first.get();
|
|
83
|
-
auto index = ancestors.back().second;
|
|
84
|
-
|
|
85
|
-
// this is node represented by one of the registered families and since we
|
|
86
|
-
// only register markdown decorator shadow families, static casting should
|
|
87
|
-
// be safe here
|
|
88
|
-
const auto &decoratorNode =
|
|
89
|
-
std::static_pointer_cast<const MarkdownTextInputDecoratorShadowNode>(
|
|
90
|
-
parentNode.getChildren().at(index));
|
|
91
|
-
// text input always precedes the decorator component
|
|
92
|
-
const auto &previousSibling = parentNode.getChildren().at(index - 1);
|
|
93
|
-
|
|
94
|
-
if (const auto &textInputNode =
|
|
95
|
-
std::dynamic_pointer_cast<const TextInputShadowNode>(
|
|
96
|
-
previousSibling)) {
|
|
97
|
-
// store the pair of text input and decorator to update in the next step
|
|
98
|
-
// we need both, decorator to get markdown style and text input to
|
|
99
|
-
// update it
|
|
100
|
-
nodesToUpdate.push_back({
|
|
101
|
-
textInputNode,
|
|
102
|
-
decoratorNode,
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
for (const auto &nodes : nodesToUpdate) {
|
|
109
|
-
const auto &textInputState =
|
|
110
|
-
*std::static_pointer_cast<const ConcreteState<TextInputState>>(
|
|
111
|
-
nodes.textInput->getState());
|
|
112
|
-
const auto &stateData = textInputState.getData();
|
|
113
|
-
const auto fontSizeMultiplier =
|
|
114
|
-
newRootShadowNode->getConcreteProps().layoutContext.fontSizeMultiplier;
|
|
115
|
-
|
|
116
|
-
RCTMarkdownUtils *usedUtils = nil;
|
|
117
|
-
|
|
118
|
-
// We only want to update the shadow node when the attributed string is
|
|
119
|
-
// stored by value If it's stored by pointer, the markdown formatting should
|
|
120
|
-
// already by applied to it, since the only source of that pointer (besides
|
|
121
|
-
// this commit hook) is RCTTextInputComponentView, which has the relevant
|
|
122
|
-
// method swizzled to make sure the markdown styles are always applied
|
|
123
|
-
// before updating state. There are two caveats:
|
|
124
|
-
// 1. On the first render the swizzled method will not apply markdown since
|
|
125
|
-
// the native component
|
|
126
|
-
// is not mounted yet. In that case we save the tag to update in the
|
|
127
|
-
// method applying markdown formatting and apply it here instead,
|
|
128
|
-
// preventing wrong layout on reloads.
|
|
129
|
-
// 2. When the markdown style prop is changed, the native state needs to be
|
|
130
|
-
// updated to reflect
|
|
131
|
-
// them. In that case the relevant tag is saved in the registry when the
|
|
132
|
-
// new shadow node is created.
|
|
133
|
-
if (stateData.attributedStringBox.getMode() ==
|
|
134
|
-
AttributedStringBox::Mode::Value ||
|
|
135
|
-
MarkdownShadowFamilyRegistry::shouldForceUpdate(
|
|
136
|
-
nodes.textInput->getTag())) {
|
|
137
|
-
rootNode = rootNode->cloneTree(
|
|
138
|
-
nodes.textInput->getFamily(),
|
|
139
|
-
[&nodes, &textInputState, &stateData, &usedUtils,
|
|
140
|
-
fontSizeMultiplier](const ShadowNode &node) {
|
|
141
|
-
const auto &markdownProps = *std::static_pointer_cast<
|
|
142
|
-
MarkdownTextInputDecoratorViewProps const>(
|
|
143
|
-
nodes.decorator->getProps());
|
|
144
|
-
const auto &textInputProps =
|
|
145
|
-
*std::static_pointer_cast<TextInputProps const>(
|
|
146
|
-
nodes.textInput->getProps());
|
|
147
|
-
|
|
148
|
-
const auto defaultTextAttributes =
|
|
149
|
-
textInputProps.getEffectiveTextAttributes(fontSizeMultiplier);
|
|
150
|
-
const auto defaultNSTextAttributes =
|
|
151
|
-
RCTNSTextAttributesFromTextAttributes(defaultTextAttributes);
|
|
152
|
-
|
|
153
|
-
// this can possibly be optimized
|
|
154
|
-
RCTMarkdownStyle *markdownStyle = [[RCTMarkdownStyle alloc]
|
|
155
|
-
initWithStruct:markdownProps.markdownStyle];
|
|
156
|
-
usedUtils =
|
|
157
|
-
MarkdownCommitHook::getOrCreateMarkdownUtils(*nodes.decorator);
|
|
158
|
-
[usedUtils setMarkdownStyle:markdownStyle];
|
|
159
|
-
[usedUtils setParserId:@(markdownProps.parserId)];
|
|
160
|
-
|
|
161
|
-
// convert the attibuted string stored in state to
|
|
162
|
-
// NSAttributedString
|
|
163
|
-
auto nsAttributedString =
|
|
164
|
-
RCTNSAttributedStringFromAttributedStringBox(
|
|
165
|
-
stateData.attributedStringBox);
|
|
166
|
-
|
|
167
|
-
// Handles the first render, where the text stored in props is
|
|
168
|
-
// different than the one stored in state. The one in state is
|
|
169
|
-
// empty, while the one in props is passed from JS. If we don't
|
|
170
|
-
// update the state here, we'll end up with a one-default-line-sized
|
|
171
|
-
// text input
|
|
172
|
-
if (textInputState.getRevision() == State::initialRevisionValue) {
|
|
173
|
-
auto plainStringFromState =
|
|
174
|
-
std::string([[nsAttributedString string] UTF8String]);
|
|
175
|
-
|
|
176
|
-
if (plainStringFromState != textInputProps.text) {
|
|
177
|
-
// creates new AttributedString from props, adapted from
|
|
178
|
-
// TextInputShadowNode (ios one, text inputs are
|
|
179
|
-
// platform-specific)
|
|
180
|
-
auto attributedString = AttributedString{};
|
|
181
|
-
attributedString.appendFragment(AttributedString::Fragment{
|
|
182
|
-
textInputProps.text, defaultTextAttributes});
|
|
183
|
-
|
|
184
|
-
auto attachments = BaseTextShadowNode::Attachments{};
|
|
185
|
-
BaseTextShadowNode::buildAttributedString(
|
|
186
|
-
defaultTextAttributes, *nodes.textInput, attributedString,
|
|
187
|
-
attachments);
|
|
188
|
-
|
|
189
|
-
// convert the newly created attributed string to
|
|
190
|
-
// NSAttributedString
|
|
191
|
-
nsAttributedString =
|
|
192
|
-
RCTNSAttributedStringFromAttributedStringBox(
|
|
193
|
-
AttributedStringBox{attributedString});
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
// apply markdown
|
|
198
|
-
auto newString = [usedUtils parseMarkdown:nsAttributedString
|
|
199
|
-
withDefaultTextAttributes:defaultNSTextAttributes];
|
|
200
|
-
|
|
201
|
-
// create a clone of the old TextInputState and update the
|
|
202
|
-
// attributed string box to point to the string with markdown
|
|
203
|
-
// applied
|
|
204
|
-
auto newStateData = std::make_shared<TextInputState>(stateData);
|
|
205
|
-
newStateData->attributedStringBox =
|
|
206
|
-
RCTAttributedStringBoxFromNSAttributedString(newString);
|
|
207
|
-
|
|
208
|
-
// clone the text input with the new state
|
|
209
|
-
return node.clone({
|
|
210
|
-
.state = std::make_shared<const ConcreteState<TextInputState>>(
|
|
211
|
-
newStateData, textInputState),
|
|
212
|
-
});
|
|
213
|
-
});
|
|
214
|
-
} else if (stateData.attributedStringBox.getMode() ==
|
|
215
|
-
AttributedStringBox::Mode::OpaquePointer) {
|
|
216
|
-
rootNode = rootNode->cloneTree(
|
|
217
|
-
nodes.textInput->getFamily(),
|
|
218
|
-
[&nodes, &textInputState, &stateData, &usedUtils,
|
|
219
|
-
fontSizeMultiplier](const ShadowNode &node) {
|
|
220
|
-
const auto &markdownProps = *std::static_pointer_cast<
|
|
221
|
-
MarkdownTextInputDecoratorViewProps const>(
|
|
222
|
-
nodes.decorator->getProps());
|
|
223
|
-
const auto &textInputProps =
|
|
224
|
-
*std::static_pointer_cast<TextInputProps const>(
|
|
225
|
-
nodes.textInput->getProps());
|
|
226
|
-
|
|
227
|
-
const auto defaultTextAttributes =
|
|
228
|
-
textInputProps.getEffectiveTextAttributes(fontSizeMultiplier);
|
|
229
|
-
const auto defaultNSTextAttributes =
|
|
230
|
-
RCTNSTextAttributesFromTextAttributes(defaultTextAttributes);
|
|
231
|
-
|
|
232
|
-
// this can possibly be optimized
|
|
233
|
-
RCTMarkdownStyle *markdownStyle = [[RCTMarkdownStyle alloc]
|
|
234
|
-
initWithStruct:markdownProps.markdownStyle];
|
|
235
|
-
usedUtils =
|
|
236
|
-
MarkdownCommitHook::getOrCreateMarkdownUtils(*nodes.decorator);
|
|
237
|
-
[usedUtils setMarkdownStyle:markdownStyle];
|
|
238
|
-
[usedUtils setParserId:@(markdownProps.parserId)];
|
|
239
|
-
|
|
240
|
-
// convert the attibuted string stored in state to
|
|
241
|
-
// NSAttributedString
|
|
242
|
-
auto nsAttributedString =
|
|
243
|
-
RCTNSAttributedStringFromAttributedStringBox(
|
|
244
|
-
stateData.attributedStringBox);
|
|
245
|
-
|
|
246
|
-
// apply markdown
|
|
247
|
-
auto newString = [usedUtils parseMarkdown:nsAttributedString
|
|
248
|
-
withDefaultTextAttributes:defaultNSTextAttributes];
|
|
249
|
-
|
|
250
|
-
// create a clone of the old TextInputState and update the
|
|
251
|
-
// attributed string box to point to the string with markdown
|
|
252
|
-
// applied
|
|
253
|
-
auto newStateData = std::make_shared<TextInputState>(stateData);
|
|
254
|
-
newStateData->attributedStringBox =
|
|
255
|
-
RCTAttributedStringBoxFromNSAttributedString(newString);
|
|
256
|
-
|
|
257
|
-
// clone the text input with the new state
|
|
258
|
-
return node.clone({
|
|
259
|
-
.state = std::make_shared<const ConcreteState<TextInputState>>(
|
|
260
|
-
newStateData, textInputState),
|
|
261
|
-
});
|
|
262
|
-
});
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
// if usedUtils is not nil, then we did some work on the TextInput
|
|
266
|
-
// ShadowNode, we may need to update the decorator as well
|
|
267
|
-
if (usedUtils != nil) {
|
|
268
|
-
const auto ancestors =
|
|
269
|
-
nodes.decorator->getFamily().getAncestors(*rootNode);
|
|
270
|
-
const auto parentInfo = ancestors.back();
|
|
271
|
-
const auto decoratorNode =
|
|
272
|
-
std::static_pointer_cast<const MarkdownTextInputDecoratorShadowNode>(
|
|
273
|
-
parentInfo.first.get().getChildren().at(parentInfo.second));
|
|
274
|
-
|
|
275
|
-
// if usedUtils is defferent from the one kept in the decorator state, it
|
|
276
|
-
// needs to be updated to ensure memoization works correctly
|
|
277
|
-
if (usedUtils != MarkdownCommitHook::getMarkdownUtils(*decoratorNode)) {
|
|
278
|
-
const auto oldDecoratorState = *std::static_pointer_cast<
|
|
279
|
-
const ConcreteState<MarkdownTextInputDecoratorState>>(
|
|
280
|
-
decoratorNode->getState());
|
|
281
|
-
const auto newDecoratorState =
|
|
282
|
-
std::make_shared<const MarkdownTextInputDecoratorState>(
|
|
283
|
-
oldDecoratorState.getData().decoratorFamily,
|
|
284
|
-
wrapManagedObject(usedUtils));
|
|
285
|
-
const auto newDecoratorNode = decoratorNode->clone(
|
|
286
|
-
{.state = std::make_shared<
|
|
287
|
-
const ConcreteState<MarkdownTextInputDecoratorState>>(
|
|
288
|
-
newDecoratorState, oldDecoratorState)});
|
|
289
|
-
|
|
290
|
-
// since we did clone the path to the text input, parent node is mutable
|
|
291
|
-
// at this point - no need to clone the entire path
|
|
292
|
-
const auto mutableParent =
|
|
293
|
-
const_cast<ShadowNode *>(&parentInfo.first.get());
|
|
294
|
-
mutableParent->replaceChild(*decoratorNode, newDecoratorNode);
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
return std::static_pointer_cast<RootShadowNode>(rootNode);
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
} // namespace livemarkdown
|
|
303
|
-
} // namespace expensify
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
#include "MarkdownShadowFamilyRegistry.h"
|
|
2
|
-
|
|
3
|
-
namespace expensify {
|
|
4
|
-
namespace livemarkdown {
|
|
5
|
-
|
|
6
|
-
std::set<facebook::react::ShadowNodeFamily::Shared>
|
|
7
|
-
MarkdownShadowFamilyRegistry::familiesToUpdate_;
|
|
8
|
-
std::set<facebook::react::Tag> MarkdownShadowFamilyRegistry::forcedUpdates_;
|
|
9
|
-
std::mutex MarkdownShadowFamilyRegistry::mutex_;
|
|
10
|
-
|
|
11
|
-
void MarkdownShadowFamilyRegistry::registerFamilyForUpdates(
|
|
12
|
-
facebook::react::ShadowNodeFamily::Shared family) {
|
|
13
|
-
auto lock =
|
|
14
|
-
std::unique_lock<std::mutex>(MarkdownShadowFamilyRegistry::mutex_);
|
|
15
|
-
MarkdownShadowFamilyRegistry::familiesToUpdate_.insert(family);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
void MarkdownShadowFamilyRegistry::unregisterFamilyForUpdates(
|
|
19
|
-
facebook::react::ShadowNodeFamily::Shared family) {
|
|
20
|
-
auto lock =
|
|
21
|
-
std::unique_lock<std::mutex>(MarkdownShadowFamilyRegistry::mutex_);
|
|
22
|
-
MarkdownShadowFamilyRegistry::familiesToUpdate_.erase(family);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
void MarkdownShadowFamilyRegistry::reset() {
|
|
26
|
-
auto lock =
|
|
27
|
-
std::unique_lock<std::mutex>(MarkdownShadowFamilyRegistry::mutex_);
|
|
28
|
-
MarkdownShadowFamilyRegistry::familiesToUpdate_.clear();
|
|
29
|
-
MarkdownShadowFamilyRegistry::forcedUpdates_.clear();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
void MarkdownShadowFamilyRegistry::runForEveryFamily(
|
|
33
|
-
std::function<void(facebook::react::ShadowNodeFamily::Shared)> fun) {
|
|
34
|
-
auto lock =
|
|
35
|
-
std::unique_lock<std::mutex>(MarkdownShadowFamilyRegistry::mutex_);
|
|
36
|
-
for (auto &family : MarkdownShadowFamilyRegistry::familiesToUpdate_) {
|
|
37
|
-
fun(family);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
void MarkdownShadowFamilyRegistry::forceNextStateUpdate(
|
|
42
|
-
facebook::react::Tag tag) {
|
|
43
|
-
auto lock =
|
|
44
|
-
std::unique_lock<std::mutex>(MarkdownShadowFamilyRegistry::mutex_);
|
|
45
|
-
forcedUpdates_.insert(tag);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
bool MarkdownShadowFamilyRegistry::shouldForceUpdate(facebook::react::Tag tag) {
|
|
49
|
-
auto lock =
|
|
50
|
-
std::unique_lock<std::mutex>(MarkdownShadowFamilyRegistry::mutex_);
|
|
51
|
-
bool force = forcedUpdates_.contains(tag);
|
|
52
|
-
if (force) {
|
|
53
|
-
forcedUpdates_.erase(tag);
|
|
54
|
-
return true;
|
|
55
|
-
}
|
|
56
|
-
return false;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
} // namespace livemarkdown
|
|
60
|
-
} // namespace expensify
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include <react/renderer/core/ShadowNodeFamily.h>
|
|
4
|
-
|
|
5
|
-
#include <mutex>
|
|
6
|
-
#include <set>
|
|
7
|
-
|
|
8
|
-
namespace expensify {
|
|
9
|
-
namespace livemarkdown {
|
|
10
|
-
|
|
11
|
-
// A registry to store pointers to the ShadowNodeFamilies of markdown
|
|
12
|
-
// decorators. The only place we can _legally_ access the family of shadow node
|
|
13
|
-
// is in the constructor and we need it inside commit hook. To achieve it, we
|
|
14
|
-
// use this simple registry where families are registered when nodes are created
|
|
15
|
-
// and cleaned up when native view is removed from window or when a turbomodule
|
|
16
|
-
// is deallocated.
|
|
17
|
-
|
|
18
|
-
class MarkdownShadowFamilyRegistry {
|
|
19
|
-
public:
|
|
20
|
-
static void
|
|
21
|
-
registerFamilyForUpdates(facebook::react::ShadowNodeFamily::Shared family);
|
|
22
|
-
static void
|
|
23
|
-
unregisterFamilyForUpdates(facebook::react::ShadowNodeFamily::Shared family);
|
|
24
|
-
static void reset();
|
|
25
|
-
static void runForEveryFamily(
|
|
26
|
-
std::function<void(facebook::react::ShadowNodeFamily::Shared family)>
|
|
27
|
-
fun);
|
|
28
|
-
static void forceNextStateUpdate(facebook::react::Tag tag);
|
|
29
|
-
static bool shouldForceUpdate(facebook::react::Tag tag);
|
|
30
|
-
|
|
31
|
-
private:
|
|
32
|
-
static std::set<facebook::react::ShadowNodeFamily::Shared> familiesToUpdate_;
|
|
33
|
-
static std::set<facebook::react::Tag> forcedUpdates_;
|
|
34
|
-
static std::mutex mutex_;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
} // namespace livemarkdown
|
|
38
|
-
} // namespace expensify
|
package/cpp/react/renderer/components/RNLiveMarkdownSpec/MarkdownTextInputDecoratorShadowNode.cpp
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
#include "MarkdownTextInputDecoratorShadowNode.h"
|
|
2
|
-
|
|
3
|
-
using namespace expensify::livemarkdown;
|
|
4
|
-
|
|
5
|
-
namespace facebook {
|
|
6
|
-
namespace react {
|
|
7
|
-
|
|
8
|
-
extern const char MarkdownTextInputDecoratorViewComponentName[] =
|
|
9
|
-
"MarkdownTextInputDecoratorView";
|
|
10
|
-
|
|
11
|
-
const OwningShadowNodeFragment
|
|
12
|
-
MarkdownTextInputDecoratorShadowNode::updateFragmentState(
|
|
13
|
-
ShadowNodeFragment const &fragment,
|
|
14
|
-
ShadowNodeFamily::Shared const &family) {
|
|
15
|
-
const auto newStateData =
|
|
16
|
-
std::make_shared<MarkdownTextInputDecoratorState>(family);
|
|
17
|
-
|
|
18
|
-
MarkdownShadowFamilyRegistry::registerFamilyForUpdates(family);
|
|
19
|
-
|
|
20
|
-
// we pass the pointer to the ShadowNodeFamily in the initial state, so it's
|
|
21
|
-
// propagated on every clone we need it to clear the reference in the registry
|
|
22
|
-
// when the view is removed from window it cannot be done in the destructor,
|
|
23
|
-
// as multiple shadow nodes for the same family may be created
|
|
24
|
-
return OwningShadowNodeFragment{
|
|
25
|
-
.props = fragment.props,
|
|
26
|
-
.children = fragment.children,
|
|
27
|
-
.state =
|
|
28
|
-
std::make_shared<const ConcreteState>(newStateData, *fragment.state),
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
} // namespace react
|
|
33
|
-
} // namespace facebook
|
package/cpp/react/renderer/components/RNLiveMarkdownSpec/MarkdownTextInputDecoratorShadowNode.h
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include "MarkdownShadowFamilyRegistry.h"
|
|
4
|
-
#include "MarkdownTextInputDecoratorState.h"
|
|
5
|
-
#include "OwningShadowNodeFragment.h"
|
|
6
|
-
#include <react/renderer/components/RNLiveMarkdownSpec/EventEmitters.h>
|
|
7
|
-
#include <react/renderer/components/RNLiveMarkdownSpec/Props.h>
|
|
8
|
-
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
|
|
9
|
-
|
|
10
|
-
using namespace expensify::livemarkdown;
|
|
11
|
-
|
|
12
|
-
namespace facebook {
|
|
13
|
-
namespace react {
|
|
14
|
-
|
|
15
|
-
JSI_EXPORT extern const char MarkdownTextInputDecoratorViewComponentName[];
|
|
16
|
-
|
|
17
|
-
class JSI_EXPORT MarkdownTextInputDecoratorShadowNode final
|
|
18
|
-
: public ConcreteViewShadowNode<MarkdownTextInputDecoratorViewComponentName,
|
|
19
|
-
MarkdownTextInputDecoratorViewProps,
|
|
20
|
-
MarkdownTextInputDecoratorViewEventEmitter,
|
|
21
|
-
MarkdownTextInputDecoratorState> {
|
|
22
|
-
public:
|
|
23
|
-
MarkdownTextInputDecoratorShadowNode(ShadowNodeFragment const &fragment,
|
|
24
|
-
ShadowNodeFamily::Shared const &family,
|
|
25
|
-
ShadowNodeTraits traits)
|
|
26
|
-
: ConcreteViewShadowNode(updateFragmentState(fragment, family),
|
|
27
|
-
family, traits) {}
|
|
28
|
-
|
|
29
|
-
MarkdownTextInputDecoratorShadowNode(ShadowNode const &sourceShadowNode,
|
|
30
|
-
ShadowNodeFragment const &fragment)
|
|
31
|
-
: ConcreteViewShadowNode(sourceShadowNode, fragment) {
|
|
32
|
-
// if the props changed, we need to update the shadow node state to reflect
|
|
33
|
-
// potential style changes
|
|
34
|
-
if (fragment.props != ShadowNodeFragment::propsPlaceholder()) {
|
|
35
|
-
MarkdownShadowFamilyRegistry::forceNextStateUpdate(this->getTag());
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
private:
|
|
40
|
-
static const OwningShadowNodeFragment
|
|
41
|
-
updateFragmentState(ShadowNodeFragment const &fragment,
|
|
42
|
-
ShadowNodeFamily::Shared const &family);
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
} // namespace react
|
|
46
|
-
} // namespace facebook
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include <react/renderer/core/Props.h>
|
|
4
|
-
#include <react/renderer/core/ShadowNode.h>
|
|
5
|
-
#include <react/renderer/core/ShadowNodeFragment.h>
|
|
6
|
-
#include <react/renderer/core/State.h>
|
|
7
|
-
|
|
8
|
-
using namespace facebook::react;
|
|
9
|
-
|
|
10
|
-
namespace expensify {
|
|
11
|
-
namespace livemarkdown {
|
|
12
|
-
|
|
13
|
-
struct OwningShadowNodeFragment {
|
|
14
|
-
Props::Shared props;
|
|
15
|
-
ShadowNode::SharedListOfShared children;
|
|
16
|
-
State::Shared state;
|
|
17
|
-
|
|
18
|
-
operator ShadowNodeFragment() const {
|
|
19
|
-
return ShadowNodeFragment {
|
|
20
|
-
.props = props,
|
|
21
|
-
.children = children,
|
|
22
|
-
.state = state
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
} // namespace livemarkdown
|
|
28
|
-
} // namespace expensify
|