@office-iss/react-native-win32 0.0.0-canary.264 → 0.0.0-canary.266
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.flowconfig +1 -1
- package/CHANGELOG.json +61 -7
- package/CHANGELOG.md +28 -8
- package/Libraries/Animated/AnimatedImplementation.js +2 -2
- package/Libraries/Animated/NativeAnimatedAllowlist.js +20 -9
- package/Libraries/Animated/animations/Animation.js +1 -4
- package/Libraries/Animated/createAnimatedComponent.js +13 -0
- package/Libraries/Animated/nodes/AnimatedNode.js +39 -45
- package/Libraries/Animated/nodes/AnimatedObject.js +13 -3
- package/Libraries/Animated/nodes/AnimatedProps.js +81 -37
- package/Libraries/Animated/nodes/AnimatedStyle.js +104 -39
- package/Libraries/Animated/nodes/AnimatedTransform.js +55 -22
- package/Libraries/Animated/nodes/AnimatedWithChildren.js +1 -3
- package/Libraries/Animated/useAnimatedProps.js +38 -20
- package/Libraries/Components/ProgressBarAndroid/ProgressBarAndroid.android.js +3 -1
- package/Libraries/Components/ScrollView/ScrollView.js +12 -9
- package/Libraries/Components/ScrollView/ScrollViewNativeComponent.js +3 -0
- package/Libraries/Components/TextInput/RCTTextInputViewConfig.js +10 -0
- package/Libraries/Components/TextInput/TextInput.d.ts +19 -0
- package/Libraries/Components/TextInput/TextInput.flow.js +17 -1
- package/Libraries/Components/TextInput/TextInput.js +17 -1
- package/Libraries/Components/TextInput/TextInput.win32.js +17 -1
- package/Libraries/Components/Touchable/TouchableBounce.js +1 -1
- package/Libraries/Components/Touchable/TouchableHighlight.js +2 -2
- package/Libraries/Components/Touchable/TouchableOpacity.js +1 -1
- package/Libraries/Components/View/ReactNativeStyleAttributes.js +6 -2
- package/Libraries/Core/ReactNativeVersion.js +2 -2
- package/Libraries/Image/AssetSourceResolver.js +12 -1
- package/Libraries/Modal/Modal.d.ts +7 -0
- package/Libraries/Modal/Modal.js +9 -1
- package/Libraries/NativeComponent/BaseViewConfig.android.js +7 -2
- package/Libraries/NativeComponent/BaseViewConfig.ios.js +11 -2
- package/Libraries/NativeComponent/BaseViewConfig.win32.js +1 -1
- package/Libraries/NativeComponent/StaticViewConfigValidator.js +0 -1
- package/Libraries/ReactNative/AppRegistry.js +2 -6
- package/Libraries/ReactNative/getNativeComponentAttributes.js +4 -0
- package/Libraries/Renderer/shims/ReactNativeTypes.js +3 -3
- package/Libraries/Renderer/shims/ReactNativeViewConfigRegistry.js +5 -6
- package/Libraries/StyleSheet/StyleSheetTypes.d.ts +102 -5
- package/Libraries/StyleSheet/StyleSheetTypes.js +9 -5
- package/Libraries/StyleSheet/processBoxShadow.js +5 -7
- package/Libraries/StyleSheet/processFilter.js +4 -4
- package/Libraries/Text/TextNativeComponent.js +0 -1
- package/Libraries/Utilities/HMRClient.js +5 -5
- package/overrides.json +6 -6
- package/package.json +21 -19
- package/src/private/animated/NativeAnimatedHelper.js +12 -8
- package/src/private/animated/NativeAnimatedHelper.win32.js +12 -8
- package/src/private/animated/useAnimatedPropsMemo.js +349 -0
- package/src/private/components/HScrollViewNativeComponents.js +9 -8
- package/src/private/components/SafeAreaView_INTERNAL_DO_NOT_USE.js +13 -9
- package/src/private/components/VScrollViewNativeComponents.js +9 -8
- package/src/private/featureflags/ReactNativeFeatureFlags.js +50 -22
- package/src/private/featureflags/ReactNativeFeatureFlagsBase.js +8 -2
- package/src/private/featureflags/specs/NativeReactNativeFeatureFlags.js +7 -4
- package/src/private/webapis/dom/geometry/DOMRect.js +2 -2
- package/src/private/webapis/dom/geometry/DOMRectReadOnly.js +2 -2
- package/types/experimental.d.ts +0 -105
- package/types/modules/Codegen.d.ts +6 -0
|
@@ -8,9 +8,8 @@
|
|
|
8
8
|
* @format
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
'use strict';
|
|
12
|
-
|
|
13
11
|
import type {PlatformConfig} from '../AnimatedPlatformConfig';
|
|
12
|
+
import type {AnimatedStyleAllowlist} from './AnimatedStyle';
|
|
14
13
|
|
|
15
14
|
import {findNodeHandle} from '../../ReactNative/RendererProxy';
|
|
16
15
|
import {AnimatedEvent} from '../AnimatedEvent';
|
|
@@ -20,30 +19,33 @@ import AnimatedObject from './AnimatedObject';
|
|
|
20
19
|
import AnimatedStyle from './AnimatedStyle';
|
|
21
20
|
import invariant from 'invariant';
|
|
22
21
|
|
|
22
|
+
export type AnimatedPropsAllowlist = $ReadOnly<{
|
|
23
|
+
style?: ?AnimatedStyleAllowlist,
|
|
24
|
+
[string]: true,
|
|
25
|
+
}>;
|
|
26
|
+
|
|
23
27
|
function createAnimatedProps(
|
|
24
|
-
inputProps:
|
|
25
|
-
|
|
28
|
+
inputProps: {[string]: mixed},
|
|
29
|
+
allowlist: ?AnimatedPropsAllowlist,
|
|
30
|
+
): [$ReadOnlyArray<string>, $ReadOnlyArray<AnimatedNode>, {[string]: mixed}] {
|
|
26
31
|
const nodeKeys: Array<string> = [];
|
|
27
32
|
const nodes: Array<AnimatedNode> = [];
|
|
28
|
-
const props:
|
|
33
|
+
const props: {[string]: mixed} = {};
|
|
29
34
|
|
|
30
35
|
const keys = Object.keys(inputProps);
|
|
31
36
|
for (let ii = 0, length = keys.length; ii < length; ii++) {
|
|
32
37
|
const key = keys[ii];
|
|
33
38
|
const value = inputProps[key];
|
|
34
39
|
|
|
35
|
-
if (
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
props[key] = node;
|
|
45
|
-
} else {
|
|
46
|
-
const node = AnimatedObject.from(value);
|
|
40
|
+
if (allowlist == null || Object.hasOwn(allowlist, key)) {
|
|
41
|
+
let node;
|
|
42
|
+
if (key === 'style') {
|
|
43
|
+
node = AnimatedStyle.from(value, allowlist?.style);
|
|
44
|
+
} else if (value instanceof AnimatedNode) {
|
|
45
|
+
node = value;
|
|
46
|
+
} else {
|
|
47
|
+
node = AnimatedObject.from(value);
|
|
48
|
+
}
|
|
47
49
|
if (node == null) {
|
|
48
50
|
props[key] = value;
|
|
49
51
|
} else {
|
|
@@ -51,6 +53,20 @@ function createAnimatedProps(
|
|
|
51
53
|
nodes.push(node);
|
|
52
54
|
props[key] = node;
|
|
53
55
|
}
|
|
56
|
+
} else {
|
|
57
|
+
if (__DEV__) {
|
|
58
|
+
// WARNING: This is a potentially expensive check that we should only
|
|
59
|
+
// do in development. Without this check in development, it might be
|
|
60
|
+
// difficult to identify which props need to be allowlisted.
|
|
61
|
+
if (AnimatedObject.from(inputProps[key]) != null) {
|
|
62
|
+
console.error(
|
|
63
|
+
`AnimatedProps: ${key} is not allowlisted for animation, but it ` +
|
|
64
|
+
'contains AnimatedNode values; props allowing animation: ',
|
|
65
|
+
allowlist,
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
props[key] = value;
|
|
54
70
|
}
|
|
55
71
|
}
|
|
56
72
|
|
|
@@ -58,29 +74,32 @@ function createAnimatedProps(
|
|
|
58
74
|
}
|
|
59
75
|
|
|
60
76
|
export default class AnimatedProps extends AnimatedNode {
|
|
77
|
+
#animatedView: any = null;
|
|
78
|
+
#callback: () => void;
|
|
61
79
|
#nodeKeys: $ReadOnlyArray<string>;
|
|
62
80
|
#nodes: $ReadOnlyArray<AnimatedNode>;
|
|
81
|
+
#props: {[string]: mixed};
|
|
63
82
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
83
|
+
constructor(
|
|
84
|
+
inputProps: {[string]: mixed},
|
|
85
|
+
callback: () => void,
|
|
86
|
+
allowlist?: ?AnimatedPropsAllowlist,
|
|
87
|
+
) {
|
|
69
88
|
super();
|
|
70
|
-
const [nodeKeys, nodes, props] = createAnimatedProps(inputProps);
|
|
89
|
+
const [nodeKeys, nodes, props] = createAnimatedProps(inputProps, allowlist);
|
|
71
90
|
this.#nodeKeys = nodeKeys;
|
|
72
91
|
this.#nodes = nodes;
|
|
73
|
-
this
|
|
74
|
-
this
|
|
92
|
+
this.#props = props;
|
|
93
|
+
this.#callback = callback;
|
|
75
94
|
}
|
|
76
95
|
|
|
77
96
|
__getValue(): Object {
|
|
78
|
-
const props: {[string]:
|
|
97
|
+
const props: {[string]: mixed} = {};
|
|
79
98
|
|
|
80
|
-
const keys = Object.keys(this
|
|
99
|
+
const keys = Object.keys(this.#props);
|
|
81
100
|
for (let ii = 0, length = keys.length; ii < length; ii++) {
|
|
82
101
|
const key = keys[ii];
|
|
83
|
-
const value = this
|
|
102
|
+
const value = this.#props[key];
|
|
84
103
|
|
|
85
104
|
if (value instanceof AnimatedNode) {
|
|
86
105
|
props[key] = value.__getValue();
|
|
@@ -94,8 +113,33 @@ export default class AnimatedProps extends AnimatedNode {
|
|
|
94
113
|
return props;
|
|
95
114
|
}
|
|
96
115
|
|
|
116
|
+
/**
|
|
117
|
+
* Creates a new `props` object that contains the same props as the supplied
|
|
118
|
+
* `staticProps` object, except with animated nodes for any props that were
|
|
119
|
+
* created by this `AnimatedProps` instance.
|
|
120
|
+
*/
|
|
121
|
+
__getValueWithStaticProps(staticProps: Object): Object {
|
|
122
|
+
const props: {[string]: mixed} = {...staticProps};
|
|
123
|
+
|
|
124
|
+
const keys = Object.keys(staticProps);
|
|
125
|
+
for (let ii = 0, length = keys.length; ii < length; ii++) {
|
|
126
|
+
const key = keys[ii];
|
|
127
|
+
const maybeNode = this.#props[key];
|
|
128
|
+
|
|
129
|
+
if (key === 'style' && maybeNode instanceof AnimatedStyle) {
|
|
130
|
+
props[key] = maybeNode.__getValueWithStaticStyle(staticProps.style);
|
|
131
|
+
} else if (maybeNode instanceof AnimatedNode) {
|
|
132
|
+
props[key] = maybeNode.__getValue();
|
|
133
|
+
} else if (maybeNode instanceof AnimatedEvent) {
|
|
134
|
+
props[key] = maybeNode.__getHandler();
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return props;
|
|
139
|
+
}
|
|
140
|
+
|
|
97
141
|
__getAnimatedValue(): Object {
|
|
98
|
-
const props: {[string]:
|
|
142
|
+
const props: {[string]: mixed} = {};
|
|
99
143
|
|
|
100
144
|
const nodeKeys = this.#nodeKeys;
|
|
101
145
|
const nodes = this.#nodes;
|
|
@@ -117,10 +161,10 @@ export default class AnimatedProps extends AnimatedNode {
|
|
|
117
161
|
}
|
|
118
162
|
|
|
119
163
|
__detach(): void {
|
|
120
|
-
if (this.__isNative && this
|
|
164
|
+
if (this.__isNative && this.#animatedView) {
|
|
121
165
|
this.__disconnectAnimatedView();
|
|
122
166
|
}
|
|
123
|
-
this
|
|
167
|
+
this.#animatedView = null;
|
|
124
168
|
|
|
125
169
|
const nodes = this.#nodes;
|
|
126
170
|
for (let ii = 0, length = nodes.length; ii < length; ii++) {
|
|
@@ -132,7 +176,7 @@ export default class AnimatedProps extends AnimatedNode {
|
|
|
132
176
|
}
|
|
133
177
|
|
|
134
178
|
update(): void {
|
|
135
|
-
this
|
|
179
|
+
this.#callback();
|
|
136
180
|
}
|
|
137
181
|
|
|
138
182
|
__makeNative(platformConfig: ?PlatformConfig): void {
|
|
@@ -150,17 +194,17 @@ export default class AnimatedProps extends AnimatedNode {
|
|
|
150
194
|
// where it will be needed to traverse the graph of attached values.
|
|
151
195
|
super.__setPlatformConfig(platformConfig);
|
|
152
196
|
|
|
153
|
-
if (this
|
|
197
|
+
if (this.#animatedView) {
|
|
154
198
|
this.__connectAnimatedView();
|
|
155
199
|
}
|
|
156
200
|
}
|
|
157
201
|
}
|
|
158
202
|
|
|
159
203
|
setNativeView(animatedView: any): void {
|
|
160
|
-
if (this
|
|
204
|
+
if (this.#animatedView === animatedView) {
|
|
161
205
|
return;
|
|
162
206
|
}
|
|
163
|
-
this
|
|
207
|
+
this.#animatedView = animatedView;
|
|
164
208
|
if (this.__isNative) {
|
|
165
209
|
this.__connectAnimatedView();
|
|
166
210
|
}
|
|
@@ -168,7 +212,7 @@ export default class AnimatedProps extends AnimatedNode {
|
|
|
168
212
|
|
|
169
213
|
__connectAnimatedView(): void {
|
|
170
214
|
invariant(this.__isNative, 'Expected node to be marked as "native"');
|
|
171
|
-
const nativeViewTag: ?number = findNodeHandle(this
|
|
215
|
+
const nativeViewTag: ?number = findNodeHandle(this.#animatedView);
|
|
172
216
|
invariant(
|
|
173
217
|
nativeViewTag != null,
|
|
174
218
|
'Unable to locate attached view in the native tree',
|
|
@@ -181,7 +225,7 @@ export default class AnimatedProps extends AnimatedNode {
|
|
|
181
225
|
|
|
182
226
|
__disconnectAnimatedView(): void {
|
|
183
227
|
invariant(this.__isNative, 'Expected node to be marked as "native"');
|
|
184
|
-
const nativeViewTag: ?number = findNodeHandle(this
|
|
228
|
+
const nativeViewTag: ?number = findNodeHandle(this.#animatedView);
|
|
185
229
|
invariant(
|
|
186
230
|
nativeViewTag != null,
|
|
187
231
|
'Unable to locate attached view in the native tree',
|
|
@@ -8,8 +8,6 @@
|
|
|
8
8
|
* @format
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
'use strict';
|
|
12
|
-
|
|
13
11
|
import type {PlatformConfig} from '../AnimatedPlatformConfig';
|
|
14
12
|
|
|
15
13
|
import {validateStyles} from '../../../src/private/animated/NativeAnimatedValidation';
|
|
@@ -21,24 +19,34 @@ import AnimatedObject from './AnimatedObject';
|
|
|
21
19
|
import AnimatedTransform from './AnimatedTransform';
|
|
22
20
|
import AnimatedWithChildren from './AnimatedWithChildren';
|
|
23
21
|
|
|
22
|
+
export type AnimatedStyleAllowlist = $ReadOnly<{[string]: true}>;
|
|
23
|
+
|
|
24
24
|
function createAnimatedStyle(
|
|
25
25
|
inputStyle: {[string]: mixed},
|
|
26
|
+
allowlist: ?AnimatedStyleAllowlist,
|
|
26
27
|
keepUnanimatedValues: boolean,
|
|
27
|
-
): [$ReadOnlyArray<string>, $ReadOnlyArray<AnimatedNode>,
|
|
28
|
+
): [$ReadOnlyArray<string>, $ReadOnlyArray<AnimatedNode>, {[string]: mixed}] {
|
|
28
29
|
const nodeKeys: Array<string> = [];
|
|
29
30
|
const nodes: Array<AnimatedNode> = [];
|
|
30
|
-
const style: {[string]:
|
|
31
|
+
const style: {[string]: mixed} = {};
|
|
31
32
|
|
|
32
33
|
const keys = Object.keys(inputStyle);
|
|
33
34
|
for (let ii = 0, length = keys.length; ii < length; ii++) {
|
|
34
35
|
const key = keys[ii];
|
|
35
36
|
const value = inputStyle[key];
|
|
36
37
|
|
|
37
|
-
if (
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
if (allowlist == null || Object.hasOwn(allowlist, key)) {
|
|
39
|
+
let node;
|
|
40
|
+
if (value != null && key === 'transform') {
|
|
41
|
+
node = ReactNativeFeatureFlags.shouldUseAnimatedObjectForTransform()
|
|
42
|
+
? AnimatedObject.from(value)
|
|
43
|
+
: // $FlowFixMe[incompatible-call] - `value` is mixed.
|
|
44
|
+
AnimatedTransform.from(value);
|
|
45
|
+
} else if (value instanceof AnimatedNode) {
|
|
46
|
+
node = value;
|
|
47
|
+
} else {
|
|
48
|
+
node = AnimatedObject.from(value);
|
|
49
|
+
}
|
|
42
50
|
if (node == null) {
|
|
43
51
|
if (keepUnanimatedValues) {
|
|
44
52
|
style[key] = value;
|
|
@@ -48,21 +56,21 @@ function createAnimatedStyle(
|
|
|
48
56
|
nodes.push(node);
|
|
49
57
|
style[key] = node;
|
|
50
58
|
}
|
|
51
|
-
} else if (value instanceof AnimatedNode) {
|
|
52
|
-
const node = value;
|
|
53
|
-
nodeKeys.push(key);
|
|
54
|
-
nodes.push(node);
|
|
55
|
-
style[key] = value;
|
|
56
59
|
} else {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
60
|
+
if (__DEV__) {
|
|
61
|
+
// WARNING: This is a potentially expensive check that we should only
|
|
62
|
+
// do in development. Without this check in development, it might be
|
|
63
|
+
// difficult to identify which styles need to be allowlisted.
|
|
64
|
+
if (AnimatedObject.from(inputStyle[key]) != null) {
|
|
65
|
+
console.error(
|
|
66
|
+
`AnimatedStyle: ${key} is not allowlisted for animation, but it ` +
|
|
67
|
+
'contains AnimatedNode values; styles allowing animation: ',
|
|
68
|
+
allowlist,
|
|
69
|
+
);
|
|
61
70
|
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
style[key] = node;
|
|
71
|
+
}
|
|
72
|
+
if (keepUnanimatedValues) {
|
|
73
|
+
style[key] = value;
|
|
66
74
|
}
|
|
67
75
|
}
|
|
68
76
|
}
|
|
@@ -71,34 +79,54 @@ function createAnimatedStyle(
|
|
|
71
79
|
}
|
|
72
80
|
|
|
73
81
|
export default class AnimatedStyle extends AnimatedWithChildren {
|
|
82
|
+
#inputStyle: any;
|
|
74
83
|
#nodeKeys: $ReadOnlyArray<string>;
|
|
75
84
|
#nodes: $ReadOnlyArray<AnimatedNode>;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
85
|
+
#style: {[string]: mixed};
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Creates an `AnimatedStyle` if `value` contains `AnimatedNode` instances.
|
|
89
|
+
* Otherwise, returns `null`.
|
|
90
|
+
*/
|
|
91
|
+
static from(
|
|
92
|
+
inputStyle: any,
|
|
93
|
+
allowlist: ?AnimatedStyleAllowlist,
|
|
94
|
+
): ?AnimatedStyle {
|
|
95
|
+
const flatStyle = flattenStyle(inputStyle);
|
|
96
|
+
if (flatStyle == null) {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
83
99
|
const [nodeKeys, nodes, style] = createAnimatedStyle(
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
// to instantiation sites.
|
|
87
|
-
flattenStyle(inputStyle) ?? {},
|
|
100
|
+
flatStyle,
|
|
101
|
+
allowlist,
|
|
88
102
|
Platform.OS !== 'web',
|
|
89
103
|
);
|
|
104
|
+
if (nodes.length === 0) {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
return new AnimatedStyle(nodeKeys, nodes, style, inputStyle);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
constructor(
|
|
111
|
+
nodeKeys: $ReadOnlyArray<string>,
|
|
112
|
+
nodes: $ReadOnlyArray<AnimatedNode>,
|
|
113
|
+
style: {[string]: mixed},
|
|
114
|
+
inputStyle: any,
|
|
115
|
+
) {
|
|
116
|
+
super();
|
|
90
117
|
this.#nodeKeys = nodeKeys;
|
|
91
118
|
this.#nodes = nodes;
|
|
92
|
-
this
|
|
119
|
+
this.#style = style;
|
|
120
|
+
this.#inputStyle = inputStyle;
|
|
93
121
|
}
|
|
94
122
|
|
|
95
123
|
__getValue(): Object | Array<Object> {
|
|
96
|
-
const style: {[string]:
|
|
124
|
+
const style: {[string]: mixed} = {};
|
|
97
125
|
|
|
98
|
-
const keys = Object.keys(this
|
|
126
|
+
const keys = Object.keys(this.#style);
|
|
99
127
|
for (let ii = 0, length = keys.length; ii < length; ii++) {
|
|
100
128
|
const key = keys[ii];
|
|
101
|
-
const value = this
|
|
129
|
+
const value = this.#style[key];
|
|
102
130
|
|
|
103
131
|
if (value instanceof AnimatedNode) {
|
|
104
132
|
style[key] = value.__getValue();
|
|
@@ -107,11 +135,48 @@ export default class AnimatedStyle extends AnimatedWithChildren {
|
|
|
107
135
|
}
|
|
108
136
|
}
|
|
109
137
|
|
|
110
|
-
return Platform.OS === 'web' ? [this
|
|
138
|
+
return Platform.OS === 'web' ? [this.#inputStyle, style] : style;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Creates a new `style` object that contains the same style properties as
|
|
143
|
+
* the supplied `staticStyle` object, except with animated nodes for any
|
|
144
|
+
* style properties that were created by this `AnimatedStyle` instance.
|
|
145
|
+
*/
|
|
146
|
+
__getValueWithStaticStyle(staticStyle: Object): Object | Array<Object> {
|
|
147
|
+
const flatStaticStyle = flattenStyle(staticStyle);
|
|
148
|
+
const style: {[string]: mixed} =
|
|
149
|
+
flatStaticStyle == null
|
|
150
|
+
? {}
|
|
151
|
+
: flatStaticStyle === staticStyle
|
|
152
|
+
? // Copy the input style, since we'll mutate it below.
|
|
153
|
+
{...flatStaticStyle}
|
|
154
|
+
: // Reuse `flatStaticStyle` if it is a newly created object.
|
|
155
|
+
flatStaticStyle;
|
|
156
|
+
|
|
157
|
+
const keys = Object.keys(style);
|
|
158
|
+
for (let ii = 0, length = keys.length; ii < length; ii++) {
|
|
159
|
+
const key = keys[ii];
|
|
160
|
+
const maybeNode = this.#style[key];
|
|
161
|
+
|
|
162
|
+
if (key === 'transform' && maybeNode instanceof AnimatedTransform) {
|
|
163
|
+
style[key] = maybeNode.__getValueWithStaticTransforms(
|
|
164
|
+
// NOTE: This check should not be necessary, but the types are not
|
|
165
|
+
// enforced as of this writing.
|
|
166
|
+
Array.isArray(style[key]) ? style[key] : [],
|
|
167
|
+
);
|
|
168
|
+
} else if (maybeNode instanceof AnimatedObject) {
|
|
169
|
+
style[key] = maybeNode.__getValueWithStaticObject(style[key]);
|
|
170
|
+
} else if (maybeNode instanceof AnimatedNode) {
|
|
171
|
+
style[key] = maybeNode.__getValue();
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return Platform.OS === 'web' ? [this.#inputStyle, style] : style;
|
|
111
176
|
}
|
|
112
177
|
|
|
113
178
|
__getAnimatedValue(): Object {
|
|
114
|
-
const style: {[string]:
|
|
179
|
+
const style: {[string]: mixed} = {};
|
|
115
180
|
|
|
116
181
|
const nodeKeys = this.#nodeKeys;
|
|
117
182
|
const nodes = this.#nodes;
|
|
@@ -26,37 +26,58 @@ type Transform<T = AnimatedNode> = {
|
|
|
26
26
|
| {[string]: number | string | T},
|
|
27
27
|
};
|
|
28
28
|
|
|
29
|
+
function flatAnimatedNodes(
|
|
30
|
+
transforms: $ReadOnlyArray<Transform<>>,
|
|
31
|
+
): Array<AnimatedNode> {
|
|
32
|
+
const nodes = [];
|
|
33
|
+
for (let ii = 0, length = transforms.length; ii < length; ii++) {
|
|
34
|
+
const transform = transforms[ii];
|
|
35
|
+
// There should be exactly one property in `transform`.
|
|
36
|
+
for (const key in transform) {
|
|
37
|
+
const value = transform[key];
|
|
38
|
+
if (value instanceof AnimatedNode) {
|
|
39
|
+
nodes.push(value);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return nodes;
|
|
44
|
+
}
|
|
45
|
+
|
|
29
46
|
export default class AnimatedTransform extends AnimatedWithChildren {
|
|
30
47
|
// NOTE: For potentially historical reasons, some operations only operate on
|
|
31
48
|
// the first level of AnimatedNode instances. This optimizes that bevavior.
|
|
32
|
-
#
|
|
49
|
+
#nodes: $ReadOnlyArray<AnimatedNode>;
|
|
33
50
|
|
|
34
51
|
_transforms: $ReadOnlyArray<Transform<>>;
|
|
35
52
|
|
|
36
|
-
|
|
53
|
+
/**
|
|
54
|
+
* Creates an `AnimatedTransform` if `transforms` contains `AnimatedNode`
|
|
55
|
+
* instances. Otherwise, returns `null`.
|
|
56
|
+
*/
|
|
57
|
+
static from(transforms: $ReadOnlyArray<Transform<>>): ?AnimatedTransform {
|
|
58
|
+
const nodes = flatAnimatedNodes(
|
|
59
|
+
// NOTE: This check should not be necessary, but the types are not
|
|
60
|
+
// enforced as of this writing. This check should be hoisted to
|
|
61
|
+
// instantiation sites.
|
|
62
|
+
Array.isArray(transforms) ? transforms : [],
|
|
63
|
+
);
|
|
64
|
+
if (nodes.length === 0) {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
return new AnimatedTransform(nodes, transforms);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
constructor(
|
|
71
|
+
nodes: $ReadOnlyArray<AnimatedNode>,
|
|
72
|
+
transforms: $ReadOnlyArray<Transform<>>,
|
|
73
|
+
) {
|
|
37
74
|
super();
|
|
75
|
+
this.#nodes = nodes;
|
|
38
76
|
this._transforms = transforms;
|
|
39
|
-
|
|
40
|
-
const shallowNodes = [];
|
|
41
|
-
// NOTE: This check should not be necessary, but the types are not enforced
|
|
42
|
-
// as of this writing. This check should be hoisted to instantiation sites.
|
|
43
|
-
if (Array.isArray(transforms)) {
|
|
44
|
-
for (let ii = 0, length = transforms.length; ii < length; ii++) {
|
|
45
|
-
const transform = transforms[ii];
|
|
46
|
-
// There should be exactly one property in `transform`.
|
|
47
|
-
for (const key in transform) {
|
|
48
|
-
const value = transform[key];
|
|
49
|
-
if (value instanceof AnimatedNode) {
|
|
50
|
-
shallowNodes.push(value);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
this.#shallowNodes = shallowNodes;
|
|
56
77
|
}
|
|
57
78
|
|
|
58
79
|
__makeNative(platformConfig: ?PlatformConfig) {
|
|
59
|
-
const nodes = this.#
|
|
80
|
+
const nodes = this.#nodes;
|
|
60
81
|
for (let ii = 0, length = nodes.length; ii < length; ii++) {
|
|
61
82
|
const node = nodes[ii];
|
|
62
83
|
node.__makeNative(platformConfig);
|
|
@@ -70,6 +91,18 @@ export default class AnimatedTransform extends AnimatedWithChildren {
|
|
|
70
91
|
);
|
|
71
92
|
}
|
|
72
93
|
|
|
94
|
+
__getValueWithStaticTransforms(
|
|
95
|
+
staticTransforms: $ReadOnlyArray<Object>,
|
|
96
|
+
): $ReadOnlyArray<Object> {
|
|
97
|
+
const values = [];
|
|
98
|
+
mapTransforms(this._transforms, node => {
|
|
99
|
+
values.push(node.__getValue());
|
|
100
|
+
});
|
|
101
|
+
// NOTE: We can depend on `this._transforms` and `staticTransforms` sharing
|
|
102
|
+
// a structure because of `useAnimatedPropsMemo`.
|
|
103
|
+
return mapTransforms(staticTransforms, () => values.shift());
|
|
104
|
+
}
|
|
105
|
+
|
|
73
106
|
__getAnimatedValue(): $ReadOnlyArray<Transform<any>> {
|
|
74
107
|
return mapTransforms(this._transforms, animatedNode =>
|
|
75
108
|
animatedNode.__getAnimatedValue(),
|
|
@@ -77,7 +110,7 @@ export default class AnimatedTransform extends AnimatedWithChildren {
|
|
|
77
110
|
}
|
|
78
111
|
|
|
79
112
|
__attach(): void {
|
|
80
|
-
const nodes = this.#
|
|
113
|
+
const nodes = this.#nodes;
|
|
81
114
|
for (let ii = 0, length = nodes.length; ii < length; ii++) {
|
|
82
115
|
const node = nodes[ii];
|
|
83
116
|
node.__addChild(this);
|
|
@@ -85,7 +118,7 @@ export default class AnimatedTransform extends AnimatedWithChildren {
|
|
|
85
118
|
}
|
|
86
119
|
|
|
87
120
|
__detach(): void {
|
|
88
|
-
const nodes = this.#
|
|
121
|
+
const nodes = this.#nodes;
|
|
89
122
|
for (let ii = 0, length = nodes.length; ii < length; ii++) {
|
|
90
123
|
const node = nodes[ii];
|
|
91
124
|
node.__removeChild(this);
|
|
@@ -28,12 +28,10 @@ export default class AnimatedWithChildren extends AnimatedNode {
|
|
|
28
28
|
const children = this._children;
|
|
29
29
|
let length = children.length;
|
|
30
30
|
if (length > 0) {
|
|
31
|
-
const nativeTag = this.__getNativeTag();
|
|
32
|
-
|
|
33
31
|
for (let ii = 0; ii < length; ii++) {
|
|
34
32
|
const child = children[ii];
|
|
35
33
|
child.__makeNative(platformConfig);
|
|
36
|
-
connectAnimatedNodes(
|
|
34
|
+
connectAnimatedNodes(this.__getNativeTag(), child.__getNativeTag());
|
|
37
35
|
}
|
|
38
36
|
}
|
|
39
37
|
}
|
|
@@ -8,8 +8,7 @@
|
|
|
8
8
|
* @format
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
import type {AnimatedPropsAllowlist} from './nodes/AnimatedProps';
|
|
13
12
|
import type {EventSubscription} from '../EventEmitter/NativeEventEmitter';
|
|
14
13
|
|
|
15
14
|
import * as ReactNativeFeatureFlags from '../../src/private/featureflags/ReactNativeFeatureFlags';
|
|
@@ -23,11 +22,13 @@ import AnimatedValue from './nodes/AnimatedValue';
|
|
|
23
22
|
import {
|
|
24
23
|
useCallback,
|
|
25
24
|
useEffect,
|
|
25
|
+
useInsertionEffect,
|
|
26
26
|
useLayoutEffect,
|
|
27
27
|
useMemo,
|
|
28
28
|
useReducer,
|
|
29
29
|
useRef,
|
|
30
30
|
} from 'react';
|
|
31
|
+
import {useAnimatedPropsMemo} from '../../src/private/animated/useAnimatedPropsMemo';
|
|
31
32
|
|
|
32
33
|
type ReducedProps<TProps> = {
|
|
33
34
|
...TProps,
|
|
@@ -36,34 +37,48 @@ type ReducedProps<TProps> = {
|
|
|
36
37
|
};
|
|
37
38
|
type CallbackRef<T> = T => mixed;
|
|
38
39
|
|
|
40
|
+
type UpdateCallback = () => void;
|
|
41
|
+
|
|
39
42
|
type AnimatedValueListeners = Array<{
|
|
40
43
|
propValue: AnimatedValue,
|
|
41
44
|
listenerId: string,
|
|
42
45
|
}>;
|
|
43
46
|
|
|
47
|
+
const useMemoOrAnimatedPropsMemo =
|
|
48
|
+
ReactNativeFeatureFlags.enableAnimatedPropsMemo()
|
|
49
|
+
? useAnimatedPropsMemo
|
|
50
|
+
: useMemo;
|
|
51
|
+
|
|
44
52
|
export default function useAnimatedProps<TProps: {...}, TInstance>(
|
|
45
53
|
props: TProps,
|
|
54
|
+
allowlist?: ?AnimatedPropsAllowlist,
|
|
46
55
|
): [ReducedProps<TProps>, CallbackRef<TInstance | null>] {
|
|
47
56
|
const [, scheduleUpdate] = useReducer<number, void>(count => count + 1, 0);
|
|
48
|
-
const onUpdateRef = useRef
|
|
57
|
+
const onUpdateRef = useRef<UpdateCallback | null>(null);
|
|
49
58
|
const timerRef = useRef<TimeoutID | null>(null);
|
|
50
59
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const node =
|
|
56
|
-
() =>
|
|
57
|
-
|
|
60
|
+
const allowlistIfEnabled = ReactNativeFeatureFlags.enableAnimatedAllowlist()
|
|
61
|
+
? allowlist
|
|
62
|
+
: null;
|
|
63
|
+
|
|
64
|
+
const node = useMemoOrAnimatedPropsMemo(
|
|
65
|
+
() =>
|
|
66
|
+
new AnimatedProps(
|
|
67
|
+
props,
|
|
68
|
+
() => onUpdateRef.current?.(),
|
|
69
|
+
allowlistIfEnabled,
|
|
70
|
+
),
|
|
71
|
+
[allowlistIfEnabled, props],
|
|
58
72
|
);
|
|
73
|
+
|
|
59
74
|
const useNativePropsInFabric =
|
|
60
75
|
ReactNativeFeatureFlags.shouldUseSetNativePropsInFabric();
|
|
61
76
|
const useSetNativePropsInNativeAnimationsInFabric =
|
|
62
77
|
ReactNativeFeatureFlags.shouldUseSetNativePropsInNativeAnimationsInFabric();
|
|
63
78
|
|
|
64
79
|
const useAnimatedPropsLifecycle =
|
|
65
|
-
ReactNativeFeatureFlags.
|
|
66
|
-
?
|
|
80
|
+
ReactNativeFeatureFlags.useInsertionEffectsForAnimations()
|
|
81
|
+
? useAnimatedPropsLifecycle_insertionEffects
|
|
67
82
|
: useAnimatedPropsLifecycle_layoutEffects;
|
|
68
83
|
|
|
69
84
|
useAnimatedPropsLifecycle(node);
|
|
@@ -195,14 +210,19 @@ export default function useAnimatedProps<TProps: {...}, TInstance>(
|
|
|
195
210
|
);
|
|
196
211
|
const callbackRef = useRefEffect<TInstance>(refEffect);
|
|
197
212
|
|
|
198
|
-
return [reduceAnimatedProps<TProps>(node), callbackRef];
|
|
213
|
+
return [reduceAnimatedProps<TProps>(node, props), callbackRef];
|
|
199
214
|
}
|
|
200
215
|
|
|
201
|
-
function reduceAnimatedProps<TProps>(
|
|
216
|
+
function reduceAnimatedProps<TProps>(
|
|
217
|
+
node: AnimatedProps,
|
|
218
|
+
props: TProps,
|
|
219
|
+
): ReducedProps<TProps> {
|
|
202
220
|
// Force `collapsable` to be false so that the native view is not flattened.
|
|
203
221
|
// Flattened views cannot be accurately referenced by the native driver.
|
|
204
222
|
return {
|
|
205
|
-
...
|
|
223
|
+
...(ReactNativeFeatureFlags.enableAnimatedPropsMemo()
|
|
224
|
+
? node.__getValueWithStaticProps(props)
|
|
225
|
+
: node.__getValue()),
|
|
206
226
|
collapsable: false,
|
|
207
227
|
};
|
|
208
228
|
}
|
|
@@ -301,10 +321,8 @@ function useAnimatedPropsLifecycle_layoutEffects(node: AnimatedProps): void {
|
|
|
301
321
|
* uses reference counting to determine when to recursively detach its children
|
|
302
322
|
* nodes. So in order to optimize this, we avoid detaching until the next attach
|
|
303
323
|
* unless we are unmounting.
|
|
304
|
-
*
|
|
305
|
-
* NOTE: unlike `useAnimatedPropsLifecycle_layoutEffects`, this version uses passive effects to setup animation graph.
|
|
306
324
|
*/
|
|
307
|
-
function
|
|
325
|
+
function useAnimatedPropsLifecycle_insertionEffects(node: AnimatedProps): void {
|
|
308
326
|
const prevNodeRef = useRef<?AnimatedProps>(null);
|
|
309
327
|
const isUnmountingRef = useRef<boolean>(false);
|
|
310
328
|
|
|
@@ -315,14 +333,14 @@ function useAnimatedPropsLifecycle_passiveEffects(node: AnimatedProps): void {
|
|
|
315
333
|
NativeAnimatedHelper.API.flushQueue();
|
|
316
334
|
});
|
|
317
335
|
|
|
318
|
-
|
|
336
|
+
useInsertionEffect(() => {
|
|
319
337
|
isUnmountingRef.current = false;
|
|
320
338
|
return () => {
|
|
321
339
|
isUnmountingRef.current = true;
|
|
322
340
|
};
|
|
323
341
|
}, []);
|
|
324
342
|
|
|
325
|
-
|
|
343
|
+
useInsertionEffect(() => {
|
|
326
344
|
node.__attach();
|
|
327
345
|
let drivenAnimationEndedListener: ?EventSubscription = null;
|
|
328
346
|
|