Skip to content

Commit 940d648

Browse files
huntiemeta-codesync[bot]
authored andcommitted
Improve generated API doc comments (match baseline) (#57380)
Summary: Pull Request resolved: #57380 Surface documentation on hover for more APIs in the generated TypeScript types (`types_generated/`). **Changes** - Fix doc comments that were previously detached from the intended symbol (`Modal`, `Button`, `TextInput`, `ScrollView`, and others). - Migrate doc comments/extra detail present in the legacy hand-written `.d.ts` files but missing from Flow source. - (**Note**: The quality of these vary — but lift the equivalent current state into Flow land.) - Reformat malformed JSDoc comments across the codebase. Comments only — no code or type changes. Does not look to audit/improve doc comments beyond today's manual TS API baseline. Changelog: [Internal] Differential Revision: D109316360
1 parent b364490 commit 940d648

37 files changed

Lines changed: 1124 additions & 687 deletions

packages/react-native/Libraries/ActionSheetIOS/ActionSheetIOS.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ export type ShareActionSheetIOSOptions = Readonly<{
3838
tintColor?: ?number,
3939
cancelButtonTintColor?: ?number,
4040
disabledButtonTintColor?: ?number,
41+
/**
42+
* The activities to exclude from the ActionSheet.
43+
* For example: ['com.apple.UIKit.activity.PostToTwitter']
44+
*/
4145
excludedActivityTypes?: ?Array<string>,
4246
userInterfaceStyle?: ?string,
4347
}>;

packages/react-native/Libraries/Alert/Alert.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,33 @@ export type AlertOptions = {
5757
* alerts. On iOS, you can show an alert that prompts the user to enter
5858
* some information.
5959
*
60+
* ## iOS
61+
*
62+
* On iOS you can specify any number of buttons. Each button can optionally
63+
* specify a style, which is one of 'default', 'cancel' or 'destructive'.
64+
*
65+
* ## Android
66+
*
67+
* On Android at most three buttons can be specified. Android has a concept
68+
* of a neutral, negative and a positive button:
69+
*
70+
* - If you specify one button, it will be the 'positive' one (such as 'OK')
71+
* - Two buttons mean 'negative', 'positive' (such as 'Cancel', 'OK')
72+
* - Three buttons mean 'neutral', 'negative', 'positive' (such as 'Later', 'Cancel', 'OK')
73+
*
74+
* ```
75+
* // Works on both iOS and Android
76+
* Alert.alert(
77+
* 'Alert Title',
78+
* 'My Alert Msg',
79+
* [
80+
* {text: 'Ask me later', onPress: () => console.log('Ask me later pressed')},
81+
* {text: 'Cancel', onPress: () => console.log('Cancel Pressed'), style: 'cancel'},
82+
* {text: 'OK', onPress: () => console.log('OK Pressed')},
83+
* ]
84+
* )
85+
* ```
86+
*
6087
* See https://reactnative.dev/docs/alert
6188
*/
6289
class Alert {

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,43 @@ const Animated: typeof AnimatedImplementation = Platform.isDisableAnimations
2424
: AnimatedImplementation;
2525

2626
export default {
27+
/**
28+
* FlatList and SectionList infer generic Type defined under their `data` and `section` props.
29+
*/
2730
get FlatList(): AnimatedFlatList<any> {
2831
return require('./components/AnimatedFlatList').default;
2932
},
33+
/**
34+
* Animated variants of the basic native views. Accepts Animated.Value for
35+
* props and style.
36+
*/
3037
get Image(): AnimatedImage {
3138
return require('./components/AnimatedImage').default;
3239
},
40+
/**
41+
* Animated variants of the basic native views. Accepts Animated.Value for
42+
* props and style.
43+
*/
3344
get ScrollView(): AnimatedScrollView {
3445
return require('./components/AnimatedScrollView').default;
3546
},
47+
/**
48+
* FlatList and SectionList infer generic Type defined under their `data` and `section` props.
49+
*/
3650
get SectionList(): AnimatedSectionList<any, any> {
3751
return require('./components/AnimatedSectionList').default;
3852
},
53+
/**
54+
* Animated variants of the basic native views. Accepts Animated.Value for
55+
* props and style.
56+
*/
3957
get Text(): AnimatedText {
4058
return require('./components/AnimatedText').default;
4159
},
60+
/**
61+
* Animated variants of the basic native views. Accepts Animated.Value for
62+
* props and style.
63+
*/
4264
get View(): AnimatedView {
4365
return require('./components/AnimatedView').default;
4466
},

packages/react-native/Libraries/Animated/AnimatedImplementation.js

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,29 @@ import AnimatedValue from './nodes/AnimatedValue';
4040
import AnimatedValueXY from './nodes/AnimatedValueXY';
4141

4242
export type CompositeAnimation = {
43+
/**
44+
* Animations are started by calling start() on your animation.
45+
* start() takes a completion callback that will be called when the
46+
* animation is done or when the animation is done because stop() was
47+
* called on it before it could finish.
48+
*
49+
* @param callback - Optional function that will be called
50+
* after the animation finished running normally or when the animation
51+
* is done because stop() was called on it before it could finish
52+
*
53+
* @example
54+
* Animated.timing({}).start(({ finished }) => {
55+
* // completion callback
56+
* });
57+
*/
4358
start: (callback?: ?EndCallback, isLooping?: boolean) => void,
59+
/**
60+
* Stops any running animation.
61+
*/
4462
stop: () => void,
63+
/**
64+
* Stops any running animation and resets the value to its original.
65+
*/
4566
reset: () => void,
4667
_startNativeLoop: (iterations?: number) => void,
4768
_isUsingNativeDriver: () => boolean,
@@ -621,21 +642,104 @@ export default {
621642
* See https://reactnative.dev/docs/animated#node
622643
*/
623644
Node: AnimatedNode,
645+
/**
646+
* Animates a value from an initial velocity to zero based on a decay
647+
* coefficient.
648+
*/
624649
decay: decayImpl,
650+
/**
651+
* Animates a value along a timed easing curve. The `Easing` module has tons
652+
* of pre-defined curves, or you can use your own function.
653+
*/
625654
timing: timingImpl,
655+
/**
656+
* Spring animation based on Rebound and Origami. Tracks velocity state to
657+
* create fluid motions as the `toValue` updates, and can be chained together.
658+
*/
626659
spring: springImpl,
660+
/**
661+
* Creates a new Animated value composed from two Animated values added
662+
* together.
663+
*/
627664
add: addImpl,
665+
/**
666+
* Creates a new Animated value composed by subtracting the second Animated
667+
* value from the first Animated value.
668+
*/
628669
subtract: subtractImpl,
670+
/**
671+
* Creates a new Animated value composed by dividing the first Animated
672+
* value by the second Animated value.
673+
*/
629674
divide: divideImpl,
675+
/**
676+
* Creates a new Animated value composed from two Animated values multiplied
677+
* together.
678+
*/
630679
multiply: multiplyImpl,
680+
/**
681+
* Creates a new Animated value that is the (non-negative) modulo of the
682+
* provided Animated value
683+
*/
631684
modulo: moduloImpl,
685+
/**
686+
* Create a new Animated value that is limited between 2 values. It uses the
687+
* difference between the last value so even if the value is far from the bounds
688+
* it will start changing when the value starts getting closer again.
689+
* (`value = clamp(value + diff, min, max)`).
690+
*
691+
* This is useful with scroll events, for example, to show the navbar when
692+
* scrolling up and to hide it when scrolling down.
693+
*/
632694
diffClamp: diffClampImpl,
695+
/**
696+
* Starts an animation after the given delay.
697+
*/
633698
delay: delayImpl,
699+
/**
700+
* Starts an array of animations in order, waiting for each to complete
701+
* before starting the next. If the current running animation is stopped, no
702+
* following animations will be started.
703+
*/
634704
sequence: sequenceImpl,
705+
/**
706+
* Starts an array of animations all at the same time. By default, if one
707+
* of the animations is stopped, they will all be stopped. You can override
708+
* this with the `stopTogether` flag.
709+
*/
635710
parallel: parallelImpl,
711+
/**
712+
* Array of animations may run in parallel (overlap), but are started in
713+
* sequence with successive delays. Nice for doing trailing effects.
714+
*/
636715
stagger: staggerImpl,
716+
/**
717+
* Loops a given animation continuously, so that each time it reaches the end,
718+
* it resets and begins again from the start. Can specify number of times to
719+
* loop using the key 'iterations' in the config. Will loop without blocking
720+
* the UI thread if the child animation is set to 'useNativeDriver'.
721+
*/
637722
loop: loopImpl,
723+
/**
724+
* Takes an array of mappings and extracts values from each arg accordingly,
725+
* then calls `setValue` on the mapped outputs. e.g.
726+
*
727+
*```javascript
728+
* onScroll={Animated.event(
729+
* [{nativeEvent: {contentOffset: {x: this._scrollX}}}]
730+
* {listener}, // Optional async listener
731+
* )
732+
* ...
733+
* onPanResponderMove: Animated.event([
734+
* null, // raw event arg ignored
735+
* {dx: this._panX}, // gestureState arg
736+
* ]),
737+
*```
738+
*/
638739
event: eventImpl,
740+
/**
741+
* Make any React component Animatable. Used to create `Animated.View`, etc.
742+
*/
639743
createAnimatedComponent,
640744
attachNativeEvent: attachNativeEventImpl,
641745
forkEvent: forkEventImpl,

packages/react-native/Libraries/BatchedBridge/NativeModules.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,13 @@ function updateErrorWithErrorData(
180180
return Object.assign(error, errorData || {});
181181
}
182182

183+
/**
184+
* Native Modules written in ObjectiveC/Swift/Java exposed via the RCTBridge
185+
* Define lazy getters for each module. These will return the module if already loaded, or load it if not.
186+
* See https://reactnative.dev/docs/native-modules-ios
187+
* @example
188+
* const MyModule = NativeModules.ModuleName
189+
*/
183190
/* $FlowFixMe[unclear-type] unclear type of NativeModules */
184191
let NativeModules: {[moduleName: string]: any, ...} = {};
185192
if (global.nativeModuleProxy) {

packages/react-native/Libraries/Components/ActivityIndicator/ActivityIndicator.js

Lines changed: 52 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010

1111
'use strict';
12+
1213
import type {HostInstance} from '../../../src/private/types/HostInstance';
1314
import type {ViewProps} from '../View/ViewPropTypes';
1415

@@ -30,39 +31,75 @@ type IndicatorSize = number | 'small' | 'large';
3031

3132
type ActivityIndicatorIOSProps = Readonly<{
3233
/**
33-
Whether the indicator should hide when not animating.
34-
35-
@platform ios
36-
*/
34+
* Whether the indicator should hide when not animating.
35+
*
36+
* @platform ios
37+
*/
3738
hidesWhenStopped?: ?boolean,
3839
}>;
40+
3941
/** @build-types emit-as-interface Uniwind compatibility */
4042
export type ActivityIndicatorProps = Readonly<{
4143
...ViewProps,
4244
...ActivityIndicatorIOSProps,
4345

4446
/**
45-
Whether to show the indicator (`true`) or hide it (`false`).
47+
* Whether to show the indicator (`true`) or hide it (`false`).
4648
*/
4749
animating?: ?boolean,
4850

4951
/**
50-
The foreground color of the spinner.
51-
52-
@default {@platform android} `null` (system accent default color)
53-
@default {@platform ios} '#999999'
54-
*/
52+
* The foreground color of the spinner.
53+
*
54+
* @default {@platform android} `null` (system accent default color)
55+
* @default {@platform ios} '#999999'
56+
*/
5557
color?: ?ColorValue,
5658

5759
/**
58-
Size of the indicator.
59-
60-
@type enum(`'small'`, `'large'`)
61-
@type {@platform android} number
62-
*/
60+
* Size of the indicator.
61+
*
62+
* Small has a height of 20, large has a height of 36.
63+
*
64+
* @type enum(`'small'`, `'large'`)
65+
* @type {@platform android} number
66+
*/
6367
size?: ?IndicatorSize,
6468
}>;
6569

70+
/**
71+
* Displays a circular loading indicator.
72+
*
73+
* Example:
74+
*
75+
* ```js
76+
* import React from 'react';
77+
* import {ActivityIndicator, StyleSheet, View} from 'react-native';
78+
*
79+
* const App = () => (
80+
* <View style={[styles.container, styles.horizontal]}>
81+
* <ActivityIndicator />
82+
* <ActivityIndicator size="large" />
83+
* <ActivityIndicator size="small" color="#0000ff" />
84+
* <ActivityIndicator size="large" color="#00ff00" />
85+
* </View>
86+
* );
87+
*
88+
* const styles = StyleSheet.create({
89+
* container: {
90+
* flex: 1,
91+
* justifyContent: 'center',
92+
* },
93+
* horizontal: {
94+
* flexDirection: 'row',
95+
* justifyContent: 'space-around',
96+
* padding: 10,
97+
* },
98+
* });
99+
*
100+
* export default App;
101+
* ```
102+
*/
66103
const ActivityIndicator: component(
67104
ref?: React.RefSetter<ActivityIndicatorInstance>,
68105
...props: ActivityIndicatorProps
@@ -129,38 +166,6 @@ const ActivityIndicator: component(
129166
);
130167
};
131168

132-
/**
133-
Displays a circular loading indicator.
134-
135-
```SnackPlayer name=ActivityIndicator%20Example
136-
import React from 'react';
137-
import {ActivityIndicator, StyleSheet, View} from 'react-native';
138-
139-
const App = () => (
140-
<View style={[styles.container, styles.horizontal]}>
141-
<ActivityIndicator />
142-
<ActivityIndicator size="large" />
143-
<ActivityIndicator size="small" color="#0000ff" />
144-
<ActivityIndicator size="large" color="#00ff00" />
145-
</View>
146-
);
147-
148-
const styles = StyleSheet.create({
149-
container: {
150-
flex: 1,
151-
justifyContent: 'center',
152-
},
153-
horizontal: {
154-
flexDirection: 'row',
155-
justifyContent: 'space-around',
156-
padding: 10,
157-
},
158-
});
159-
160-
export default App;
161-
```
162-
*/
163-
164169
ActivityIndicator.displayName = 'ActivityIndicator';
165170

166171
const styles = StyleSheet.create({

0 commit comments

Comments
 (0)