@expensify/react-native-live-markdown 0.1.141 → 0.1.142

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.
@@ -169,6 +169,53 @@ RootShadowNode::Unshared MarkdownCommitHook::shadowTreeWillCommit(
169
169
  }
170
170
  }
171
171
 
172
+ // apply markdown
173
+ auto newString = [utils parseMarkdown:nsAttributedString
174
+ withAttributes:defaultNSTextAttributes];
175
+
176
+ // create a clone of the old TextInputState and update the
177
+ // attributed string box to point to the string with markdown
178
+ // applied
179
+ auto newStateData = std::make_shared<TextInputState>(stateData);
180
+ newStateData->attributedStringBox =
181
+ RCTAttributedStringBoxFromNSAttributedString(newString);
182
+
183
+ // clone the text input with the new state
184
+ return node.clone({
185
+ .state = std::make_shared<const ConcreteState<TextInputState>>(
186
+ newStateData, textInputState),
187
+ });
188
+ });
189
+ } else if (stateData.attributedStringBox.getMode() ==
190
+ AttributedStringBox::Mode::OpaquePointer) {
191
+ rootNode = rootNode->cloneTree(
192
+ nodes.textInput->getFamily(),
193
+ [&nodes, &textInputState, &stateData,
194
+ fontSizeMultiplier](const ShadowNode &node) {
195
+ const auto &markdownProps = *std::static_pointer_cast<
196
+ MarkdownTextInputDecoratorViewProps const>(
197
+ nodes.decorator->getProps());
198
+ const auto &textInputProps =
199
+ *std::static_pointer_cast<TextInputProps const>(
200
+ nodes.textInput->getProps());
201
+
202
+ const auto defaultTextAttributes =
203
+ textInputProps.getEffectiveTextAttributes(fontSizeMultiplier);
204
+ const auto defaultNSTextAttributes =
205
+ RCTNSTextAttributesFromTextAttributes(defaultTextAttributes);
206
+
207
+ // this can possibly be optimized
208
+ RCTMarkdownStyle *markdownStyle = [[RCTMarkdownStyle alloc]
209
+ initWithStruct:markdownProps.markdownStyle];
210
+ RCTMarkdownUtils *utils = [[RCTMarkdownUtils alloc] init];
211
+ [utils setMarkdownStyle:markdownStyle];
212
+
213
+ // convert the attibuted string stored in state to
214
+ // NSAttributedString
215
+ auto nsAttributedString =
216
+ RCTNSAttributedStringFromAttributedStringBox(
217
+ stateData.attributedStringBox);
218
+
172
219
  // apply markdown
173
220
  auto newString = [utils parseMarkdown:nsAttributedString
174
221
  withAttributes:defaultNSTextAttributes];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@expensify/react-native-live-markdown",
3
- "version": "0.1.141",
3
+ "version": "0.1.142",
4
4
  "description": "Drop-in replacement for React Native's TextInput component with Markdown formatting.",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",