@expensify/react-native-live-markdown 0.1.99 → 0.1.101

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.
@@ -141,30 +141,31 @@ RootShadowNode::Unshared MarkdownCommitHook::shadowTreeWillCommit(
141
141
  stateData.attributedStringBox);
142
142
 
143
143
  // Handles the first render, where the text stored in props is
144
- // different than the one stored in state The one in state is empty,
145
- // while the one in props is passed from JS If we don't update the
146
- // state here, we'll end up with a one-default-line-sized text
147
- // input. A better condition to do that can be probably chosen, but
148
- // this seems to work
149
- auto plainString =
150
- std::string([[nsAttributedString string] UTF8String]);
151
- if (plainString != textInputProps.text) {
152
- // creates new AttributedString from props, adapted from
153
- // TextInputShadowNode (ios one, text inputs are
154
- // platform-specific)
155
- auto attributedString = AttributedString{};
156
- attributedString.appendFragment(AttributedString::Fragment{
157
- textInputProps.text, defaultTextAttributes});
158
-
159
- auto attachments = BaseTextShadowNode::Attachments{};
160
- BaseTextShadowNode::buildAttributedString(
161
- defaultTextAttributes, *nodes.textInput, attributedString,
162
- attachments);
163
-
164
- // convert the newly created attributed string to
165
- // NSAttributedString
166
- nsAttributedString = RCTNSAttributedStringFromAttributedStringBox(
167
- AttributedStringBox{attributedString});
144
+ // different than the one stored in state. The one in state is empty,
145
+ // while the one in props is passed from JS. If we don't update the
146
+ // state here, we'll end up with a one-default-line-sized text input
147
+ if (textInputState.getRevision() == State::initialRevisionValue) {
148
+ auto plainStringFromState =
149
+ std::string([[nsAttributedString string] UTF8String]);
150
+
151
+ if (plainStringFromState != textInputProps.text) {
152
+ // creates new AttributedString from props, adapted from
153
+ // TextInputShadowNode (ios one, text inputs are
154
+ // platform-specific)
155
+ auto attributedString = AttributedString{};
156
+ attributedString.appendFragment(AttributedString::Fragment{
157
+ textInputProps.text, defaultTextAttributes});
158
+
159
+ auto attachments = BaseTextShadowNode::Attachments{};
160
+ BaseTextShadowNode::buildAttributedString(
161
+ defaultTextAttributes, *nodes.textInput, attributedString,
162
+ attachments);
163
+
164
+ // convert the newly created attributed string to
165
+ // NSAttributedString
166
+ nsAttributedString = RCTNSAttributedStringFromAttributedStringBox(
167
+ AttributedStringBox{attributedString});
168
+ }
168
169
  }
169
170
 
170
171
  // apply markdown
@@ -28,6 +28,9 @@ using namespace facebook;
28
28
  }
29
29
 
30
30
  static std::shared_ptr<jsi::Runtime> runtime;
31
+ static std::mutex runtimeMutex;
32
+ auto lock = std::lock_guard<std::mutex>(runtimeMutex);
33
+
31
34
  if (runtime == nullptr) {
32
35
  NSString *path = [[NSBundle mainBundle] pathForResource:@"react-native-live-markdown-parser" ofType:@"js"];
33
36
  assert(path != nil && "[react-native-live-markdown] Markdown parser bundle not found");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@expensify/react-native-live-markdown",
3
- "version": "0.1.99",
3
+ "version": "0.1.101",
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",