6
6
*/
7
7
package com .facebook .react .views .drawer ;
8
8
9
- import android .os .Build ;
10
9
import android .view .Gravity ;
11
10
import android .view .View ;
11
+
12
+ import androidx .annotation .NonNull ;
12
13
import androidx .annotation .Nullable ;
13
14
import androidx .drawerlayout .widget .DrawerLayout ;
14
- import com .facebook .common .logging .FLog ;
15
15
import com .facebook .react .bridge .Dynamic ;
16
16
import com .facebook .react .bridge .JSApplicationIllegalArgumentException ;
17
17
import com .facebook .react .bridge .ReadableArray ;
18
18
import com .facebook .react .bridge .ReadableType ;
19
19
import com .facebook .react .common .MapBuilder ;
20
- import com .facebook .react .common .ReactConstants ;
21
20
import com .facebook .react .module .annotations .ReactModule ;
22
21
import com .facebook .react .uimanager .PixelUtil ;
23
22
import com .facebook .react .uimanager .ThemedReactContext ;
29
28
import com .facebook .react .views .drawer .events .DrawerOpenedEvent ;
30
29
import com .facebook .react .views .drawer .events .DrawerSlideEvent ;
31
30
import com .facebook .react .views .drawer .events .DrawerStateChangedEvent ;
32
- import java .lang .reflect .Method ;
33
31
import java .util .Map ;
34
32
35
33
/** View Manager for {@link ReactDrawerLayout} components. */
@@ -42,19 +40,20 @@ public class ReactDrawerLayoutManager extends ViewGroupManager<ReactDrawerLayout
42
40
public static final int CLOSE_DRAWER = 2 ;
43
41
44
42
@ Override
45
- public String getName () {
43
+ public @ NonNull String getName () {
46
44
return REACT_CLASS ;
47
45
}
48
46
49
47
@ Override
50
48
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
+ );
54
53
}
55
54
56
55
@ Override
57
- protected ReactDrawerLayout createViewInstance (ThemedReactContext context ) {
56
+ protected @ NonNull ReactDrawerLayout createViewInstance (@ NonNull ThemedReactContext context ) {
58
57
return new ReactDrawerLayout (context );
59
58
}
60
59
@@ -110,21 +109,8 @@ public void setDrawerLockMode(ReactDrawerLayout view, @Nullable String drawerLoc
110
109
}
111
110
112
111
@ 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 ));
128
114
}
129
115
130
116
@ Override
@@ -152,7 +138,7 @@ public void receiveCommand(ReactDrawerLayout root, int commandId, @Nullable Read
152
138
153
139
@ Override
154
140
public void receiveCommand (
155
- ReactDrawerLayout root , String commandId , @ Nullable ReadableArray args ) {
141
+ @ NonNull ReactDrawerLayout root , String commandId , @ Nullable ReadableArray args ) {
156
142
switch (commandId ) {
157
143
case "openDrawer" :
158
144
root .openDrawer ();
@@ -208,17 +194,17 @@ public DrawerEventEmitter(DrawerLayout drawerLayout, EventDispatcher eventDispat
208
194
}
209
195
210
196
@ Override
211
- public void onDrawerSlide (View view , float v ) {
197
+ public void onDrawerSlide (@ NonNull View view , float v ) {
212
198
mEventDispatcher .dispatchEvent (new DrawerSlideEvent (mDrawerLayout .getId (), v ));
213
199
}
214
200
215
201
@ Override
216
- public void onDrawerOpened (View view ) {
202
+ public void onDrawerOpened (@ NonNull View view ) {
217
203
mEventDispatcher .dispatchEvent (new DrawerOpenedEvent (mDrawerLayout .getId ()));
218
204
}
219
205
220
206
@ Override
221
- public void onDrawerClosed (View view ) {
207
+ public void onDrawerClosed (@ NonNull View view ) {
222
208
mEventDispatcher .dispatchEvent (new DrawerClosedEvent (mDrawerLayout .getId ()));
223
209
}
224
210
0 commit comments