@expensify/react-native-live-markdown 0.1.75 → 0.1.76

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.
@@ -136,6 +136,8 @@
136
136
  }
137
137
  }];
138
138
 
139
+ RCTApplyBaselineOffset(attributedString);
140
+
139
141
  [attributedString endEditing];
140
142
 
141
143
  _prevInputString = inputString;
@@ -148,4 +150,47 @@
148
150
  }
149
151
  }
150
152
 
153
+ static void RCTApplyBaselineOffset(NSMutableAttributedString *attributedText)
154
+ {
155
+ __block CGFloat maximumLineHeight = 0;
156
+
157
+ [attributedText enumerateAttribute:NSParagraphStyleAttributeName
158
+ inRange:NSMakeRange(0, attributedText.length)
159
+ options:NSAttributedStringEnumerationLongestEffectiveRangeNotRequired
160
+ usingBlock:^(NSParagraphStyle *paragraphStyle, __unused NSRange range, __unused BOOL *stop) {
161
+ if (!paragraphStyle) {
162
+ return;
163
+ }
164
+
165
+ maximumLineHeight = MAX(paragraphStyle.maximumLineHeight, maximumLineHeight);
166
+ }];
167
+
168
+ if (maximumLineHeight == 0) {
169
+ // `lineHeight` was not specified, nothing to do.
170
+ return;
171
+ }
172
+
173
+ __block CGFloat maximumFontLineHeight = 0;
174
+
175
+ [attributedText enumerateAttribute:NSFontAttributeName
176
+ inRange:NSMakeRange(0, attributedText.length)
177
+ options:NSAttributedStringEnumerationLongestEffectiveRangeNotRequired
178
+ usingBlock:^(UIFont *font, NSRange range, __unused BOOL *stop) {
179
+ if (!font) {
180
+ return;
181
+ }
182
+
183
+ maximumFontLineHeight = MAX(font.lineHeight, maximumFontLineHeight);
184
+ }];
185
+
186
+ if (maximumLineHeight < maximumFontLineHeight) {
187
+ return;
188
+ }
189
+
190
+ CGFloat baseLineOffset = (maximumLineHeight - maximumFontLineHeight) / 2.0;
191
+ [attributedText addAttribute:NSBaselineOffsetAttributeName
192
+ value:@(baseLineOffset)
193
+ range:NSMakeRange(0, attributedText.length)];
194
+ }
195
+
151
196
  @end
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@expensify/react-native-live-markdown",
3
- "version": "0.1.75",
3
+ "version": "0.1.76",
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",