Skip to content

Commit

Permalink
Change AndroidDrawerLayoutNativeComponent to use JS codegen for commands
Browse files Browse the repository at this point in the history
Summary:
`codegenNativeCommands` returns an object with functions for each command that has the previous behavior inside the React Renderer, and the new Fabric logic inside of the Fabric React Native Renderer.

Changelog:
[Internal] - Change AndroidDrawerLayoutNativeComponent to use JS codegen for commands

Reviewed By: rickhanlonii

Differential Revision: D16529887

fbshipit-source-id: 24a5307944a7f62e18482d60d26052fea3be2051
  • Loading branch information
elicwhite authored and facebook-github-bot committed Aug 2, 2019
1 parent e2f82b1 commit e906af1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

'use strict';

import codegenNativeCommands from 'react-native/Libraries/Utilities/codegenNativeCommands';
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
import * as React from 'react';
import type {ViewProps} from 'react-native/Libraries/Components/View/ViewPropTypes';
import type {
WithDefault,
Expand All @@ -28,6 +30,11 @@ type DrawerSlideEvent = $ReadOnly<{|
offset: Float,
|}>;

interface NativeCommands {
+openDrawer: (viewRef: React.Ref<'AndroidDrawerLayout'>) => void;
+closeDrawer: (viewRef: React.Ref<'AndroidDrawerLayout'>) => void;
}

type NativeProps = $ReadOnly<{|
...ViewProps,
/**
Expand Down Expand Up @@ -106,4 +113,8 @@ type NativeProps = $ReadOnly<{|
statusBarBackgroundColor?: ?ColorValue,
|}>;

export const Commands = codegenNativeCommands<NativeCommands>({
supportedCommands: ['openDrawer', 'closeDrawer'],
});

export default codegenNativeComponent<NativeProps>('AndroidDrawerLayout');
22 changes: 6 additions & 16 deletions Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ const nullthrows = require('nullthrows');
const DrawerConsts = UIManager.getViewManagerConfig('AndroidDrawerLayout')
.Constants;
const dismissKeyboard = require('../../Utilities/dismissKeyboard');
import AndroidDrawerLayoutNativeComponent from './AndroidDrawerLayoutNativeComponent';
import AndroidDrawerLayoutNativeComponent, {
Commands,
} from './AndroidDrawerLayoutNativeComponent';

const DRAWER_STATES = ['Idle', 'Dragging', 'Settling'];

Expand Down Expand Up @@ -163,7 +165,7 @@ class DrawerLayoutAndroid extends React.Component<Props, State> {
drawerBackgroundColor: 'white',
};

_nativeRef = React.createRef<Class<ReactNative.NativeComponent<Props>>>();
_nativeRef = React.createRef();

state = {statusBarBackgroundColor: null};

Expand Down Expand Up @@ -264,23 +266,14 @@ class DrawerLayoutAndroid extends React.Component<Props, State> {
* Opens the drawer.
*/
openDrawer() {
UIManager.dispatchViewManagerCommand(
this._getDrawerLayoutHandle(),
UIManager.getViewManagerConfig('AndroidDrawerLayout').Commands.openDrawer,
null,
);
Commands.openDrawer(nullthrows(this._nativeRef.current));
}

/**
* Closes the drawer.
*/
closeDrawer() {
UIManager.dispatchViewManagerCommand(
this._getDrawerLayoutHandle(),
UIManager.getViewManagerConfig('AndroidDrawerLayout').Commands
.closeDrawer,
null,
);
Commands.closeDrawer(nullthrows(this._nativeRef.current));
}

/**
Expand Down Expand Up @@ -318,9 +311,6 @@ class DrawerLayoutAndroid extends React.Component<Props, State> {
* </DrawerLayoutAndroid>
* )
*/
_getDrawerLayoutHandle() {
return ReactNative.findNodeHandle(this._nativeRef.current);
}

/**
* Native methods
Expand Down

0 comments on commit e906af1

Please sign in to comment.