Skip to content

Commit 49fdd99

Browse files
janicduplessisFacebook Github Bot 1
authored andcommitted
Display component methods on the website and tweak the documentation
Summary:The website now displays public methods on components. This was implemented mostly in react-docgen via #66. This adds a <Method> component that is used by the component and API doc pages to display documentation for a method. It also adds some missing documentation and tweak some existing one to integrate with this feature. I also prefixed some component methods with an '_' so they don't show up in the doc. **Test plan (required)** Tested every component page locally to make sure the methods doc was displayed properly. Tested an API page to make sure it still worked properly. Closes #6890 Differential Revision: D3159911 Pulled By: vjeux fb-gh-sync-id: 1e6a4640cda6794496d9844c1af6a1451c017dcc fbshipit-source-id: 1e6a4640cda6794496d9844c1af6a1451c017dcc
1 parent 2eafcd4 commit 49fdd99

File tree

14 files changed

+297
-152
lines changed

14 files changed

+297
-152
lines changed

Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.android.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,14 +223,20 @@ var DrawerLayoutAndroid = React.createClass({
223223
}
224224
},
225225

226-
openDrawer: function() {
226+
/**
227+
* Opens the drawer.
228+
*/
229+
openDrawer: function(test: number) {
227230
UIManager.dispatchViewManagerCommand(
228231
this._getDrawerLayoutHandle(),
229232
UIManager.AndroidDrawerLayout.Commands.openDrawer,
230233
null
231234
);
232235
},
233236

237+
/**
238+
* Closes the drawer.
239+
*/
234240
closeDrawer: function() {
235241
UIManager.dispatchViewManagerCommand(
236242
this._getDrawerLayoutHandle(),

Libraries/Components/Navigation/NavigatorIOS.ios.js

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -143,20 +143,6 @@ type Event = Object;
143143
* });
144144
* ```
145145
*
146-
* A navigation object contains the following functions:
147-
*
148-
* - `push(route)` - Navigate forward to a new route
149-
* - `pop()` - Go back one page
150-
* - `popN(n)` - Go back N pages at once. When N=1, behavior matches `pop()`
151-
* - `replace(route)` - Replace the route for the current page and immediately
152-
* load the view for the new route
153-
* - `replacePrevious(route)` - Replace the route/view for the previous page
154-
* - `replacePreviousAndPop(route)` - Replaces the previous route/view and
155-
* transitions back to it
156-
* - `resetTo(route)` - Replaces the top item and popToTop
157-
* - `popToRoute(route)` - Go back to the item for a particular route object
158-
* - `popToTop()` - Go back to the top item
159-
*
160146
* Navigator functions are also available on the NavigatorIOS component:
161147
*
162148
* ```
@@ -492,6 +478,9 @@ var NavigatorIOS = React.createClass({
492478
this.navigationContext.emit('willfocus', {route: route});
493479
},
494480

481+
/**
482+
* Navigate forward to a new route
483+
*/
495484
push: function(route: Route) {
496485
invariant(!!route, 'Must supply route to push');
497486
// Make sure all previous requests are caught up first. Otherwise reject.
@@ -514,6 +503,9 @@ var NavigatorIOS = React.createClass({
514503
}
515504
},
516505

506+
/**
507+
* Go back N pages at once. When N=1, behavior matches `pop()`
508+
*/
517509
popN: function(n: number) {
518510
if (n === 0) {
519511
return;
@@ -535,6 +527,9 @@ var NavigatorIOS = React.createClass({
535527
}
536528
},
537529

530+
/**
531+
* Go back one page
532+
*/
538533
pop: function() {
539534
this.popN(1);
540535
},
@@ -574,23 +569,30 @@ var NavigatorIOS = React.createClass({
574569
},
575570

576571
/**
577-
* Replaces the top of the navigation stack.
572+
* Replace the route for the current page and immediately
573+
* load the view for the new route.
578574
*/
579575
replace: function(route: Route) {
580576
this.replaceAtIndex(route, -1);
581577
},
582578

583579
/**
584-
* Replace the current route's parent.
580+
* Replace the route/view for the previous page.
585581
*/
586582
replacePrevious: function(route: Route) {
587583
this.replaceAtIndex(route, -2);
588584
},
589585

586+
/**
587+
* Go back to the top item
588+
*/
590589
popToTop: function() {
591590
this.popToRoute(this.state.routeStack[0]);
592591
},
593592

593+
/**
594+
* Go back to the item for a particular route object
595+
*/
594596
popToRoute: function(route: Route) {
595597
var indexOfRoute = this.state.routeStack.indexOf(route);
596598
invariant(
@@ -601,6 +603,9 @@ var NavigatorIOS = React.createClass({
601603
this.popN(numToPop);
602604
},
603605

606+
/**
607+
* Replaces the previous route/view and transitions back to it.
608+
*/
604609
replacePreviousAndPop: function(route: Route) {
605610
// Make sure all previous requests are caught up first. Otherwise reject.
606611
if (this.state.requestedTopOfStack !== this.state.observedTopOfStack) {
@@ -618,6 +623,9 @@ var NavigatorIOS = React.createClass({
618623
});
619624
},
620625

626+
/**
627+
* Replaces the top item and popToTop
628+
*/
621629
resetTo: function(route: Route) {
622630
invariant(!!route, 'Must supply route to push');
623631
// Make sure all previous requests are caught up first. Otherwise reject.
@@ -628,7 +636,7 @@ var NavigatorIOS = React.createClass({
628636
this.popToRoute(route);
629637
},
630638

631-
handleNavigationComplete: function(e: Event) {
639+
_handleNavigationComplete: function(e: Event) {
632640
if (this._toFocusOnNavigationComplete) {
633641
this._getFocusEmitter().emit('focus', this._toFocusOnNavigationComplete);
634642
this._toFocusOnNavigationComplete = null;
@@ -663,7 +671,7 @@ var NavigatorIOS = React.createClass({
663671
);
664672
},
665673

666-
renderNavigationStackItems: function() {
674+
_renderNavigationStackItems: function() {
667675
var shouldRecurseToNavigator =
668676
this.state.makingNavigatorRequest ||
669677
this.state.updatingAllIndicesAtOrBeyond !== null;
@@ -678,7 +686,7 @@ var NavigatorIOS = React.createClass({
678686
style={styles.transitioner}
679687
vertical={this.props.vertical}
680688
requestedTopOfStack={this.state.requestedTopOfStack}
681-
onNavigationComplete={this.handleNavigationComplete}>
689+
onNavigationComplete={this._handleNavigationComplete}>
682690
{items}
683691
</NavigatorTransitionerIOS>
684692
</StaticContainer>
@@ -688,7 +696,7 @@ var NavigatorIOS = React.createClass({
688696
render: function() {
689697
return (
690698
<View style={this.props.style}>
691-
{this.renderNavigationStackItems()}
699+
{this._renderNavigationStackItems()}
692700
</View>
693701
);
694702
},

Libraries/Components/ScrollView/ScrollView.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,9 @@ var ScrollView = React.createClass({
341341
this.refs[SCROLLVIEW].setNativeProps(props);
342342
},
343343

344+
/**
345+
* Deprecated. Use `RefreshControl` instead.
346+
*/
344347
endRefreshing: function() {
345348
RCTScrollViewManager.endRefreshing(
346349
ReactNative.findNodeHandle(this)
@@ -367,9 +370,10 @@ var ScrollView = React.createClass({
367370

368371
/**
369372
* Scrolls to a given x, y offset, either immediately or with a smooth animation.
373+
*
370374
* Syntax:
371375
*
372-
* scrollTo(options: {x: number = 0; y: number = 0; animated: boolean = true})
376+
* `scrollTo(options: {x: number = 0; y: number = 0; animated: boolean = true})`
373377
*
374378
* Note: The weird argument signature is due to the fact that, for historical reasons,
375379
* the function also accepts separate arguments as as alternative to the options object.
@@ -397,7 +401,7 @@ var ScrollView = React.createClass({
397401
this.scrollTo({x, y, animated: false});
398402
},
399403

400-
handleScroll: function(e: Object) {
404+
_handleScroll: function(e: Object) {
401405
if (__DEV__) {
402406
if (this.props.onScroll && !this.props.scrollEventThrottle && Platform.OS === 'ios') {
403407
console.log(
@@ -480,7 +484,7 @@ var ScrollView = React.createClass({
480484
onStartShouldSetResponder: this.scrollResponderHandleStartShouldSetResponder,
481485
onStartShouldSetResponderCapture: this.scrollResponderHandleStartShouldSetResponderCapture,
482486
onScrollShouldSetResponder: this.scrollResponderHandleScrollShouldSetResponder,
483-
onScroll: this.handleScroll,
487+
onScroll: this._handleScroll,
484488
onResponderGrant: this.scrollResponderHandleResponderGrant,
485489
onResponderTerminationRequest: this.scrollResponderHandleTerminationRequest,
486490
onResponderTerminate: this.scrollResponderHandleTerminate,

Libraries/Components/StatusBar/StatusBar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ const StatusBar = React.createClass({
164164
StatusBarManager.setNetworkActivityIndicatorVisible(visible);
165165
},
166166

167-
setBackgroundColor(color, animated?: boolean) {
167+
setBackgroundColor(color: string, animated?: boolean) {
168168
if (Platform.OS !== 'android') {
169169
console.warn('`setBackgroundColor` is only available on Android');
170170
return;

Libraries/Components/TextInput/TextInput.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,9 @@ var TextInput = React.createClass({
319319
AndroidTextInput.viewConfig :
320320
{})) : Object),
321321

322+
/**
323+
* Returns if the input is currently focused.
324+
*/
322325
isFocused: function(): boolean {
323326
return TextInputState.currentlyFocusedField() ===
324327
ReactNative.findNodeHandle(this.refs.input);
@@ -368,6 +371,9 @@ var TextInput = React.createClass({
368371
isInAParentText: React.PropTypes.bool
369372
},
370373

374+
/**
375+
* Removes all text from the input.
376+
*/
371377
clear: function() {
372378
this.setNativeProps({text: ''});
373379
},

Libraries/Components/Touchable/TouchableHighlight.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ var TouchableHighlight = React.createClass({
9494
getDefaultProps: () => DEFAULT_PROPS,
9595

9696
// Performance optimization to avoid constantly re-generating these objects.
97-
computeSyntheticState: function(props) {
97+
_computeSyntheticState: function(props) {
9898
return {
9999
activeProps: {
100100
style: {
@@ -115,7 +115,7 @@ var TouchableHighlight = React.createClass({
115115

116116
getInitialState: function() {
117117
return merge(
118-
this.touchableGetInitialState(), this.computeSyntheticState(this.props)
118+
this.touchableGetInitialState(), this._computeSyntheticState(this.props)
119119
);
120120
},
121121

@@ -133,7 +133,7 @@ var TouchableHighlight = React.createClass({
133133
if (nextProps.activeOpacity !== this.props.activeOpacity ||
134134
nextProps.underlayColor !== this.props.underlayColor ||
135135
nextProps.style !== this.props.style) {
136-
this.setState(this.computeSyntheticState(nextProps));
136+
this.setState(this._computeSyntheticState(nextProps));
137137
}
138138
},
139139

Libraries/Components/Touchable/TouchableNativeFeedback.android.js

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -83,36 +83,39 @@ var TouchableNativeFeedback = React.createClass({
8383
/**
8484
* Determines the type of background drawable that's going to be used to
8585
* display feedback. It takes an object with `type` property and extra data
86-
* depending on the `type`. It's recommended to use one of the following
87-
* static methods to generate that dictionary:
88-
*
89-
* 1) TouchableNativeFeedback.SelectableBackground() - will create object
90-
* that represents android theme's default background for selectable
91-
* elements (?android:attr/selectableItemBackground)
92-
*
93-
* 2) TouchableNativeFeedback.SelectableBackgroundBorderless() - will create
94-
* object that represent android theme's default background for borderless
95-
* selectable elements (?android:attr/selectableItemBackgroundBorderless).
96-
* Available on android API level 21+
97-
*
98-
* 3) TouchableNativeFeedback.Ripple(color, borderless) - will create
99-
* object that represents ripple drawable with specified color (as a
100-
* string). If property `borderless` evaluates to true the ripple will
101-
* render outside of the view bounds (see native actionbar buttons as an
102-
* example of that behavior). This background type is available on Android
103-
* API level 21+
86+
* depending on the `type`. It's recommended to use one of the static
87+
* methods to generate that dictionary.
10488
*/
10589
background: backgroundPropType,
10690
},
10791

10892
statics: {
93+
/**
94+
* Creates an object that represents android theme's default background for
95+
* selectable elements (?android:attr/selectableItemBackground).
96+
*/
10997
SelectableBackground: function() {
11098
return {type: 'ThemeAttrAndroid', attribute: 'selectableItemBackground'};
11199
},
100+
/**
101+
* Creates an object that represent android theme's default background for borderless
102+
* selectable elements (?android:attr/selectableItemBackgroundBorderless).
103+
* Available on android API level 21+.
104+
*/
112105
SelectableBackgroundBorderless: function() {
113106
return {type: 'ThemeAttrAndroid', attribute: 'selectableItemBackgroundBorderless'};
114107
},
115-
Ripple: function(color, borderless) {
108+
/**
109+
* Creates an object that represents ripple drawable with specified color (as a
110+
* string). If property `borderless` evaluates to true the ripple will
111+
* render outside of the view bounds (see native actionbar buttons as an
112+
* example of that behavior). This background type is available on Android
113+
* API level 21+.
114+
*
115+
* @param color The ripple color
116+
* @param borderless If the ripple can render outside it's bounds
117+
*/
118+
Ripple: function(color: string, borderless: boolean) {
116119
return {type: 'RippleAndroid', color: processColor(color), borderless: borderless};
117120
},
118121
},

Libraries/Components/Touchable/TouchableOpacity.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@ var TouchableOpacity = React.createClass({
8181
ensurePositiveDelayProps(nextProps);
8282
},
8383

84-
setOpacityTo: function(value) {
84+
/**
85+
* Animate the touchable to a new opacity.
86+
*/
87+
setOpacityTo: function(value: number) {
8588
Animated.timing(
8689
this.state.anim,
8790
{toValue: value, duration: 150}

0 commit comments

Comments
 (0)