Skip to content

Commit 19bba43

Browse files
committed
[animated] Support scientific notation in string interpolation
1 parent 50d7074 commit 19bba43

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

Libraries/Animated/src/nodes/AnimatedInterpolation.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ function colorToRgba(input: string): string {
181181
return `rgba(${r}, ${g}, ${b}, ${a})`;
182182
}
183183

184-
const stringShapeRegex = /[0-9\.-]+/g;
184+
const stringShapeRegex = /[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?/g;
185185

186186
/**
187187
* Supports string shapes by extracting numbers so new values can be computed,

Libraries/NativeAnimation/Nodes/RCTInterpolationAnimatedNode.m

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ - (instancetype)initWithTag:(NSNumber *)tag
3131
{
3232
static dispatch_once_t onceToken;
3333
dispatch_once(&onceToken, ^{
34-
regex = [NSRegularExpression regularExpressionWithPattern:@"[0-9.-]+" options:NSRegularExpressionCaseInsensitive error:nil];
34+
NSString *fpRegex = @"[+-]?(\\d+\\.?\\d*|\\.\\d+)([eE][+-]?\\d+)?";
35+
regex = [NSRegularExpression regularExpressionWithPattern:fpRegex options:NSRegularExpressionCaseInsensitive error:nil];
3536
});
3637
if ((self = [super initWithTag:tag config:config])) {
3738
_inputRange = [config[@"inputRange"] copy];

ReactAndroid/src/main/java/com/facebook/react/animated/InterpolationAnimatedNode.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
public static final String EXTRAPOLATE_TYPE_IDENTITY = "identity";
2828
public static final String EXTRAPOLATE_TYPE_CLAMP = "clamp";
2929
public static final String EXTRAPOLATE_TYPE_EXTEND = "extend";
30-
static final Pattern regex = Pattern.compile("[0-9.-]+");
30+
31+
private static final String fpRegex = "[+-]?(\\d+\\.?\\d*|\\.\\d+)([eE][+-]?\\d+)?";
32+
private static final Pattern fpPattern = Pattern.compile(fpRegex);
3133

3234
private static double[] fromDoubleArray(ReadableArray ary) {
3335
double[] res = new double[ary.size()];
@@ -139,11 +141,11 @@ public InterpolationAnimatedNode(ReadableMap config) {
139141
mOutputRange = new double[size];
140142
mPattern = output.getString(0);
141143
mShouldRound = mPattern.startsWith("rgb");
142-
mSOutputMatcher = regex.matcher(mPattern);
144+
mSOutputMatcher = fpPattern.matcher(mPattern);
143145
ArrayList<ArrayList<Double>> mOutputRanges = new ArrayList<>();
144146
for (int i = 0; i < size; i++) {
145147
String val = output.getString(i);
146-
Matcher m = regex.matcher(val);
148+
Matcher m = fpPattern.matcher(val);
147149
ArrayList<Double> outputRange = new ArrayList<>();
148150
mOutputRanges.add(outputRange);
149151
while (m.find()) {

0 commit comments

Comments
 (0)