Skip to content
This repository has been archived by the owner on Feb 18, 2019. It is now read-only.

Commit

Permalink
Add support for elevation in DrawerLayoutAndroid
Browse files Browse the repository at this point in the history
Summary:It didn't work for a few reason. First, the drawer view NEEDS to have a background color or no shadow will ever render. Second, we need to use the `setDrawerElevation` method instead of `setElevation` for DrawerLayout. Finally we need to actually pass the style value (maybe we could just pass elevation but I don't really think it can cause any issues) down to the native component as it is not the case at the moment.

I also added a default style to elevation of 16 which is the standard for material design according to https://www.google.com/design/spec/patterns/navigation-drawer.html#navigation-drawer-specs. I could also default it to 0 so it keeps the same appearance as before but I think it looks better this way.

Closes facebook#6022
**Test plan**
Tested using the DrawerLayout in the UIExplorer app.

Before, elevation 0
<img width="420" alt="screen shot 2016-02-23 at 1 55 42 am" src="https://cloud.githubusercontent.com/assets/2677334/13244000/008afdb2-d9d1-11e5-95b8-9c345ea0ea8d.png">

After, elevation
Closes facebook#6100

Reviewed By: bestander

Differential Revision: D3012242

Pulled By: lexs

fb-gh-sync-id: 4967d7ec920f0229d823032ba95c8a3cace329c6
shipit-source-id: 4967d7ec920f0229d823032ba95c8a3cace329c6
  • Loading branch information
janicduplessis authored and Facebook Github Bot 9 committed Mar 21, 2016
1 parent 36893ec commit 61483aa
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ var DrawerLayoutAndroid = React.createClass({
drawerWidth={this.props.drawerWidth}
drawerPosition={this.props.drawerPosition}
drawerLockMode={this.props.drawerLockMode}
style={styles.base}
style={[styles.base, this.props.style]}
onDrawerSlide={this._onDrawerSlide}
onDrawerOpen={this._onDrawerOpen}
onDrawerClose={this._onDrawerClose}
Expand Down Expand Up @@ -218,6 +218,7 @@ var DrawerLayoutAndroid = React.createClass({
var styles = StyleSheet.create({
base: {
flex: 1,
elevation: 16,
},
mainSubview: {
position: 'absolute',
Expand All @@ -230,6 +231,7 @@ var styles = StyleSheet.create({
position: 'absolute',
top: 0,
bottom: 0,
backgroundColor: 'white',
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,8 @@ public void addProperty(PropertyInfo propertyInfo) throws ReactPropertyException
if (checkPropertyExists(name)) {
throw new ReactPropertyException(
"Module " + mClassName + " has already registered a property named \"" +
name + '"', propertyInfo);
name + "\". If you want to override a property, don't add" +
"the @ReactProp annotation to the property in the subclass", propertyInfo);
}

mProperties.add(propertyInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ android_library(
react_native_target('java/com/facebook/react/uimanager:uimanager'),
react_native_target('java/com/facebook/react/uimanager/annotations:annotations'),
react_native_target('java/com/facebook/react/views/scroll:scroll'),
react_native_dep('libraries/fbcore/src/main/java/com/facebook/common/logging:logging'),
react_native_dep('third-party/java/jsr-305:jsr-305'),
react_native_dep('third-party/android/support/v4:lib-support-v4'),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,21 @@

import javax.annotation.Nullable;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Map;

import android.os.Build;
import android.support.v4.widget.DrawerLayout;
import android.view.Gravity;
import android.view.View;

import com.facebook.common.logging.FLog;

import com.facebook.react.bridge.JSApplicationIllegalArgumentException;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.common.MapBuilder;
import com.facebook.react.common.ReactConstants;
import com.facebook.react.common.SystemClock;
import com.facebook.react.uimanager.PixelUtil;
import com.facebook.react.uimanager.ThemedReactContext;
Expand Down Expand Up @@ -89,6 +95,24 @@ public void setDrawerLockMode(ReactDrawerLayout view, @Nullable String drawerLoc
}
}

@Override
public void setElevation(ReactDrawerLayout view, float elevation) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// Facebook is using an older version of the support lib internally that doesn't support
// setDrawerElevation so we invoke it using reflection.
// TODO: Call the method directly when this is no longer needed.
try {
Method method = ReactDrawerLayout.class.getMethod("setDrawerElevation", float.class);
method.invoke(view, PixelUtil.toPixelFromDIP(elevation));
} catch (Exception ex) {
FLog.w(
ReactConstants.TAG,
"setDrawerElevation is not available in this version of the support lib.",
ex);
}
}
}

@Override
public boolean needsCustomLayoutForChildren() {
// Return true, since DrawerLayout will lay out it's own children.
Expand Down

0 comments on commit 61483aa

Please sign in to comment.