Skip to content

Commit 16487f3

Browse files
Christine AbernathyMorgan Pretty
authored andcommitted
Improve autogen for reference docs including jsdoc support
Summary: As part of improving the API and Component reference docs facebook#8154 this pull request adds the following: - jsdoc support for API docs. See the AlertIOS changes as an example. - type definitions support and added to both API and Component docs. This is supported via react-docgen and jsdoc. - better formatting of method properties (now shown in a table). FYI, API and Component docs were previously generated in two different ways. Components were using react-docgen and that basically remains as-is. APIs were using custom parsing code and that's been switched to use a jsdoc parser + react-docgen as an option for typedefs (it could also use the jsdoc parser). Two docs have been updated to showcase how we'd like the new docs to look: - AlertIOS (API): showing method parameters, examples, typedefs, more details overall. - Statusbar (Component): showing method parameters, typedefs, more details overall. **Note**: To convert new API docs to use the new format, add `jsdoc` to the initial file comment. C Closes facebook#8196 Differential Revision: D3465037 Pulled By: lacker fbshipit-source-id: 78415d44bc5be02db802f5b1f7a0b249689abdf7
1 parent 9d10d8d commit 16487f3

File tree

9 files changed

+906
-98
lines changed

9 files changed

+906
-98
lines changed

Libraries/Components/StatusBar/StatusBar.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,35 @@ const processColor = require('processColor');
1919

2020
const StatusBarManager = require('NativeModules').StatusBarManager;
2121

22+
/**
23+
* Status bar style
24+
*/
2225
export type StatusBarStyle = $Enum<{
26+
/**
27+
* Default status bar style
28+
*/
2329
'default': string,
30+
/**
31+
* Dark background style
32+
*/
2433
'light-content': string,
2534
}>;
2635

36+
/**
37+
* Status bar animation
38+
*/
2739
export type StatusBarAnimation = $Enum<{
40+
/**
41+
* No animation
42+
*/
2843
'none': string,
44+
/**
45+
* Fade animation
46+
*/
2947
'fade': string,
48+
/**
49+
* Slide animation
50+
*/
3051
'slide': string,
3152
}>;
3253

