Skip to content

Commit 60b57ba

Browse files
dulmandakhfacebook-github-bot
authored andcommitted
cleanup DrawerLayoutAndroid (#26497)
Summary: This PR removes Java reflection use in ReactDrawerLayoutManager.java because we all use AndroidX and setDrawerElevation is available. Also adds NonNull annotations ## Changelog [Android] [Changed] - cleanup DrawerLayoutAndroid Pull Request resolved: #26497 Test Plan: RNTester is working as expected. Differential Revision: D17488727 Pulled By: mdvacca fbshipit-source-id: fd626e3e7aca3965f62c4c82a55c69e81facc61d
1 parent eb7dbc8 commit 60b57ba

File tree

1 file changed

+14
-28
lines changed

1 file changed

+14
-28
lines changed

ReactAndroid/src/main/java/com/facebook/react/views/drawer/ReactDrawerLayoutManager.java

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,17 @@
66
*/
77
package com.facebook.react.views.drawer;
88

9-
import android.os.Build;
109
import android.view.Gravity;
1110
import android.view.View;
11+
12+
import androidx.annotation.NonNull;
1213
import androidx.annotation.Nullable;
1314
import androidx.drawerlayout.widget.DrawerLayout;
14-
import com.facebook.common.logging.FLog;
1515
import com.facebook.react.bridge.Dynamic;
1616
import com.facebook.react.bridge.JSApplicationIllegalArgumentException;
1717
import com.facebook.react.bridge.ReadableArray;
1818
import com.facebook.react.bridge.ReadableType;
1919
import com.facebook.react.common.MapBuilder;
20-
import com.facebook.react.common.ReactConstants;
2120
import com.facebook.react.module.annotations.ReactModule;
2221
import com.facebook.react.uimanager.PixelUtil;
2322
import com.facebook.react.uimanager.ThemedReactContext;
@@ -29,7 +28,6 @@
2928
import com.facebook.react.views.drawer.events.DrawerOpenedEvent;
3029
import com.facebook.react.views.drawer.events.DrawerSlideEvent;
3130
import com.facebook.react.views.drawer.events.DrawerStateChangedEvent;
32-
import java.lang.reflect.Method;
3331
import java.util.Map;
3432

3533
/** View Manager for {@link ReactDrawerLayout} components. */
@@ -42,19 +40,20 @@ public class ReactDrawerLayoutManager extends ViewGroupManager<ReactDrawerLayout
4240
public static final int CLOSE_DRAWER = 2;
4341

4442
@Override
45-
public String getName() {
43+
public @NonNull String getName() {
4644
return REACT_CLASS;
4745
}
4846

4947
@Override
5048
protected void addEventEmitters(ThemedReactContext reactContext, ReactDrawerLayout view) {
51-
view.setDrawerListener(
52-
new DrawerEventEmitter(
53-
view, reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher()));
49+
view.addDrawerListener(
50+
new DrawerEventEmitter(
51+
view, reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher())
52+
);
5453
}
5554

5655
@Override
57-
protected ReactDrawerLayout createViewInstance(ThemedReactContext context) {
56+
protected @NonNull ReactDrawerLayout createViewInstance(@NonNull ThemedReactContext context) {
5857
return new ReactDrawerLayout(context);
5958
}
6059

@@ -110,21 +109,8 @@ public void setDrawerLockMode(ReactDrawerLayout view, @Nullable String drawerLoc
110109
}
111110

112111
@Override
113-
public void setElevation(ReactDrawerLayout view, float elevation) {
114-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
115-
// Facebook is using an older version of the support lib internally that doesn't support
116-
// setDrawerElevation so we invoke it using reflection.
117-
// TODO: Call the method directly when this is no longer needed.
118-
try {
119-
Method method = ReactDrawerLayout.class.getMethod("setDrawerElevation", float.class);
120-
method.invoke(view, PixelUtil.toPixelFromDIP(elevation));
121-
} catch (Exception ex) {
122-
FLog.w(
123-
ReactConstants.TAG,
124-
"setDrawerElevation is not available in this version of the support lib.",
125-
ex);
126-
}
127-
}
112+
public void setElevation(@NonNull ReactDrawerLayout view, float elevation) {
113+
view.setDrawerElevation(PixelUtil.toPixelFromDIP(elevation));
128114
}
129115

130116
@Override
@@ -152,7 +138,7 @@ public void receiveCommand(ReactDrawerLayout root, int commandId, @Nullable Read
152138

153139
@Override
154140
public void receiveCommand(
155-
ReactDrawerLayout root, String commandId, @Nullable ReadableArray args) {
141+
@NonNull ReactDrawerLayout root, String commandId, @Nullable ReadableArray args) {
156142
switch (commandId) {
157143
case "openDrawer":
158144
root.openDrawer();
@@ -208,17 +194,17 @@ public DrawerEventEmitter(DrawerLayout drawerLayout, EventDispatcher eventDispat
208194
}
209195

210196
@Override
211-
public void onDrawerSlide(View view, float v) {
197+
public void onDrawerSlide(@NonNull View view, float v) {
212198
mEventDispatcher.dispatchEvent(new DrawerSlideEvent(mDrawerLayout.getId(), v));
213199
}
214200

215201
@Override
216-
public void onDrawerOpened(View view) {
202+
public void onDrawerOpened(@NonNull View view) {
217203
mEventDispatcher.dispatchEvent(new DrawerOpenedEvent(mDrawerLayout.getId()));
218204
}
219205

220206
@Override
221-
public void onDrawerClosed(View view) {
207+
public void onDrawerClosed(@NonNull View view) {
222208
mEventDispatcher.dispatchEvent(new DrawerClosedEvent(mDrawerLayout.getId()));
223209
}
224210

0 commit comments

Comments
 (0)