Implement basic support for native animation of font size

This commit is contained in:
Mikael Sand
2019-02-17 03:29:59 +02:00
parent ccb8026462
commit 9b1ccf0e7f
4 changed files with 42 additions and 1 deletions
@@ -15,6 +15,7 @@ import android.view.ViewGroup;
import com.facebook.infer.annotation.Assertions;
import com.facebook.react.bridge.Dynamic;
import com.facebook.react.bridge.JavaOnlyMap;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.uimanager.DisplayMetricsHolder;
@@ -345,6 +346,22 @@ class RenderableViewManager extends ViewGroupManager<VirtualView> {
public void setFont(GroupView node, @Nullable ReadableMap font) {
node.setFont(font);
}
@ReactProp(name = "fontSize")
public void setFontSize(GroupView node, Dynamic fontSize) {
JavaOnlyMap map = new JavaOnlyMap();
switch (fontSize.getType()) {
case Number:
map.putDouble("fontSize", fontSize.asDouble());
break;
case String:
map.putString("fontSize", fontSize.asString());
break;
default:
return;
}
node.setFont(map);
}
}
+12
View File
@@ -21,4 +21,16 @@ RCT_EXPORT_MODULE()
RCT_EXPORT_VIEW_PROPERTY(font, NSDictionary)
RCT_CUSTOM_VIEW_PROPERTY(fontSize, id, RNSVGGroup)
{
if ([json isKindOfClass:[NSString class]]) {
NSString *stringValue = (NSString *)json;
view.font = @{ @"fontSize": stringValue };
} else {
NSNumber* number = (NSNumber*)json;
double num = [number doubleValue];
view.font = @{@"fontSize": [NSNumber numberWithDouble:num] };
}
}
@end
+12
View File
@@ -68,4 +68,16 @@ RCT_CUSTOM_VIEW_PROPERTY(baselineShift, id, RNSVGText)
RCT_EXPORT_VIEW_PROPERTY(lengthAdjust, NSString)
RCT_EXPORT_VIEW_PROPERTY(alignmentBaseline, NSString)
RCT_CUSTOM_VIEW_PROPERTY(fontSize, id, RNSVGGroup)
{
if ([json isKindOfClass:[NSString class]]) {
NSString *stringValue = (NSString *)json;
view.font = @{ @"fontSize": stringValue };
} else {
NSNumber* number = (NSNumber*)json;
double num = [number doubleValue];
view.font = @{@"fontSize": [NSNumber numberWithDouble:num] };
}
}
@end
+1 -1
View File
@@ -33,7 +33,7 @@ function parseFontString(font) {
const isBold = /bold/.exec(match[1]);
const isItalic = /italic/.exec(match[1]);
cachedFontObjectsFromString[font] = {
fontSize: match[2] || '12',
fontSize: match[2] || 12,
fontWeight: isBold ? 'bold' : 'normal',
fontStyle: isItalic ? 'italic' : 'normal',
fontFamily: extractSingleFontFamily(match[3]),