Skip to content

Commit

Permalink
DrawerLayoutAndroid drawerPosition now expects a string, number is de…
Browse files Browse the repository at this point in the history
…precated

Summary: The native change to support strings was made in D15912607 on June 21st. Migrating the JS callsites now to start passing strings instead of the constants.

Reviewed By: zackargyle, mdvacca

Differential Revision: D16703569

fbshipit-source-id: cb1d8698df55d2961cde1e2b1fbfcba086a03bb2
  • Loading branch information
elicwhite authored and facebook-github-bot committed Aug 8, 2019
1 parent 0dcd57c commit 305b0a2
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ type NativeProps = $ReadOnly<{|
/**
* Specifies the side of the screen from which the drawer will slide in.
*/
drawerPosition: ?Int32,
drawerPosition?: WithDefault<'left' | 'right', 'left'>,

/**
* Specifies the width of the drawer, more precisely the width of the view that be pulled in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,11 @@

const Platform = require('../../Utilities/Platform');
const React = require('react');
const ReactNative = require('../../Renderer/shims/ReactNative');
const StatusBar = require('../StatusBar/StatusBar');
const StyleSheet = require('../../StyleSheet/StyleSheet');
const UIManager = require('../../ReactNative/UIManager');
const View = require('../View/View');
const nullthrows = require('nullthrows');

const DrawerConsts = UIManager.getViewManagerConfig('AndroidDrawerLayout')
.Constants;
const dismissKeyboard = require('../../Utilities/dismissKeyboard');
import AndroidDrawerLayoutNativeComponent, {
Commands,
Expand Down Expand Up @@ -67,7 +63,7 @@ type Props = $ReadOnly<{|
/**
* Specifies the side of the screen from which the drawer will slide in.
*/
drawerPosition: ?number,
drawerPosition: ?('left' | 'right'),

/**
* Specifies the width of the drawer, more precisely the width of the view that be pulled in
Expand Down Expand Up @@ -148,7 +144,7 @@ type State = {|
* return (
* <DrawerLayoutAndroid
* drawerWidth={300}
* drawerPosition={DrawerLayoutAndroid.positions.Left}
* drawerPosition="left"
* renderNavigationView={() => navigationView}>
* <View style={{flex: 1, alignItems: 'center'}}>
* <Text style={{margin: 10, fontSize: 15, textAlign: 'right'}}>Hello</Text>
Expand All @@ -160,7 +156,13 @@ type State = {|
* ```
*/
class DrawerLayoutAndroid extends React.Component<Props, State> {
static positions = DrawerConsts.DrawerPosition;
static get positions(): mixed {
console.warn(
'Setting DrawerLayoutAndroid drawerPosition using `DrawerLayoutAndroid.positions` is deprecated. Instead pass the string value "left" or "right"',
);

return {Left: 'left', Right: 'right'};
}
static defaultProps = {
drawerBackgroundColor: 'white',
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('<DrawerLayoutAndroid />', () => {
const instance = render.create(
<DrawerLayoutAndroid
drawerWidth={300}
drawerPosition={DrawerLayoutAndroid.positions.Left}
drawerPosition="left"
renderNavigationView={() => <View />}
/>,
);
Expand All @@ -36,7 +36,7 @@ describe('<DrawerLayoutAndroid />', () => {
const output = render.shallow(
<DrawerLayoutAndroid
drawerWidth={300}
drawerPosition={DrawerLayoutAndroid.positions.Left}
drawerPosition="left"
renderNavigationView={() => <View />}
/>,
);
Expand All @@ -49,7 +49,7 @@ describe('<DrawerLayoutAndroid />', () => {
const output = render.shallow(
<DrawerLayoutAndroid
drawerWidth={300}
drawerPosition={DrawerLayoutAndroid.positions.Left}
drawerPosition="left"
renderNavigationView={() => <View />}
/>,
);
Expand All @@ -62,7 +62,7 @@ describe('<DrawerLayoutAndroid />', () => {
const instance = render.create(
<DrawerLayoutAndroid
drawerWidth={300}
drawerPosition={DrawerLayoutAndroid.positions.Left}
drawerPosition="left"
renderNavigationView={() => <View />}
/>,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`<DrawerLayoutAndroid /> should render as <DrawerLayoutAndroid> when mocked 1`] = `
<AndroidDrawerLayout
drawerBackgroundColor="white"
drawerPosition={10}
drawerPosition="left"
drawerWidth={300}
onDrawerClose={[Function]}
onDrawerOpen={[Function]}
Expand Down Expand Up @@ -55,7 +55,7 @@ exports[`<DrawerLayoutAndroid /> should render as <DrawerLayoutAndroid> when moc
exports[`<DrawerLayoutAndroid /> should render as <DrawerLayoutAndroid> when not mocked 1`] = `
<AndroidDrawerLayout
drawerBackgroundColor="white"
drawerPosition={10}
drawerPosition="left"
drawerWidth={300}
onDrawerClose={[Function]}
onDrawerOpen={[Function]}
Expand Down Expand Up @@ -107,7 +107,7 @@ exports[`<DrawerLayoutAndroid /> should render as <DrawerLayoutAndroid> when not
exports[`<DrawerLayoutAndroid /> should shallow render as <DrawerLayoutAndroid> when mocked 1`] = `
<DrawerLayoutAndroid
drawerBackgroundColor="white"
drawerPosition={10}
drawerPosition="left"
drawerWidth={300}
renderNavigationView={[Function]}
/>
Expand All @@ -116,7 +116,7 @@ exports[`<DrawerLayoutAndroid /> should shallow render as <DrawerLayoutAndroid>
exports[`<DrawerLayoutAndroid /> should shallow render as <DrawerLayoutAndroid> when not mocked 1`] = `
<DrawerLayoutAndroid
drawerBackgroundColor="white"
drawerPosition={10}
drawerPosition="left"
drawerWidth={300}
renderNavigationView={[Function]}
/>
Expand Down
2 changes: 1 addition & 1 deletion RNTester/js/RNTesterApp.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class RNTesterApp extends React.Component<Props, RNTesterNavigationState> {
}
return (
<DrawerLayoutAndroid
drawerPosition={DrawerLayoutAndroid.positions.Left}
drawerPosition="left"
drawerWidth={Dimensions.get('window').width - DRAWER_WIDTH_LEFT}
keyboardDismissMode="on-drag"
onDrawerOpen={() => {
Expand Down

0 comments on commit 305b0a2

Please sign in to comment.