Skip to content

Commit 2fac993

Browse files
committed
feat(ios): add support for H5 styling in RichTextView
1 parent b1a73a1 commit 2fac993

7 files changed

Lines changed: 63 additions & 5 deletions

File tree

ios/RichTextView.mm

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,21 @@ - (void)updateProps:(Props::Shared const &)props
231231
stylePropChanged = YES;
232232
}
233233

234+
if (newViewProps.richTextStyle.h5.fontSize != oldViewProps.richTextStyle.h5.fontSize) {
235+
[newConfig setH5FontSize:newViewProps.richTextStyle.h5.fontSize];
236+
stylePropChanged = YES;
237+
}
238+
239+
if (newViewProps.richTextStyle.h5.fontFamily != oldViewProps.richTextStyle.h5.fontFamily) {
240+
if (!newViewProps.richTextStyle.h5.fontFamily.empty()) {
241+
NSString *fontFamily = [[NSString alloc] initWithUTF8String:newViewProps.richTextStyle.h5.fontFamily.c_str()];
242+
[newConfig setH5FontFamily:fontFamily];
243+
} else {
244+
[newConfig setH5FontFamily:nullptr];
245+
}
246+
stylePropChanged = YES;
247+
}
248+
234249
if (stylePropChanged) {
235250
NSString *currentMarkdown = [[NSString alloc] initWithUTF8String:newViewProps.markdown.c_str()];
236251

ios/config/RichTextConfig.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@
3333
- (void)setH4FontSize:(CGFloat)newValue;
3434
- (NSString *)h4FontFamily;
3535
- (void)setH4FontFamily:(NSString *)newValue;
36+
// H5 properties
37+
- (CGFloat)h5FontSize;
38+
- (void)setH5FontSize:(CGFloat)newValue;
39+
- (NSString *)h5FontFamily;
40+
- (void)setH5FontFamily:(NSString *)newValue;
3641

37-
// Future: H5, H6, link, paragraph properties
42+
// Future: H6, link, paragraph properties
3843
@end

ios/config/RichTextConfig.mm

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ @implementation RichTextConfig {
2121
// H4 properties
2222
CGFloat _h4FontSize;
2323
NSString *_h4FontFamily;
24+
// H5 properties
25+
CGFloat _h5FontSize;
26+
NSString *_h5FontFamily;
2427
}
2528

2629
- (instancetype)init {
@@ -45,6 +48,8 @@ - (id)copyWithZone:(NSZone *)zone {
4548
copy->_h3FontFamily = [_h3FontFamily copy];
4649
copy->_h4FontSize = _h4FontSize;
4750
copy->_h4FontFamily = [_h4FontFamily copy];
51+
copy->_h5FontSize = _h5FontSize;
52+
copy->_h5FontFamily = [_h5FontFamily copy];
4853

4954
return copy;
5055
}
@@ -162,4 +167,20 @@ - (void)setH4FontFamily:(NSString *)newValue {
162167
_h4FontFamily = newValue;
163168
}
164169

170+
- (CGFloat)h5FontSize {
171+
return _h5FontSize > 0 ? _h5FontSize : 18.0;
172+
}
173+
174+
- (void)setH5FontSize:(CGFloat)newValue {
175+
_h5FontSize = newValue;
176+
}
177+
178+
- (NSString *)h5FontFamily {
179+
return _h5FontFamily;
180+
}
181+
182+
- (void)setH5FontFamily:(NSString *)newValue {
183+
_h5FontFamily = newValue;
184+
}
185+
165186
@end

ios/styles/HeadingStyle.mm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ - (CGFloat)fontSize {
2020
case 2: return [_config h2FontSize];
2121
case 3: return [_config h3FontSize];
2222
case 4: return [_config h4FontSize];
23-
// Future: Add H5-H6 support
24-
// case 5: return [_config h5FontSize];
23+
case 5: return [_config h5FontSize];
24+
// Future: Add H6 support
2525
// case 6: return [_config h6FontSize];
2626
default: return 32.0; // Default heading size
2727
}
@@ -33,8 +33,8 @@ - (NSString *)fontFamily {
3333
case 2: return [_config h2FontFamily];
3434
case 3: return [_config h3FontFamily];
3535
case 4: return [_config h4FontFamily];
36-
// Future: Add H5-H6 support
37-
// case 5: return [_config h5FontFamily];
36+
case 5: return [_config h5FontFamily];
37+
// Future: Add H6 support
3838
// case 6: return [_config h6FontFamily];
3939
default: return nil;
4040
}

src/RichTextView.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ export interface RichTextStyle {
2222
fontSize?: number;
2323
fontFamily?: string;
2424
};
25+
h5?: {
26+
fontSize?: number;
27+
fontFamily?: string;
28+
};
2529
}
2630

2731
export interface RichTextViewProps

src/RichTextViewNativeComponent.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ export interface RichTextStyleInternal {
2222
fontSize?: CodegenTypes.Float;
2323
fontFamily?: string;
2424
};
25+
h5?: {
26+
fontSize?: CodegenTypes.Float;
27+
fontFamily?: string;
28+
};
2529
}
2630

2731
export interface NativeProps extends ViewProps {

src/normalizeRichTextStyle.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ const defaultH4Style: RichTextStyleInternal['h4'] = {
2121
fontFamily: 'Helvetica-Bold',
2222
};
2323

24+
const defaultH5Style: RichTextStyleInternal['h5'] = {
25+
fontSize: 18,
26+
fontFamily: 'Helvetica-Bold',
27+
};
28+
2429
export const normalizeRichTextStyle = (
2530
style: RichTextStyle
2631
): RichTextStyleInternal => {
@@ -41,5 +46,9 @@ export const normalizeRichTextStyle = (
4146
...defaultH4Style,
4247
...style.h4,
4348
},
49+
h5: {
50+
...defaultH5Style,
51+
...style.h5,
52+
},
4453
};
4554
};

0 commit comments

Comments
 (0)