mirror of
https://github.com/zoriya/react-native-svg.git
synced 2025-12-06 07:06:11 +00:00
Changed `requireNativeComponent` to `codegenNativeComponent` so that upcoming changes (Static View Configs, Bridgeless Mode and idk what more) in `react-native` are available in the library. Also, types and native components are now taken directly from `fabric` folder to make sure the values passed to the native components are the ones defined in props. It should work on all supported versions since `codegenNativeComponent` function exists from RN v. 0.61.0. Suggested by @RSNara and @cipolleschi Reason for [`5394bbb` (#1847)](5394bbbced): - on `Paper`, `Animated` uses `setNativeProps` method when we set `useNativeDriver` to `false`, and does not rerender the component. Therefore, new transform lands only in `SvgView` and is parsed in `RCTViewManager.m` . - on `Fabric`, the same code makes the components rerender. Due to this, information about new transform is passed to the `SvgView` child: `G` , making it apply translations from the transform in its `updateProps` method. - other than `Animated` use-case, on both archs, if we just passed `transform` prop to `Svg` component, it would end up in double transformations now as well. All of those changes are due to https://github.com/software-mansion/react-native-svg/pull/1895, which added proper parsing of RN style `transform` prop (array of transformations objects) therefore making `G` properly handle `transform` prop passed from `Svg`. Reason for [`19bcb24` (#1847)](19bcb2464b): Same as https://github.com/software-mansion/react-native-screens/pull/1624
90 lines
2.3 KiB
Plaintext
90 lines
2.3 KiB
Plaintext
/**
|
|
* Copyright (c) 2015-present, Horcrux.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the MIT-style license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#import "RNSVGTextManager.h"
|
|
|
|
#import "RCTConvert+RNSVG.h"
|
|
#import "RNSVGText.h"
|
|
|
|
@implementation RNSVGTextManager
|
|
|
|
RCT_EXPORT_MODULE()
|
|
|
|
- (RNSVGRenderable *)node
|
|
{
|
|
return [RNSVGText new];
|
|
}
|
|
|
|
RCT_CUSTOM_VIEW_PROPERTY(dx, id, RNSVGText)
|
|
{
|
|
view.deltaX = [RCTConvert RNSVGLengthArray:json];
|
|
}
|
|
RCT_CUSTOM_VIEW_PROPERTY(dy, id, RNSVGText)
|
|
{
|
|
view.deltaY = [RCTConvert RNSVGLengthArray:json];
|
|
}
|
|
RCT_CUSTOM_VIEW_PROPERTY(x, id, RNSVGText)
|
|
{
|
|
view.positionX = [RCTConvert RNSVGLengthArray:json];
|
|
}
|
|
RCT_CUSTOM_VIEW_PROPERTY(y, id, RNSVGText)
|
|
{
|
|
view.positionY = [RCTConvert RNSVGLengthArray:json];
|
|
}
|
|
RCT_CUSTOM_VIEW_PROPERTY(rotate, id, RNSVGText)
|
|
{
|
|
view.rotate = [RCTConvert RNSVGLengthArray:json];
|
|
}
|
|
RCT_EXPORT_VIEW_PROPERTY(font, NSDictionary)
|
|
RCT_CUSTOM_VIEW_PROPERTY(inlineSize, id, RNSVGText)
|
|
{
|
|
view.inlineSize = [RCTConvert RNSVGLength:json];
|
|
}
|
|
RCT_CUSTOM_VIEW_PROPERTY(textLength, id, RNSVGText)
|
|
{
|
|
view.textLength = [RCTConvert RNSVGLength:json];
|
|
}
|
|
RCT_CUSTOM_VIEW_PROPERTY(baselineShift, id, RNSVGText)
|
|
{
|
|
if ([json isKindOfClass:[NSString class]]) {
|
|
NSString *stringValue = (NSString *)json;
|
|
view.baselineShift = stringValue;
|
|
} else {
|
|
view.baselineShift = [NSString stringWithFormat:@"%f", [json doubleValue]];
|
|
}
|
|
}
|
|
RCT_EXPORT_VIEW_PROPERTY(lengthAdjust, NSString)
|
|
RCT_EXPORT_VIEW_PROPERTY(alignmentBaseline, NSString)
|
|
RCT_EXPORT_VIEW_PROPERTY(verticalAlign, NSString) // unused on iOS
|
|
|
|
RCT_CUSTOM_VIEW_PROPERTY(fontSize, id, RNSVGText)
|
|
{
|
|
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]};
|
|
}
|
|
}
|
|
|
|
RCT_CUSTOM_VIEW_PROPERTY(fontWeight, id, RNSVGText)
|
|
{
|
|
if ([json isKindOfClass:[NSString class]]) {
|
|
NSString *stringValue = (NSString *)json;
|
|
view.font = @{@"fontWeight" : stringValue};
|
|
} else {
|
|
NSNumber *number = (NSNumber *)json;
|
|
double num = [number doubleValue];
|
|
view.font = @{@"fontWeight" : [NSNumber numberWithDouble:num]};
|
|
}
|
|
}
|
|
|
|
@end
|