Commit 6bc4f8d
Add support for PlatformColor type of toValue and interpolation outputRange (facebook#54450)
Summary:
## Changelog:
[Android] [Added] Add support for PlatformColor type of toValue and interpolation outputRange
Making this change in order to support animation from and to PlatformColor type, in use cases like below
Example 1:
```
const animatedColor = useRef(
new Animated.Color(PlatformColor('android:color/white')),
);
...
Animated.timing(animatedColor.current, {
toValue: PlatformColor('android:color/darker_gray'),
duration: 500,
useNativeDriver: true,
}).start();
```
Example 2:
```
const animatedValue = useRef(new Animated.Value(0));
...
backgroundColor: animatedValue.current.interpolate({
inputRange: [0, 1],
outputRange: [
PlatformColor('android:color/white'),
PlatformColor('android:color/darker_gray'),
],
}),
```
A nuance here: in the framework js code, usually `AnimatedColor` class will resolve color for each channel (RGBA) and create multiple `AnimatedValue` instances. However for platform color, instead of directly resolving the PlatformColor by calling native module, we could pass down the color string + channel name to native, and defer to AnimatedNode/Driver on the native side to resolve the actual color value when it's necessary.
But this strategy means PlatformColor toValue/outputRange won't work if `useNativeDriver` is turned off.
Note that `fromValue` is already supported (in ColorAnimatedNode.kt)
Differential Revision: D863512841 parent 7c91517 commit 6bc4f8d
File tree
5 files changed
+132
-28
lines changed- packages/react-native/ReactAndroid/src/main/java/com/facebook/react/animated
5 files changed
+132
-28
lines changedLines changed: 17 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
18 | 35 | | |
19 | 36 | | |
20 | 37 | | |
| |||
Lines changed: 0 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | 93 | | |
Lines changed: 48 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
10 | 12 | | |
| 13 | + | |
| 14 | + | |
11 | 15 | | |
12 | 16 | | |
13 | 17 | | |
| |||
18 | 22 | | |
19 | 23 | | |
20 | 24 | | |
21 | | - | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
22 | 29 | | |
23 | 30 | | |
24 | | - | |
| 31 | + | |
25 | 32 | | |
26 | 33 | | |
27 | 34 | | |
28 | 35 | | |
29 | 36 | | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
30 | 45 | | |
31 | 46 | | |
32 | 47 | | |
33 | 48 | | |
34 | 49 | | |
35 | | - | |
36 | | - | |
| 50 | + | |
37 | 51 | | |
38 | 52 | | |
39 | 53 | | |
40 | 54 | | |
41 | 55 | | |
| 56 | + | |
42 | 57 | | |
43 | | - | |
44 | | - | |
45 | | - | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
46 | 87 | | |
47 | 88 | | |
48 | 89 | | |
| |||
Lines changed: 63 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
| 12 | + | |
11 | 13 | | |
| 14 | + | |
12 | 15 | | |
13 | 16 | | |
14 | 17 | | |
| |||
19 | 22 | | |
20 | 23 | | |
21 | 24 | | |
22 | | - | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
23 | 29 | | |
24 | 30 | | |
25 | 31 | | |
| 32 | + | |
26 | 33 | | |
27 | 34 | | |
28 | 35 | | |
| |||
35 | 42 | | |
36 | 43 | | |
37 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
38 | 52 | | |
39 | 53 | | |
40 | 54 | | |
41 | 55 | | |
42 | 56 | | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
43 | 60 | | |
44 | 61 | | |
45 | 62 | | |
| |||
77 | 94 | | |
78 | 95 | | |
79 | 96 | | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
80 | 108 | | |
81 | 109 | | |
82 | 110 | | |
| |||
100 | 128 | | |
101 | 129 | | |
102 | 130 | | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
103 | 155 | | |
104 | 156 | | |
105 | 157 | | |
| |||
108 | 160 | | |
109 | 161 | | |
110 | 162 | | |
| 163 | + | |
111 | 164 | | |
112 | 165 | | |
113 | 166 | | |
| |||
127 | 180 | | |
128 | 181 | | |
129 | 182 | | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
130 | 192 | | |
131 | 193 | | |
132 | 194 | | |
| |||
Lines changed: 4 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
115 | | - | |
| 115 | + | |
| 116 | + | |
116 | 117 | | |
117 | 118 | | |
118 | 119 | | |
| |||
247 | 248 | | |
248 | 249 | | |
249 | 250 | | |
250 | | - | |
| 251 | + | |
| 252 | + | |
251 | 253 | | |
252 | 254 | | |
253 | 255 | | |
| |||
0 commit comments