mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-01-12 22:50:10 +08:00
chore: update comment in DrawerLayoutAndroid (#23730)
Summary: ...referencing stale function component limitations While preparing a short tutorial on the DrawerLayoutAndroid using the v59 RC, I came across a comment that we can update that states refs as being available only in Class components. This updates that with both class and function components. If we'd rather delete the comment entirely and move both examples to the website, I'm fine with that too. The current docs page doesn't address the imperative API. https://facebook.github.io/react-native/docs/drawerlayoutandroid [General] [fixed] - Update stale comment to provide both class and functional component ref example for DrawerLayoutAndroid Pull Request resolved: https://github.com/facebook/react-native/pull/23730 Differential Revision: D14298527 Pulled By: cpojer fbshipit-source-id: 3e9f0d6ae49588045fd9d924996fe7cff3d6a156
This commit is contained in:
committed by
Facebook Github Bot
parent
d8d42c7310
commit
ced155327e
@@ -288,7 +288,10 @@ class DrawerLayoutAndroid extends React.Component<Props, State> {
|
||||
|
||||
/**
|
||||
* Closing and opening example
|
||||
* Note: To access the drawer you have to give it a ref. Refs do not work on stateless components
|
||||
* Note: To access the drawer you have to give it a ref
|
||||
*
|
||||
* Class component:
|
||||
*
|
||||
* render () {
|
||||
* this.openDrawer = () => {
|
||||
* this.refs.DRAWER.openDrawer()
|
||||
@@ -298,9 +301,25 @@ class DrawerLayoutAndroid extends React.Component<Props, State> {
|
||||
* }
|
||||
* return (
|
||||
* <DrawerLayoutAndroid ref={'DRAWER'}>
|
||||
* {children}
|
||||
* </DrawerLayoutAndroid>
|
||||
* )
|
||||
* }
|
||||
*
|
||||
* Function component:
|
||||
*
|
||||
* const drawerRef = useRef()
|
||||
* const openDrawer = () => {
|
||||
* drawerRef.current.openDrawer()
|
||||
* }
|
||||
* const closeDrawer = () => {
|
||||
* drawerRef.current.closeDrawer()
|
||||
* }
|
||||
* return (
|
||||
* <DrawerLayoutAndroid ref={drawerRef}>
|
||||
* {children}
|
||||
* </DrawerLayoutAndroid>
|
||||
* )
|
||||
*/
|
||||
_getDrawerLayoutHandle() {
|
||||
return ReactNative.findNodeHandle(this._nativeRef.current);
|
||||
|
||||
Reference in New Issue
Block a user