Skip to content

Commit 701de4e

Browse files
huntiemeta-codesync[bot]
authored andcommitted
Migrate/audit JSDoc on public APIs (APIs) (#57383)
Summary: Pull Request resolved: #57383 **Context** Strict TypeScript API readiness: High quality inline docs should reach users via TypeScript in their IDEs. **This diff** I asked Claude to crawl reactnative.dev and insert JSDoc comments into our core components, based on some manual-pass starting points. This is also a quality pass on all modules touched, standardising JSDoc use, and in some cases merging/removing redundant information (preferring the docs we’ve maintained more carefully on the website). **Manual edits** - `StyleSheet` Commit 2 of 2 (APIs). Replaces #57380. Changelog: [General][Added] - Strict TypeScript API: Component and API doc comment coverage has been significantly improved ___ Differential Revision: D110195868 fbshipit-source-id: 7d8880352c934702671f89a403f334e30b1e749c
1 parent fb2f319 commit 701de4e

48 files changed

Lines changed: 1250 additions & 653 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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

Lines changed: 19 additions & 24 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
}>;
@@ -50,9 +54,10 @@ export type ShareActionSheetError = Readonly<{
5054
}>;
5155

5256
/**
53-
* Display action sheets and share sheets on iOS.
57+
* Displays native iOS action sheets and share sheets.
5458
*
55-
* See https://reactnative.dev/docs/actionsheetios
59+
* @see https://reactnative.dev/docs/actionsheetios
60+
* @platform ios
5661
*/
5762
const ActionSheetIOS = {
5863
/**
@@ -62,15 +67,13 @@ const ActionSheetIOS = {
6267
*
6368
* - `options` (array of strings) - a list of button titles (required)
6469
* - `cancelButtonIndex` (int) - index of cancel button in `options`
65-
* - `destructiveButtonIndex` (int or array of ints) - index or indices of destructive buttons in `options`
70+
* - `destructiveButtonIndex` (int or array of ints) - indices of destructive buttons in `options`
6671
* - `title` (string) - a title to show above the action sheet
6772
* - `message` (string) - a message to show below the title
6873
* - `disabledButtonIndices` (array of numbers) - a list of button indices which should be disabled
6974
*
70-
* The 'callback' function takes one parameter, the zero-based index
71-
* of the selected item.
72-
*
73-
* See https://reactnative.dev/docs/actionsheetios#showactionsheetwithoptions
75+
* The `callback` function receives the zero-based index of the selected
76+
* item.
7477
*/
7578
showActionSheetWithOptions(
7679
options: ActionSheetIOSOptions,
@@ -136,27 +139,19 @@ const ActionSheetIOS = {
136139
},
137140

138141
/**
139-
* Display the iOS share sheet. The `options` object should contain
140-
* one or both of `message` and `url` and can additionally have
141-
* a `subject` or `excludedActivityTypes`:
142+
* Display the iOS share sheet. The `options` object should contain one or
143+
* both of `message` and `url` and can additionally have a `subject` or
144+
* `excludedActivityTypes`:
142145
*
143146
* - `url` (string) - a URL to share
144147
* - `message` (string) - a message to share
145148
* - `subject` (string) - a subject for the message
146-
* - `excludedActivityTypes` (array) - the activities to exclude from
147-
* the ActionSheet
149+
* - `excludedActivityTypes` (array) - the activities to exclude from the ActionSheet
148150
* - `tintColor` (color) - tint color of the buttons
149151
*
150-
* The 'failureCallback' function takes one parameter, an error object.
151-
* The only property defined on this object is an optional `stack` property
152-
* of type `string`.
153-
*
154-
* The 'successCallback' function takes two parameters:
155-
*
156-
* - a boolean value signifying success or failure
157-
* - a string that, in the case of success, indicates the method of sharing
158-
*
159-
* See https://reactnative.dev/docs/actionsheetios#showshareactionsheetwithoptions
152+
* The `failureCallback` function receives an error object. The
153+
* `successCallback` function receives a boolean indicating success and a
154+
* string describing the sharing method used.
160155
*/
161156
showShareActionSheetWithOptions(
162157
options: ShareActionSheetIOSOptions,
@@ -186,8 +181,8 @@ const ActionSheetIOS = {
186181
},
187182

188183
/**
189-
* Dismisses the most upper iOS action sheet presented, if no action sheet is
190-
* present a warning is displayed.
184+
* Dismiss the most upper action sheet currently presented. Displays a
185+
* warning if no action sheet is present.
191186
*/
192187
dismissActionSheet: () => {
193188
invariant(RCTActionSheetManager, "ActionSheetManager doesn't exist");

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

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,43 @@ export type AlertOptions = {
5757
* alerts. On iOS, you can show an alert that prompts the user to enter
5858
* some information.
5959
*
60-
* See https://reactnative.dev/docs/alert
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+
* Example:
75+
*
76+
* ```tsx
77+
* // Works on both iOS and Android
78+
* Alert.alert(
79+
* 'Alert Title',
80+
* 'My Alert Msg',
81+
* [
82+
* {text: 'Ask me later', onPress: () => console.log('Ask me later pressed')},
83+
* {text: 'Cancel', onPress: () => console.log('Cancel Pressed'), style: 'cancel'},
84+
* {text: 'OK', onPress: () => console.log('OK Pressed')},
85+
* ]
86+
* )
87+
* ```
88+
*
89+
* @see https://reactnative.dev/docs/alert
6190
*/
6291
class Alert {
92+
/**
93+
* Display an alert dialog with the specified title, message, and buttons.
94+
* On Android, at most three buttons can be specified. On iOS, any number of
95+
* buttons can be used.
96+
*/
6397
static alert(
6498
title: ?string,
6599
message?: ?string,
@@ -140,6 +174,9 @@ class Alert {
140174
}
141175

142176
/**
177+
* Create and display a prompt to enter text. Accepts a title, message,
178+
* callback or buttons, input type, default value, keyboard type, and options.
179+
*
143180
* @platform ios
144181
*/
145182
static prompt(

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/Animated/Easing.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ let ease;
1515
export type EasingFunction = (t: number) => number;
1616

1717
/**
18-
* The `Easing` module implements common easing functions. This module is used
19-
* by [Animate.timing()](docs/animate.html#timing) to convey physically
20-
* believable motion in animations.
18+
* Implements common easing functions for use with `Animated.timing()` to convey
19+
* physically believable motion in animations.
2120
*
2221
* You can find a visualization of some common easing functions at
2322
* http://easings.net/
@@ -58,6 +57,8 @@ export type EasingFunction = (t: number) => number;
5857
* - [`in`](docs/easing.html#in) runs an easing function forwards
5958
* - [`inOut`](docs/easing.html#inout) makes any easing function symmetrical
6059
* - [`out`](docs/easing.html#out) runs an easing function backwards
60+
*
61+
* @see https://reactnative.dev/docs/easing
6162
*/
6263
const EasingStatic = {
6364
/**

0 commit comments

Comments
 (0)