mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-05-24 11:44:39 +00:00
Implement basic support for native animation of font size
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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]),
|
||||
|
||||
Reference in New Issue
Block a user