Skip to content

Commit 305b0a2

Browse files
elicwhitefacebook-github-bot
authored andcommitted
DrawerLayoutAndroid drawerPosition now expects a string, number is deprecated
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
1 parent 0dcd57c commit 305b0a2

File tree

5 files changed

+19
-17
lines changed

5 files changed

+19
-17
lines changed

Libraries/Components/DrawerAndroid/AndroidDrawerLayoutNativeComponent.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ type NativeProps = $ReadOnly<{|
6060
/**
6161
* Specifies the side of the screen from which the drawer will slide in.
6262
*/
63-
drawerPosition: ?Int32,
63+
drawerPosition?: WithDefault<'left' | 'right', 'left'>,
6464

6565
/**
6666
* Specifies the width of the drawer, more precisely the width of the view that be pulled in

Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.android.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,11 @@
1212

1313
const Platform = require('../../Utilities/Platform');
1414
const React = require('react');
15-
const ReactNative = require('../../Renderer/shims/ReactNative');
1615
const StatusBar = require('../StatusBar/StatusBar');
1716
const StyleSheet = require('../../StyleSheet/StyleSheet');
18-
const UIManager = require('../../ReactNative/UIManager');
1917
const View = require('../View/View');
2018
const nullthrows = require('nullthrows');
2119

22-
const DrawerConsts = UIManager.getViewManagerConfig('AndroidDrawerLayout')
23-
.Constants;
2420
const dismissKeyboard = require('../../Utilities/dismissKeyboard');
2521
import AndroidDrawerLayoutNativeComponent, {
2622
Commands,
@@ -67,7 +63,7 @@ type Props = $ReadOnly<{|
6763
/**
6864
* Specifies the side of the screen from which the drawer will slide in.
6965
*/
70-
drawerPosition: ?number,
66+
drawerPosition: ?('left' | 'right'),
7167

7268
/**
7369
* Specifies the width of the drawer, more precisely the width of the view that be pulled in
@@ -148,7 +144,7 @@ type State = {|
148144
* return (
149145
* <DrawerLayoutAndroid
150146
* drawerWidth={300}
151-
* drawerPosition={DrawerLayoutAndroid.positions.Left}
147+
* drawerPosition="left"
152148
* renderNavigationView={() => navigationView}>
153149
* <View style={{flex: 1, alignItems: 'center'}}>
154150
* <Text style={{margin: 10, fontSize: 15, textAlign: 'right'}}>Hello</Text>
@@ -160,7 +156,13 @@ type State = {|
160156
* ```
161157
*/
162158
class DrawerLayoutAndroid extends React.Component<Props, State> {
163-
static positions = DrawerConsts.DrawerPosition;
159+
static get positions(): mixed {
160+
console.warn(
161+
'Setting DrawerLayoutAndroid drawerPosition using `DrawerLayoutAndroid.positions` is deprecated. Instead pass the string value "left" or "right"',
162+
);
163+
164+
return {Left: 'left', Right: 'right'};
165+
}
164166
static defaultProps = {
165167
drawerBackgroundColor: 'white',
166168
};

Libraries/Components/DrawerAndroid/__tests__/DrawerAndroid-test.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe('<DrawerLayoutAndroid />', () => {
2525
const instance = render.create(
2626
<DrawerLayoutAndroid
2727
drawerWidth={300}
28-
drawerPosition={DrawerLayoutAndroid.positions.Left}
28+
drawerPosition="left"
2929
renderNavigationView={() => <View />}
3030
/>,
3131
);
@@ -36,7 +36,7 @@ describe('<DrawerLayoutAndroid />', () => {
3636
const output = render.shallow(
3737
<DrawerLayoutAndroid
3838
drawerWidth={300}
39-
drawerPosition={DrawerLayoutAndroid.positions.Left}
39+
drawerPosition="left"
4040
renderNavigationView={() => <View />}
4141
/>,
4242
);
@@ -49,7 +49,7 @@ describe('<DrawerLayoutAndroid />', () => {
4949
const output = render.shallow(
5050
<DrawerLayoutAndroid
5151
drawerWidth={300}
52-
drawerPosition={DrawerLayoutAndroid.positions.Left}
52+
drawerPosition="left"
5353
renderNavigationView={() => <View />}
5454
/>,
5555
);
@@ -62,7 +62,7 @@ describe('<DrawerLayoutAndroid />', () => {
6262
const instance = render.create(
6363
<DrawerLayoutAndroid
6464
drawerWidth={300}
65-
drawerPosition={DrawerLayoutAndroid.positions.Left}
65+
drawerPosition="left"
6666
renderNavigationView={() => <View />}
6767
/>,
6868
);

Libraries/Components/DrawerAndroid/__tests__/__snapshots__/DrawerAndroid-test.js.snap

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
exports[`<DrawerLayoutAndroid /> should render as <DrawerLayoutAndroid> when mocked 1`] = `
44
<AndroidDrawerLayout
55
drawerBackgroundColor="white"
6-
drawerPosition={10}
6+
drawerPosition="left"
77
drawerWidth={300}
88
onDrawerClose={[Function]}
99
onDrawerOpen={[Function]}
@@ -55,7 +55,7 @@ exports[`<DrawerLayoutAndroid /> should render as <DrawerLayoutAndroid> when moc
5555
exports[`<DrawerLayoutAndroid /> should render as <DrawerLayoutAndroid> when not mocked 1`] = `
5656
<AndroidDrawerLayout
5757
drawerBackgroundColor="white"
58-
drawerPosition={10}
58+
drawerPosition="left"
5959
drawerWidth={300}
6060
onDrawerClose={[Function]}
6161
onDrawerOpen={[Function]}
@@ -107,7 +107,7 @@ exports[`<DrawerLayoutAndroid /> should render as <DrawerLayoutAndroid> when not
107107
exports[`<DrawerLayoutAndroid /> should shallow render as <DrawerLayoutAndroid> when mocked 1`] = `
108108
<DrawerLayoutAndroid
109109
drawerBackgroundColor="white"
110-
drawerPosition={10}
110+
drawerPosition="left"
111111
drawerWidth={300}
112112
renderNavigationView={[Function]}
113113
/>
@@ -116,7 +116,7 @@ exports[`<DrawerLayoutAndroid /> should shallow render as <DrawerLayoutAndroid>
116116
exports[`<DrawerLayoutAndroid /> should shallow render as <DrawerLayoutAndroid> when not mocked 1`] = `
117117
<DrawerLayoutAndroid
118118
drawerBackgroundColor="white"
119-
drawerPosition={10}
119+
drawerPosition="left"
120120
drawerWidth={300}
121121
renderNavigationView={[Function]}
122122
/>

RNTester/js/RNTesterApp.android.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class RNTesterApp extends React.Component<Props, RNTesterNavigationState> {
105105
}
106106
return (
107107
<DrawerLayoutAndroid
108-
drawerPosition={DrawerLayoutAndroid.positions.Left}
108+
drawerPosition="left"
109109
drawerWidth={Dimensions.get('window').width - DRAWER_WIDTH_LEFT}
110110
keyboardDismissMode="on-drag"
111111
onDrawerOpen={() => {

0 commit comments

Comments
 (0)