66 */
77package com .facebook .react .views .drawer ;
88
9- import android .os .Build ;
109import android .view .Gravity ;
1110import android .view .View ;
11+
12+ import androidx .annotation .NonNull ;
1213import androidx .annotation .Nullable ;
1314import androidx .drawerlayout .widget .DrawerLayout ;
14- import com .facebook .common .logging .FLog ;
1515import com .facebook .react .bridge .Dynamic ;
1616import com .facebook .react .bridge .JSApplicationIllegalArgumentException ;
1717import com .facebook .react .bridge .ReadableArray ;
1818import com .facebook .react .bridge .ReadableType ;
1919import com .facebook .react .common .MapBuilder ;
20- import com .facebook .react .common .ReactConstants ;
2120import com .facebook .react .module .annotations .ReactModule ;
2221import com .facebook .react .uimanager .PixelUtil ;
2322import com .facebook .react .uimanager .ThemedReactContext ;
2928import com .facebook .react .views .drawer .events .DrawerOpenedEvent ;
3029import com .facebook .react .views .drawer .events .DrawerSlideEvent ;
3130import com .facebook .react .views .drawer .events .DrawerStateChangedEvent ;
32- import java .lang .reflect .Method ;
3331import 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