Skip to content

Commit 37bd5e6

Browse files
authored
Export Animated components as named exports (#59221)
1 parent d9c05a1 commit 37bd5e6

7 files changed

Lines changed: 128 additions & 76 deletions

File tree

‎packages/react-native/Libraries/Animated/AnimatedExports.js‎

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,41 +27,37 @@ const Animated: typeof AnimatedImplementation = Platform.isDisableAnimations
2727

2828
export default {
2929
/**
30-
* FlatList and SectionList infer generic Type defined under their `data` and `section` props.
30+
* @deprecated Use `AnimatedFlatList` instead.
3131
*/
3232
get FlatList(): AnimatedFlatList<> {
3333
return require('./components/AnimatedFlatList').default;
3434
},
3535
/**
36-
* Animated variants of the basic native views. Accepts Animated.Value for
37-
* props and style.
36+
* @deprecated Use `AnimatedImage` instead.
3837
*/
3938
get Image(): AnimatedImage {
4039
return require('./components/AnimatedImage').default;
4140
},
4241
/**
43-
* Animated variants of the basic native views. Accepts Animated.Value for
44-
* props and style.
42+
* @deprecated Use `AnimatedScrollView` instead.
4543
*/
4644
get ScrollView(): AnimatedScrollView {
4745
return require('./components/AnimatedScrollView').default;
4846
},
4947
/**
50-
* FlatList and SectionList infer generic Type defined under their `data` and `section` props.
48+
* @deprecated Use `AnimatedSectionList` instead.
5149
*/
5250
get SectionList(): AnimatedSectionList<> {
5351
return require('./components/AnimatedSectionList').default;
5452
},
5553
/**
56-
* Animated variants of the basic native views. Accepts Animated.Value for
57-
* props and style.
54+
* @deprecated Use `AnimatedText` instead.
5855
*/
5956
get Text(): AnimatedText {
6057
return require('./components/AnimatedText').default;
6158
},
6259
/**
63-
* Animated variants of the basic native views. Accepts Animated.Value for
64-
* props and style.
60+
* @deprecated Use `AnimatedView` instead.
6561
*/
6662
get View(): AnimatedView {
6763
return require('./components/AnimatedView').default;

‎packages/react-native/Libraries/Animated/AnimatedExports.js.flow‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,17 @@ export type {DecayAnimationConfig} from './animations/DecayAnimation';
1515
export type {SpringAnimationConfig} from './animations/SpringAnimation';
1616
export type {TimingAnimationConfig} from './animations/TimingAnimation';
1717

18+
/** @deprecated Use `AnimatedFlatList` instead. */
1819
export {default as FlatList} from './components/AnimatedFlatList';
20+
/** @deprecated Use `AnimatedImage` instead. */
1921
export {default as Image} from './components/AnimatedImage';
22+
/** @deprecated Use `AnimatedScrollView` instead. */
2023
export {default as ScrollView} from './components/AnimatedScrollView';
24+
/** @deprecated Use `AnimatedSectionList` instead. */
2125
export {default as SectionList} from './components/AnimatedSectionList';
26+
/** @deprecated Use `AnimatedText` instead. */
2227
export {default as Text} from './components/AnimatedText';
28+
/** @deprecated Use `AnimatedView` instead. */
2329
export {default as View} from './components/AnimatedView';
2430
export {default as Color} from './nodes/AnimatedColor';
2531
export {AnimatedEvent as Event} from './AnimatedEvent';

‎packages/react-native/ReactNativeApi.d.ts‎

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<ed9c28d3d67e72e66c1a86081d61dee7>>
7+
* @generated SignedSource<<57a22e3b7e5bbdb70ec787177e97ef4b>>
88
*
99
* This file was generated by scripts/js-api/build-types/index.js.
1010
*/
@@ -22,11 +22,6 @@
2222
/* eslint-disable redundant-undefined/redundant-undefined */
2323

2424
import * as React from "react"
25-
declare const $$AnimatedFlatList: typeof AnimatedFlatList_default
26-
declare const $$AnimatedImage: AnimatedComponentType<
27-
ImageProps,
28-
React.ComponentRef<typeof Image>
29-
>
3025
declare const $$AnimatedImplementation: {
3126
add: typeof addImpl
3227
attachNativeEvent: typeof attachNativeEventImpl
@@ -54,16 +49,6 @@ declare const $$AnimatedImplementation: {
5449
Value: typeof AnimatedValue_default
5550
ValueXY: typeof AnimatedValueXY_default
5651
}
57-
declare const $$AnimatedScrollView: typeof AnimatedScrollView_default
58-
declare const $$AnimatedSectionList: typeof AnimatedSectionList_default
59-
declare const $$AnimatedText: AnimatedComponentType<
60-
TextProps,
61-
React.ComponentRef<typeof Text>
62-
>
63-
declare const $$AnimatedView: AnimatedComponentType<
64-
ViewProps,
65-
React.ComponentRef<typeof View>
66-
>
6752
declare const $$flattenStyle: typeof flattenStyle_default
6853
declare const $$index: {
6954
keyExtractor: typeof keyExtractor
@@ -135,20 +120,35 @@ declare const addImpl: (
135120
a: AnimatedNode_default | number,
136121
b: AnimatedNode_default | number,
137122
) => AnimatedAddition_default
123+
declare const AnimatedFlatList: typeof AnimatedFlatList_default
138124
declare const AnimatedFlatList_default: <ItemT = any>(
139125
props: Omit<AnimatedProps<FlatListProps<ItemT>>, "ref"> & {
140126
ref?: React.Ref<FlatList<ItemT>>
141127
},
142128
) => React.ReactNode
129+
declare const AnimatedImage: AnimatedComponentType<
130+
ImageProps,
131+
React.ComponentRef<typeof Image>
132+
>
133+
declare const AnimatedScrollView: typeof AnimatedScrollView_default
143134
declare const AnimatedScrollView_default: AnimatedComponentType<
144135
ScrollViewProps,
145136
AnimatedScrollViewInstance
146137
>
138+
declare const AnimatedSectionList: typeof AnimatedSectionList_default
147139
declare const AnimatedSectionList_default: <ItemT = any, SectionT = any>(
148140
props: Omit<AnimatedProps<SectionListProps<ItemT, SectionT>>, "ref"> & {
149141
ref?: React.Ref<SectionList<ItemT, SectionT>>
150142
},
151143
) => React.ReactNode
144+
declare const AnimatedText: AnimatedComponentType<
145+
TextProps,
146+
React.ComponentRef<typeof Text>
147+
>
148+
declare const AnimatedView: AnimatedComponentType<
149+
ViewProps,
150+
React.ComponentRef<typeof View>
151+
>
152152
declare const AppState: typeof AppState_default
153153
declare const AppState_default: AppStateImpl
154154
declare const AssetRegistry: {
@@ -906,13 +906,7 @@ declare class _TextInputInstance extends ReactNativeElement_default {
906906
isFocused(): boolean
907907
setSelection(start: number, end: number): void
908908
}
909-
declare type $$AnimatedFlatList = typeof $$AnimatedFlatList
910-
declare type $$AnimatedImage = typeof $$AnimatedImage
911909
declare type $$AnimatedImplementation = typeof $$AnimatedImplementation
912-
declare type $$AnimatedScrollView = typeof $$AnimatedScrollView
913-
declare type $$AnimatedSectionList = typeof $$AnimatedSectionList
914-
declare type $$AnimatedText = typeof $$AnimatedText
915-
declare type $$AnimatedView = typeof $$AnimatedView
916910
declare type $$flattenStyle = typeof $$flattenStyle
917911
declare type $$index = typeof $$index
918912
declare type $$NativeDeviceInfo = typeof $$NativeDeviceInfo
@@ -1208,12 +1202,12 @@ declare namespace Animated {
12081202
DecayAnimationConfig,
12091203
SpringAnimationConfig,
12101204
TimingAnimationConfig,
1211-
$$AnimatedFlatList as FlatList,
1212-
$$AnimatedImage as Image,
1213-
$$AnimatedScrollView as ScrollView,
1214-
$$AnimatedSectionList as SectionList,
1215-
$$AnimatedText as Text,
1216-
$$AnimatedView as View,
1205+
AnimatedFlatList as FlatList,
1206+
AnimatedImage as Image,
1207+
AnimatedScrollView as ScrollView,
1208+
AnimatedSectionList as SectionList,
1209+
AnimatedText as Text,
1210+
AnimatedView as View,
12171211
AnimatedColor_default as Color,
12181212
AnimatedEvent as Event,
12191213
AnimatedInterpolation_default as Interpolation,
@@ -1319,6 +1313,8 @@ declare class AnimatedEvent {
13191313
config: EventConfig<any>,
13201314
)
13211315
}
1316+
declare type AnimatedFlatList = typeof AnimatedFlatList
1317+
declare type AnimatedImage = typeof AnimatedImage
13221318
declare class AnimatedInterpolation_default<
13231319
OutputT extends InterpolationConfigSupportedOutputType,
13241320
> extends AnimatedWithChildren_default {
@@ -1379,7 +1375,9 @@ declare type AnimatedProps<Props extends {}> = LooseOmit<
13791375
"ref"
13801376
> &
13811377
PassThroughProps
1378+
declare type AnimatedScrollView = typeof AnimatedScrollView
13821379
declare type AnimatedScrollViewInstance = React.ComponentRef<typeof ScrollView>
1380+
declare type AnimatedSectionList = typeof AnimatedSectionList
13831381
declare class AnimatedSubtraction_default extends AnimatedWithChildren_default {
13841382
constructor(
13851383
a: AnimatedNode_default | number,
@@ -1390,6 +1388,7 @@ declare class AnimatedSubtraction_default extends AnimatedWithChildren_default {
13901388
config: InterpolationConfigType<OutputT>,
13911389
): AnimatedInterpolation_default<OutputT>
13921390
}
1391+
declare type AnimatedText = typeof AnimatedText
13931392
declare class AnimatedTracking_default extends AnimatedNode_default {
13941393
constructor(
13951394
value: AnimatedValue_default,
@@ -1464,6 +1463,7 @@ declare type AnimatedValueXYConfig = Readonly<
14641463
useNativeDriver: boolean
14651464
}
14661465
>
1466+
declare type AnimatedView = typeof AnimatedView
14671467
declare class AnimatedWithChildren_default extends AnimatedNode_default {}
14681468
declare class Animation_default {
14691469
constructor(config: AnimationConfig)
@@ -5791,7 +5791,13 @@ export {
57915791
AlertOptions, // 8a116d2a
57925792
AlertType, // 5ab91217
57935793
AndroidKeyboardEvent, // e03becc8
5794-
Animated, // 33fe7464
5794+
Animated, // 82e01a3c
5795+
AnimatedFlatList, // a4467eeb
5796+
AnimatedImage, // f02097b9
5797+
AnimatedScrollView, // faf0e26c
5798+
AnimatedSectionList, // 41cf38c7
5799+
AnimatedText, // ddb4c5b7
5800+
AnimatedView, // b3b343f4
57955801
AppConfig, // 35c0ca70
57965802
AppRegistry, // edec2a30
57975803
AppState, // 12012be5

‎packages/react-native/__typetests__/animated.tsx‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ import * as React from 'react';
1111

1212
import {
1313
Animated,
14+
AnimatedFlatList,
15+
AnimatedImage,
16+
AnimatedSectionList,
17+
AnimatedView,
1418
View,
1519
NativeSyntheticEvent,
1620
NativeScrollEvent,
@@ -163,11 +167,11 @@ function TestAnimatedAPI() {
163167
listener,
164168
});
165169

166-
const AnimatedView = Animated.createAnimatedComponent(View);
170+
const AnimatedCreatedView = Animated.createAnimatedComponent(View);
167171
const ref = React.useRef<React.ComponentRef<typeof View>>(null);
168172
return (
169173
<View ref={ref}>
170-
<Animated.View
174+
<AnimatedView
171175
ref={ref}
172176
style={[
173177
position.getLayout(),
@@ -176,17 +180,17 @@ function TestAnimatedAPI() {
176180
},
177181
]}
178182
/>
179-
<AnimatedView ref={ref} style={{top: 3}}>
183+
<AnimatedCreatedView ref={ref} style={{top: 3}}>
180184
i has children
181-
</AnimatedView>
185+
</AnimatedCreatedView>
182186
<AnimatedComp ref={AnimatedCompRef} width={v1} />
183187
<ForwardComp ref={ForwardCompRef} width={1} />
184188
<AnimatedForwardComp ref={AnimatedForwardCompRef} width={10} />
185-
<Animated.Image
189+
<AnimatedImage
186190
style={{transform: position.getTranslateTransform()}}
187191
source={{uri: 'https://picsum.photos/200'}}
188192
/>
189-
<Animated.View
193+
<AnimatedView
190194
testID="expect-type-animated-view"
191195
style={{opacity: v1}}
192196
onLayout={event => {
@@ -197,7 +201,7 @@ function TestAnimatedAPI() {
197201
}}
198202
/>
199203
;
200-
<Animated.FlatList
204+
<AnimatedFlatList
201205
testID="expect-type-animated-flatlist"
202206
style={{opacity: v1}}
203207
data={[1] as ReadonlyArray<number>}
@@ -207,7 +211,7 @@ function TestAnimatedAPI() {
207211
}}
208212
/>
209213
;
210-
<Animated.SectionList
214+
<AnimatedSectionList
211215
testID="expect-type-animated-sectionlist"
212216
style={{opacity: v1}}
213217
sections={
@@ -230,7 +234,7 @@ function TestAnimatedAPI() {
230234
/>
231235
;
232236
{/* @ts-expect-error the transform object must contain only one key-value pair */}
233-
<Animated.View style={{transform: [{scale: 1, translateX: 20}]}} />;
237+
<AnimatedView style={{transform: [{scale: 1, translateX: 20}]}} />;
234238
</View>
235239
);
236240
}

‎packages/react-native/index.js‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,26 @@ module.exports = {
221221
get Animated() {
222222
return require('./Libraries/Animated/Animated').default;
223223
},
224+
get AnimatedFlatList() {
225+
return require('./Libraries/Animated/components/AnimatedFlatList').default;
226+
},
227+
get AnimatedImage() {
228+
return require('./Libraries/Animated/components/AnimatedImage').default;
229+
},
230+
get AnimatedScrollView() {
231+
return require('./Libraries/Animated/components/AnimatedScrollView')
232+
.default;
233+
},
234+
get AnimatedSectionList() {
235+
return require('./Libraries/Animated/components/AnimatedSectionList')
236+
.default;
237+
},
238+
get AnimatedText() {
239+
return require('./Libraries/Animated/components/AnimatedText').default;
240+
},
241+
get AnimatedView() {
242+
return require('./Libraries/Animated/components/AnimatedView').default;
243+
},
224244
get Appearance() {
225245
return require('./Libraries/Utilities/Appearance');
226246
},

‎packages/react-native/index.js.flow‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,12 @@ export type {
260260
export {default as Alert} from './Libraries/Alert/Alert';
261261

262262
export {default as Animated} from './Libraries/Animated/Animated';
263+
export {default as AnimatedFlatList} from './Libraries/Animated/components/AnimatedFlatList';
264+
export {default as AnimatedImage} from './Libraries/Animated/components/AnimatedImage';
265+
export {default as AnimatedScrollView} from './Libraries/Animated/components/AnimatedScrollView';
266+
export {default as AnimatedSectionList} from './Libraries/Animated/components/AnimatedSectionList';
267+
export {default as AnimatedText} from './Libraries/Animated/components/AnimatedText';
268+
export {default as AnimatedView} from './Libraries/Animated/components/AnimatedView';
263269

264270
export * as Appearance from './Libraries/Utilities/Appearance';
265271

0 commit comments

Comments
 (0)