Commit 8b5a5d4 1 parent f595a4e commit 8b5a5d4 Copy full SHA for 8b5a5d4
File tree 3 files changed +42
-1
lines changed
packages/rn-tester/js/examples/Text
3 files changed +42
-1
lines changed Original file line number Diff line number Diff line change @@ -237,6 +237,23 @@ - (UIColor *)effectiveBackgroundColor
237
237
return effectiveBackgroundColor ?: [UIColor clearColor ];
238
238
}
239
239
240
+ static NSString *capitalizeText (NSString *text)
241
+ {
242
+ NSArray *words = [text componentsSeparatedByString: @" " ];
243
+ NSMutableArray *newWords = [NSMutableArray new ];
244
+ NSNumberFormatter *num = [NSNumberFormatter new ];
245
+ for (NSString *item in words) {
246
+ NSString *word;
247
+ if ([item length ] > 0 && [num numberFromString: [item substringWithRange: NSMakeRange (0 , 1 )]] == nil ) {
248
+ word = [item capitalizedString ];
249
+ } else {
250
+ word = [item lowercaseString ];
251
+ }
252
+ [newWords addObject: word];
253
+ }
254
+ return [newWords componentsJoinedByString: @" " ];
255
+ }
256
+
240
257
- (NSString *)applyTextAttributesToText : (NSString *)text
241
258
{
242
259
switch (_textTransform) {
@@ -248,7 +265,7 @@ - (NSString *)applyTextAttributesToText:(NSString *)text
248
265
case RCTTextTransformUppercase:
249
266
return [text uppercaseString ];
250
267
case RCTTextTransformCapitalize:
251
- return [ text capitalizedString ] ;
268
+ return capitalizeText ( text) ;
252
269
}
253
270
}
254
271
Original file line number Diff line number Diff line change @@ -798,6 +798,18 @@ class TextExample extends React.Component<{...}> {
798
798
< Text style = { { textTransform : 'capitalize' } } >
799
799
This text should be CAPITALIZED.
800
800
</ Text >
801
+ < Text >
802
+ Capitalize a date:
803
+ < Text style = { { textTransform : 'capitalize' } } >
804
+ the 9th of november, 1998
805
+ </ Text >
806
+ </ Text >
807
+ < Text >
808
+ Capitalize a 2 digit date:
809
+ < Text style = { { textTransform : 'capitalize' } } >
810
+ the 25th of december
811
+ </ Text >
812
+ </ Text >
801
813
< Text style = { { textTransform : 'capitalize' } } >
802
814
Mixed: < Text style = { { textTransform : 'uppercase' } } > uppercase </ Text >
803
815
< Text style = { { textTransform : 'lowercase' } } > LoWeRcAsE </ Text >
Original file line number Diff line number Diff line change @@ -1160,6 +1160,18 @@ exports.examples = [
1160
1160
< Text style = { { textTransform : 'capitalize' } } >
1161
1161
This text should be CAPITALIZED.
1162
1162
</ Text >
1163
+ < Text >
1164
+ Capitalize a date:
1165
+ < Text style = { { textTransform : 'capitalize' } } >
1166
+ the 9th of november, 1998
1167
+ </ Text >
1168
+ </ Text >
1169
+ < Text >
1170
+ Capitalize a 2 digit date:
1171
+ < Text style = { { textTransform : 'capitalize' } } >
1172
+ the 25th of december
1173
+ </ Text >
1174
+ </ Text >
1163
1175
< Text style = { { textTransform : 'capitalize' } } >
1164
1176
Mixed: < Text style = { { textTransform : 'uppercase' } } > uppercase </ Text >
1165
1177
< Text style = { { textTransform : 'lowercase' } } > LoWeRcAsE </ Text >
You can’t perform that action at this time.
0 commit comments