Skip to content

Commit

Permalink
[WIP] Added support for italics and additional font weights
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklockwood committed Mar 26, 2015
1 parent d131e1e commit f124c32
Show file tree
Hide file tree
Showing 25 changed files with 219 additions and 111 deletions.
4 changes: 2 additions & 2 deletions Examples/2048/Game2048.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ var styles = StyleSheet.create({
tryAgainText: {
color: '#ffffff',
fontSize: 20,
fontWeight: 'bold',
fontWeight: '500',
},
cell: {
width: CELL_SIZE,
Expand All @@ -259,7 +259,7 @@ var styles = StyleSheet.create({
fontSize: 24,
color: '#776666',
fontFamily: 'Verdana',
fontWeight: 'bold',
fontWeight: '500',
},
tile2: {
backgroundColor: '#eeeeee',
Expand Down
2 changes: 1 addition & 1 deletion Examples/Movies/MovieCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ var styles = StyleSheet.create({
movieTitle: {
flex: 1,
fontSize: 16,
fontWeight: 'bold',
fontWeight: '500',
marginBottom: 2,
},
movieYear: {
Expand Down
8 changes: 4 additions & 4 deletions Examples/Movies/MovieScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ var styles = StyleSheet.create({
movieTitle: {
flex: 1,
fontSize: 16,
fontWeight: 'bold',
fontWeight: '500',
},
rating: {
marginTop: 10,
Expand All @@ -119,7 +119,7 @@ var styles = StyleSheet.create({
},
ratingValue: {
fontSize: 28,
fontWeight: 'bold',
fontWeight: '500',
},
mpaaWrapper: {
alignSelf: 'flex-start',
Expand All @@ -131,7 +131,7 @@ var styles = StyleSheet.create({
mpaaText: {
fontFamily: 'Palatino',
fontSize: 13,
fontWeight: 'bold',
fontWeight: '500',
},
mainSection: {
flexDirection: 'row',
Expand All @@ -148,7 +148,7 @@ var styles = StyleSheet.create({
marginVertical: 10,
},
castTitle: {
fontWeight: 'bold',
fontWeight: '500',
marginBottom: 3,
},
castActor: {
Expand Down
2 changes: 1 addition & 1 deletion Examples/UIExplorer/ActionSheetIOSExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ var ShareActionSheetExample = React.createClass({
var style = StyleSheet.create({
button: {
marginBottom: 10,
fontWeight: 'bold',
fontWeight: '500',
}
});

Expand Down
2 changes: 1 addition & 1 deletion Examples/UIExplorer/AdSupportIOSExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,6 @@ var AdSupportIOSExample = React.createClass({

var styles = StyleSheet.create({
title: {
fontWeight: 'bold',
fontWeight: '500',
},
});
4 changes: 2 additions & 2 deletions Examples/UIExplorer/DatePickerExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,14 @@ var styles = StyleSheet.create({
paddingVertical: 2,
},
label: {
fontWeight: 'bold',
fontWeight: '500',
},
headingContainer: {
padding: 4,
backgroundColor: '#f6f7f8',
},
heading: {
fontWeight: 'bold',
fontWeight: '500',
fontSize: 14,
},
});
2 changes: 1 addition & 1 deletion Examples/UIExplorer/GeolocationExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ var GeolocationExample = React.createClass({

var styles = StyleSheet.create({
title: {
fontWeight: 'bold',
fontWeight: '500',
},
});
2 changes: 1 addition & 1 deletion Examples/UIExplorer/NavigatorIOSExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ var styles = StyleSheet.create({
},
rowText: {
fontSize: 17,
fontWeight: 'bold',
fontWeight: '500',
},
});

Expand Down
2 changes: 1 addition & 1 deletion Examples/UIExplorer/ReactNavigator/BreadcrumbNavSample.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ var styles = StyleSheet.create({
fontSize: 18,
color: '#666666',
textAlign: 'center',
fontWeight: 'bold',
fontWeight: '500',
lineHeight: 32,
},
filterText: {
Expand Down
2 changes: 1 addition & 1 deletion Examples/UIExplorer/ReactNavigator/NavigationBarSample.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ var styles = StyleSheet.create({
},
navBarTitleText: {
color: cssVar('fbui-bluegray-60'),
fontWeight: 'bold',
fontWeight: '500',
marginVertical: 9,
},
navBarButtonText: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ var styles = StyleSheet.create({
fontSize: 18,
color: '#666666',
textAlign: 'center',
fontWeight: 'bold',
fontWeight: '500',
lineHeight: 32,
},
filterText: {
Expand Down
2 changes: 1 addition & 1 deletion Examples/UIExplorer/SliderIOSExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var styles = StyleSheet.create({
text: {
fontSize: 14,
textAlign: 'center',
fontWeight: 'bold',
fontWeight: '500',
margin: 10,
},
});
Expand Down
38 changes: 33 additions & 5 deletions Examples/UIExplorer/TextExample.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var Entity = React.createClass({

var AttributeToggler = React.createClass({
getInitialState: function() {
return {fontWeight: 'bold', fontSize: 15};
return {fontWeight: '500', fontSize: 15};
},
increaseSize: function() {
this.setState({
Expand Down Expand Up @@ -129,9 +129,37 @@ exports.examples = [
title: 'Font Weight',
render: function() {
return (
<Text style={{fontWeight: 'bold'}}>
Move fast and be bold
</Text>
<View>
<Text style={{fontWeight: '100'}}>
Move fast and be ultralight
</Text>
<Text style={{fontWeight: '200'}}>
Move fast and be light
</Text>
<Text style={{fontWeight: 'normal'}}>
Move fast and be normal
</Text>
<Text style={{fontWeight: 'bold'}}>
Move fast and be bold
</Text>
<Text style={{fontWeight: '900'}}>
Move fast and be ultrabold
</Text>
</View>
);
},
}, {
title: 'Font Style',
render: function() {
return (
<View>
<Text style={{fontStyle: 'normal'}}>
Normal text
</Text>
<Text style={{fontStyle: 'italic'}}>
Italic text
</Text>
</View>
);
},
}, {
Expand Down Expand Up @@ -279,7 +307,7 @@ var styles = StyleSheet.create({
backgroundColor: 'rgba(100, 100, 100, 0.3)'
},
entity: {
fontWeight: 'bold',
fontWeight: '500',
color: '#527fe4',
},
});
2 changes: 1 addition & 1 deletion Examples/UIExplorer/TouchableExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ var styles = StyleSheet.create({
backgroundColor: '#f9f9f9',
},
textBlock: {
fontWeight: 'bold',
fontWeight: '500',
color: 'blue',
},
});
2 changes: 1 addition & 1 deletion Examples/UIExplorer/UIExplorerBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ var styles = StyleSheet.create({
},
titleText: {
fontSize: 14,
fontWeight: 'bold',
fontWeight: '500',
},
descriptionText: {
fontSize: 14,
Expand Down
4 changes: 2 additions & 2 deletions Examples/UIExplorer/UIExplorerList.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ var styles = StyleSheet.create({
backgroundColor: 'white',
},
sectionHeaderTitle: {
fontWeight: 'bold',
fontWeight: '500',
fontSize: 11,
},
row: {
Expand All @@ -220,7 +220,7 @@ var styles = StyleSheet.create({
},
rowTitleText: {
fontSize: 17,
fontWeight: 'bold',
fontWeight: '500',
},
rowDetailText: {
fontSize: 15,
Expand Down
2 changes: 1 addition & 1 deletion Examples/UIExplorer/UIExplorerTitle.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var styles = StyleSheet.create({
},
text: {
fontSize: 19,
fontWeight: 'bold',
fontWeight: '500',
},
});

Expand Down
2 changes: 1 addition & 1 deletion Examples/UIExplorer/WebViewExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ var styles = StyleSheet.create({
},
errorTextTitle: {
fontSize: 15,
fontWeight: 'bold',
fontWeight: '500',
marginBottom: 10,
},
errorText: {
Expand Down
2 changes: 1 addition & 1 deletion IntegrationTests/IntegrationTestsApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ var styles = StyleSheet.create({
padding: 10,
},
testName: {
fontWeight: 'bold',
fontWeight: '500',
},
separator: {
height: 1,
Expand Down
1 change: 1 addition & 0 deletions Libraries/Text/RCTShadowText.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ extern NSString *const RCTReactTagAttributeName;
@property (nonatomic, copy) NSString *fontFamily;
@property (nonatomic, assign) CGFloat fontSize;
@property (nonatomic, copy) NSString *fontWeight;
@property (nonatomic, copy) NSString *fontStyle;
@property (nonatomic, assign) BOOL isHighlighted;
@property (nonatomic, assign) CGFloat lineHeight;
@property (nonatomic, assign) NSInteger maxNumberOfLines;
Expand Down
13 changes: 9 additions & 4 deletions Libraries/Text/RCTShadowText.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ - (NSAttributedString *)attributedString
{
return [self _attributedStringWithFontFamily:nil
fontSize:0
fontWeight:nil];
fontWeight:nil
fontStyle:nil];
}

- (NSAttributedString *)_attributedStringWithFontFamily:(NSString *)fontFamily
fontSize:(CGFloat)fontSize
fontWeight:(NSString *)fontWeight
fontStyle:(NSString *)fontStyle
{
if (![self isTextDirty] && _cachedAttributedString) {
return _cachedAttributedString;
Expand All @@ -67,6 +69,9 @@ - (NSAttributedString *)_attributedStringWithFontFamily:(NSString *)fontFamily
if (_fontWeight) {
fontWeight = _fontWeight;
}
if (_fontStyle) {
fontStyle = _fontStyle;
}
if (_fontFamily) {
fontFamily = _fontFamily;
}
Expand All @@ -75,7 +80,7 @@ - (NSAttributedString *)_attributedStringWithFontFamily:(NSString *)fontFamily
for (RCTShadowView *child in [self reactSubviews]) {
if ([child isKindOfClass:[RCTShadowText class]]) {
RCTShadowText *shadowText = (RCTShadowText *)child;
[attributedString appendAttributedString:[shadowText _attributedStringWithFontFamily:fontFamily fontSize:fontSize fontWeight:fontWeight]];
[attributedString appendAttributedString:[shadowText _attributedStringWithFontFamily:fontFamily fontSize:fontSize fontWeight:fontWeight fontStyle:fontStyle]];
} else if ([child isKindOfClass:[RCTShadowRawText class]]) {
RCTShadowRawText *shadowRawText = (RCTShadowRawText *)child;
[attributedString appendAttributedString:[[NSAttributedString alloc] initWithString:[shadowRawText text] ?: @""]];
Expand All @@ -96,7 +101,7 @@ - (NSAttributedString *)_attributedStringWithFontFamily:(NSString *)fontFamily
[self _addAttribute:NSBackgroundColorAttributeName withValue:self.textBackgroundColor toAttributedString:attributedString];
}

_font = [RCTConvert UIFont:nil withFamily:fontFamily size:@(fontSize) weight:fontWeight];
_font = [RCTConvert UIFont:nil withFamily:fontFamily size:@(fontSize) weight:fontWeight style:fontStyle];
[self _addAttribute:NSFontAttributeName withValue:_font toAttributedString:attributedString];
[self _addAttribute:RCTReactTagAttributeName withValue:self.reactTag toAttributedString:attributedString];
[self _setParagraphStyleOnAttributedString:attributedString];
Expand All @@ -110,7 +115,7 @@ - (NSAttributedString *)_attributedStringWithFontFamily:(NSString *)fontFamily

- (UIFont *)font
{
return _font ?: [RCTConvert UIFont:nil withFamily:_fontFamily size:@(_fontSize) weight:_fontWeight];
return _font ?: [RCTConvert UIFont:nil withFamily:_fontFamily size:@(_fontSize) weight:_fontWeight style:_fontStyle];
}

- (void)_addAttribute:(NSString *)attribute withValue:(id)attributeValue toAttributedString:(NSMutableAttributedString *)attributedString
Expand Down
8 changes: 7 additions & 1 deletion ReactKit/Base/RCTConvert.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#import "Layout.h"
#import "RCTAnimationType.h"
#import "RCTLog.h"
#import "RCTPointerEvents.h"

/**
Expand Down Expand Up @@ -69,8 +70,13 @@

+ (UIFont *)UIFont:(UIFont *)font withSize:(id)json;
+ (UIFont *)UIFont:(UIFont *)font withWeight:(id)json;
+ (UIFont *)UIFont:(UIFont *)font withStyle:(id)json;
+ (UIFont *)UIFont:(UIFont *)font withFamily:(id)json;
+ (UIFont *)UIFont:(UIFont *)font withFamily:(id)json size:(id)json weight:(id)json;
+ (UIFont *)UIFont:(UIFont *)font
withFamily:(id)family
size:(id)size
weight:(id)weight
style:(id)style;

+ (NSArray *)NSStringArray:(id)json;
+ (NSArray *)NSURLArray:(id)json;
Expand Down
Loading

0 comments on commit f124c32

Please sign in to comment.