@@ -291,50 +291,6 @@ - (void)setupPlaceholderLabel {
291291 _placeholderLabel.adjustsFontForContentSizeCategory = YES ;
292292}
293293
294- // MARK: - Paragraph style helpers
295-
296- - (void )applyLineHeight : (NSMutableDictionary *)typingAttributes {
297- CGFloat rawLineHeight = [config primaryLineHeight ];
298- NSUInteger length = textView.textStorage .string .length ;
299- if (length == 0 ) {
300- return ;
301- }
302-
303- CGFloat scaledLineHeight = 0 ;
304- if (rawLineHeight > 0 ) {
305- // Scale lineHeight with the same Dynamic Type factor used for font sizes.
306- scaledLineHeight =
307- [[UIFontMetrics defaultMetrics ] scaledValueForValue: rawLineHeight];
308- }
309-
310- NSRange fullRange = NSMakeRange (0 , length);
311-
312- // apply lineHeight over the entire text storage content
313- [textView.textStorage
314- enumerateAttribute: NSParagraphStyleAttributeName
315- inRange: fullRange
316- options: 0
317- usingBlock: ^(id _Nullable value, NSRange range,
318- BOOL *_Nonnull stop) {
319- NSMutableParagraphStyle *pStyle;
320- if (value != nil ) {
321- pStyle = [(NSParagraphStyle *)value mutableCopy ];
322- } else {
323- pStyle = [[NSMutableParagraphStyle alloc ] init ];
324- }
325- pStyle.minimumLineHeight = scaledLineHeight;
326- [textView.textStorage addAttribute: NSParagraphStyleAttributeName
327- value: pStyle
328- range: range];
329- }];
330-
331- // apply lineHeight to typing attributes
332- NSMutableParagraphStyle *paragraphStyle =
333- [[NSMutableParagraphStyle alloc ] init ];
334- paragraphStyle.minimumLineHeight = scaledLineHeight;
335- typingAttributes[NSParagraphStyleAttributeName ] = paragraphStyle;
336- }
337-
338294// MARK: - Props
339295
340296- (void )updateProps : (Props::Shared const &)props
@@ -781,10 +737,16 @@ - (void)updateProps:(Props::Shared const &)props
781737 [config primaryColor ];
782738 defaultTypingAttributes[NSStrikethroughColorAttributeName ] =
783739 [config primaryColor ];
784- [self applyLineHeight: defaultTypingAttributes];
740+ NSMutableParagraphStyle *defaultPStyle =
741+ [[NSMutableParagraphStyle alloc ] init ];
742+ defaultPStyle.minimumLineHeight = [config scaledPrimaryLineHeight ];
743+ defaultTypingAttributes[NSParagraphStyleAttributeName ] = defaultPStyle;
744+
785745 textView.typingAttributes = defaultTypingAttributes;
786746 textView.selectedRange = prevSelectedRange;
787747
748+ // make sure the newest lineHeight is applied
749+ [self refreshLineHeight ];
788750 // update the placeholder as well
789751 [self refreshPlaceholderLabelStyles ];
790752 }
@@ -954,6 +916,24 @@ - (void)refreshPlaceholderLabelStyles {
954916 _placeholderLabel.attributedText = newAttrStr;
955917}
956918
919+ - (void )refreshLineHeight {
920+ [textView.textStorage
921+ enumerateAttribute: NSParagraphStyleAttributeName
922+ inRange: NSMakeRange (0 , textView.textStorage.string.length)
923+ options: 0
924+ usingBlock: ^(id _Nullable value, NSRange range,
925+ BOOL *_Nonnull stop) {
926+ NSMutableParagraphStyle *pStyle =
927+ [(NSParagraphStyle *)value mutableCopy ];
928+ if (pStyle == nil )
929+ return ;
930+ pStyle.minimumLineHeight = [config scaledPrimaryLineHeight ];
931+ [textView.textStorage addAttribute: NSParagraphStyleAttributeName
932+ value: pStyle
933+ range: range];
934+ }];
935+ }
936+
957937// MARK: - Measuring and states
958938
959939- (CGSize)measureSize : (CGFloat)maxWidth {
0 commit comments