@@ -135,6 +156,13 @@ const StatusBar = React.createClass({
135156

136157
// Provide an imperative API as static functions of the component.
137158
// See the corresponding prop for more detail.
159+
160+
/**
161+
* Show or hide the status bar
162+
* @param hidden The dialog's title.
163+
* @param animation Optional animation when
164+
* changing the status bar hidden property.
165+
*/
138166
setHidden(hidden: boolean, animation?: StatusBarAnimation) {
139167
animation = animation || 'none';
140168
StatusBar._defaultProps.hidden.value = hidden;
@@ -145,6 +173,11 @@ const StatusBar = React.createClass({
145173
}
146174
},
147175

176+
/**
177+
* Set the status bar style
178+
* @param style Status bar style to set
179+
* @param animated Animate the style change.
180+
*/
148181
setBarStyle(style: StatusBarStyle, animated?: boolean) {
149182
if (Platform.OS !== 'ios') {
150183
console.warn('`setBarStyle` is only available on iOS');
@@ -155,6 +188,10 @@ const StatusBar = React.createClass({
155188
StatusBarManager.setStyle(style, animated);
156189
},
157190

191+
/**
192+
* Control the visibility of the network activity indicator
193+
* @param visible Show the indicator.
194+
*/
158195
setNetworkActivityIndicatorVisible(visible: boolean) {
159196
if (Platform.OS !== 'ios') {
160197
console.warn('`setNetworkActivityIndicatorVisible` is only available on iOS');
@@ -164,6 +201,11 @@ const StatusBar = React.createClass({
164201
StatusBarManager.setNetworkActivityIndicatorVisible(visible);
165202
},
166203

204+
/**
205+
* Set the background color for the status bar
206+
* @param color Background color.
207+
* @param animated Animate the style change.
208+
*/
167209
setBackgroundColor(color: string, animated?: boolean) {
168210
if (Platform.OS !== 'android') {
169211
console.warn('`setBackgroundColor` is only available on Android');
@@ -174,6 +216,10 @@ const StatusBar = React.createClass({
174216
StatusBarManager.setColor(processColor(color), animated);
175217
},
176218

219+
/**
220+
* Control the translucency of the status bar
221+
* @param translucent Set as translucent.
222+
*/
177223
setTranslucent(translucent: boolean) {
178224
if (Platform.OS !== 'android') {
179225
console.warn('`setTranslucent` is only available on Android');

Libraries/Utilities/AlertIOS.js

Lines changed: 106 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,64 +8,129 @@
88
*
99
* @providesModule AlertIOS
1010
* @flow
11+
* @jsdoc
1112
*/
1213
'use strict';
1314

1415
var RCTAlertManager = require('NativeModules').AlertManager;
1516

17+
/**
18+
* An Alert button type
19+
*/
1620
export type AlertType = $Enum<{
21+
/**
22+
* Default alert with no inputs
23+
*/
1724
'default': string;
25+
/**
26+
* Plain text input alert
27+
*/
1828
'plain-text': string;
29+
/**
30+
* Secure text input alert
31+
*/
1932
'secure-text': string;
33+
/**
34+
* Login and password alert
35+
*/
2036
'login-password': string;
2137
}>;
2238

39+
/**
40+
* An Alert button style
41+
*/
2342
export type AlertButtonStyle = $Enum<{
43+
/**
44+
* Default button style
45+
*/
2446
'default': string;
47+
/**
48+
* Cancel button style
49+
*/
2550
'cancel': string;
51+
/**
52+
* Destructive button style
53+
*/
2654
'destructive': string;
2755
}>;
2856

57+
/**
58+
* Array or buttons
59+
* @typedef {Array} ButtonsArray
60+
* @property {string=} text Button label
61+
* @property {Function=} onPress Callback function when button pressed
62+
* @property {AlertButtonStyle=} style Button style
63+
*/
2964
type ButtonsArray = Array<{
65+
/**
66+
* Button label
67+
*/
3068
text?: string;
69+
/**
70+
* Callback function when button pressed
71+
*/
3172
onPress?: ?Function;
73+
/**
74+
* Button style
75+
*/
3276
style?: AlertButtonStyle;
3377
}>;
3478

3579
/**
36-
* The AlertsIOS utility provides two functions: `alert` and `prompt`. All
37-
* functionality available through `AlertIOS.alert` is also available in the
38-
* cross-platform `Alert.alert`, which we recommend you use if you don't need
39-
* iOS-specific functionality.
80+
* @description
81+
* `AlertIOS` provides functionality to create an iOS alert dialog with a
82+
* message or create a prompt for user input.
83+
*
84+
* Creating an iOS alert:
4085
*
41-
* `AlertIOS.prompt` allows you to prompt the user for input inside of an
42-
* alert popup.
86+
* ```
87+
* AlertIOS.alert(
88+
* 'Sync Complete',
89+
* 'All your data are belong to us.'
90+
* );
91+
* ```
92+
*
93+
* Creating an iOS prompt:
94+
*
95+
* ```
96+
* AlertIOS.prompt(
97+
* 'Enter a value',
98+
* null,
99+
* text => console.log("You entered "+text)
100+
* );
101+
* ```
102+
*
103+
* We recommend using the [`Alert.alert`](/docs/alert.html) method for
104+
* cross-platform support if you don't need to create iOS-only prompts.
43105
*
44106
*/
45107
class AlertIOS {
46108
/**
47-
* Creates a popup to alert the user. See
48-
* [Alert](docs/alert.html).
49-
*
50-
* - title: string -- The dialog's title.
51-
* - message: string -- An optional message that appears above the text input.
52-
* - callbackOrButtons -- This optional argument should be either a
53-
* single-argument function or an array of buttons. If passed a function,
54-
* it will be called when the user taps 'OK'.
109+
* Create and display a popup alert.
110+
* @static
111+
* @method alert
112+
* @param title The dialog's title.
113+
* @param message An optional message that appears below
114+
* the dialog's title.
115+
* @param callbackOrButtons This optional argument should
116+
* be either a single-argument function or an array of buttons. If passed
117+
* a function, it will be called when the user taps 'OK'.
55118
*
56119
* If passed an array of button configurations, each button should include
57-
* a `text` key, as well as optional `onPress` and `style` keys.
58-
* `style` should be one of 'default', 'cancel' or 'destructive'.
59-
* - type -- *deprecated, do not use*
120+
* a `text` key, as well as optional `onPress` and `style` keys. `style`
121+
* should be one of 'default', 'cancel' or 'destructive'.
122+
* @param type Deprecated, do not use.
60123
*
61-
* Example:
124+
* @example <caption>Example with custom buttons</caption>
62125
*
63-
* ```
64126
* AlertIOS.alert(
65-
* 'Sync Complete',
66-
* 'All your data are belong to us.'
127+
* 'Update available',
128+
* 'Keep your app up to date to enjoy the latest features',
129+
* [
130+
* {text: 'Cancel', onPress: () => console.log('Cancel Pressed'), style: 'cancel'},
131+
* {text: 'Install', onPress: () => console.log('Install Pressed')},
132+
* ],
67133
* );
68-
* ```
69134
*/
70135
static alert(
71136
title: ?string,
@@ -82,23 +147,26 @@ class AlertIOS {
82147
}
83148

84149
/**
85-
* Prompt the user to enter some text.
86-
*
87-
* - title: string -- The dialog's title.
88-
* - message: string -- An optional message that appears above the text input.
89-
* - callbackOrButtons -- This optional argument should be either a
90-
* single-argument function or an array of buttons. If passed a function,
91-
* it will be called with the prompt's value when the user taps 'OK'.
150+
* Create and display a prompt to enter some text.
151+
* @static
152+
* @method prompt
153+
* @param title The dialog's title.
154+
* @param message An optional message that appears above the text
155+
* input.
156+
* @param callbackOrButtons This optional argument should
157+
* be either a single-argument function or an array of buttons. If passed
158+
* a function, it will be called with the prompt's value when the user
159+
* taps 'OK'.
92160
*
93161
* If passed an array of button configurations, each button should include
94-
* a `text` key, as well as optional `onPress` and `style` keys (see example).
95-
* `style` should be one of 'default', 'cancel' or 'destructive'.
96-
* - type: string -- This configures the text input. One of 'plain-text',
162+
* a `text` key, as well as optional `onPress` and `style` keys (see
163+
* example). `style` should be one of 'default', 'cancel' or 'destructive'.
164+
* @param type This configures the text input. One of 'plain-text',
97165
* 'secure-text' or 'login-password'.
98-
* - defaultValue: string -- the default value for the text field.
166+
* @param defaultValue The dialog's title.
167+
*
168+
* @example <caption>Example with custom buttons</caption>
99169
*
100-
* Example with custom buttons:
101-
* ```
102170
* AlertIOS.prompt(
103171
* 'Enter password',
104172
* 'Enter your password to claim your $1.5B in lottery winnings',
@@ -108,18 +176,16 @@ class AlertIOS {
108176
* ],
109177
* 'secure-text'
110178
* );
111-
* ```
112179
*
113-
* Example with the default button and a custom callback:
114-
* ```
180+
* @example <caption>Example with the default button and a custom callback</caption>
181+
*
115182
* AlertIOS.prompt(
116183
* 'Update username',
117184
* null,
118185
* text => console.log("Your username is "+text),
119186
* null,
120187
* 'default'
121-
* )
122-
* ```
188+
* );
123189
*/
124190
static prompt(
125191
title: ?string,

website/jsdocs/jsdoc-conf.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"tags": {
3+
"allowUnknownTags": true,
4+
"dictionaries": ["jsdoc","closure"]
5+
},
6+
"source": {
7+
"includePattern": ".+\\.js(doc)?$",
8+
"excludePattern": "(^|\\/|\\\\)_"
9+
},
10+
"plugins": ["./jsdocs/jsdoc-plugin-values"],
11+
"templates": {
12+
"cleverLinks": true,
13+
"monospaceLinks": false
14+
}
15+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
exports.defineTags = function(dictionary) {
2+
dictionary.defineTag('value', {
3+
mustHaveValue: true,
4+
canHaveType: true,
5+
canHaveName: true,
6+
onTagged: function(doclet, tag) {
7+
if (!doclet.values) { doclet.values = []; }
8+
doclet.values.push(tag.value);
9+
}
10+
});
11+
};

0 commit comments

Comments
 (0)