From ced155327e18dad75d2a00f6e5402416ab30fdbd Mon Sep 17 00:00:00 2001 From: Ryan Stelly Date: Sun, 3 Mar 2019 20:13:57 -0800 Subject: [PATCH] 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 --- .../DrawerLayoutAndroid.android.js | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.android.js b/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.android.js index 2c1e970ca5f..3f7866b5e92 100644 --- a/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.android.js +++ b/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.android.js @@ -288,7 +288,10 @@ class DrawerLayoutAndroid extends React.Component { /** * 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 { * } * return ( * + * {children} * * ) * } + * + * Function component: + * + * const drawerRef = useRef() + * const openDrawer = () => { + * drawerRef.current.openDrawer() + * } + * const closeDrawer = () => { + * drawerRef.current.closeDrawer() + * } + * return ( + * + * {children} + * + * ) */ _getDrawerLayoutHandle() { return ReactNative.findNodeHandle(this._nativeRef.current);