25
25
import android .view .View ;
26
26
import android .view .accessibility .AccessibilityEvent ;
27
27
import androidx .annotation .AnyThread ;
28
- import androidx .annotation .NonNull ;
29
28
import androidx .annotation .Nullable ;
30
29
import androidx .annotation .UiThread ;
31
30
import com .facebook .common .logging .FLog ;
31
+ import com .facebook .infer .annotation .Assertions ;
32
+ import com .facebook .infer .annotation .Nullsafe ;
32
33
import com .facebook .infer .annotation .ThreadConfined ;
33
34
import com .facebook .proguard .annotations .DoNotStripAny ;
34
35
import com .facebook .react .bridge .ColorPropConverter ;
98
99
* We instruct ProGuard not to strip out any fields or methods, because many of these methods are
99
100
* only called through the JNI from Cxx so it appears that most of this class is "unused".
100
101
*/
102
+ @ Nullsafe (Nullsafe .Mode .LOCAL )
101
103
@ SuppressLint ("MissingNativeLoadLibrary" )
102
104
@ DoNotStripAny
103
105
public class FabricUIManager
@@ -107,8 +109,7 @@ public class FabricUIManager
107
109
// The IS_DEVELOPMENT_ENVIRONMENT variable is used to log extra data when running fabric in a
108
110
// development environment. DO NOT ENABLE THIS ON PRODUCTION OR YOU WILL BE FIRED!
109
111
public static final boolean IS_DEVELOPMENT_ENVIRONMENT = false && ReactBuildConfig .DEBUG ;
110
- // NULLSAFE_FIXME[Field Not Initialized]
111
- public DevToolsReactPerfLogger mDevToolsReactPerfLogger ;
112
+ public @ Nullable DevToolsReactPerfLogger mDevToolsReactPerfLogger ;
112
113
113
114
private static final DevToolsReactPerfLogger .DevToolsReactPerfLoggerListener FABRIC_PERF_LOGGER =
114
115
commitPoint -> {
@@ -161,27 +162,24 @@ public class FabricUIManager
161
162
}
162
163
163
164
@ Nullable private FabricUIManagerBinding mBinding ;
164
- @ NonNull private final ReactApplicationContext mReactApplicationContext ;
165
- @ NonNull private final MountingManager mMountingManager ;
166
- @ NonNull private final FabricEventDispatcher mEventDispatcher ;
167
- @ NonNull private final MountItemDispatcher mMountItemDispatcher ;
168
- @ NonNull private final ViewManagerRegistry mViewManagerRegistry ;
165
+ private final ReactApplicationContext mReactApplicationContext ;
166
+ private final MountingManager mMountingManager ;
167
+ private final FabricEventDispatcher mEventDispatcher ;
168
+ private final MountItemDispatcher mMountItemDispatcher ;
169
+ private final ViewManagerRegistry mViewManagerRegistry ;
169
170
170
- @ NonNull private final BatchEventDispatchedListener mBatchEventDispatchedListener ;
171
+ private final BatchEventDispatchedListener mBatchEventDispatchedListener ;
171
172
172
- @ NonNull
173
173
private final CopyOnWriteArrayList <UIManagerListener > mListeners = new CopyOnWriteArrayList <>();
174
174
175
175
private boolean mMountNotificationScheduled = false ;
176
176
private List <Integer > mSurfaceIdsWithPendingMountNotification = new ArrayList <>();
177
177
178
178
@ ThreadConfined (UI )
179
- @ NonNull
180
179
private final DispatchUIFrameCallback mDispatchUIFrameCallback ;
181
180
182
181
/** Set of events sent synchronously during the current frame render. Cleared after each frame. */
183
182
@ ThreadConfined (UI )
184
- @ NonNull
185
183
private final Set <SynchronousEvent > mSynchronousEvents = new HashSet <>();
186
184
187
185
/**
@@ -219,9 +217,9 @@ public void executeItems(Queue<MountItem> items) {
219
217
@ Nullable private InteropUIBlockListener mInteropUIBlockListener ;
220
218
221
219
public FabricUIManager (
222
- @ NonNull ReactApplicationContext reactContext ,
223
- @ NonNull ViewManagerRegistry viewManagerRegistry ,
224
- @ NonNull BatchEventDispatchedListener batchEventDispatchedListener ) {
220
+ ReactApplicationContext reactContext ,
221
+ ViewManagerRegistry viewManagerRegistry ,
222
+ BatchEventDispatchedListener batchEventDispatchedListener ) {
225
223
mDispatchUIFrameCallback = new DispatchUIFrameCallback (reactContext );
226
224
mReactApplicationContext = reactContext ;
227
225
mMountingManager = new MountingManager (viewManagerRegistry , mMountItemExecutor );
@@ -239,8 +237,8 @@ public FabricUIManager(
239
237
@ UiThread
240
238
@ ThreadConfined (UI )
241
239
@ Deprecated
242
- // NULLSAFE_FIXME[Inconsistent Subclass Parameter Annotation]
243
- public < T extends View > int addRootView ( final T rootView , final WritableMap initialProps ) {
240
+ public < T extends View > int addRootView (
241
+ final T rootView , final @ Nullable WritableMap initialProps ) {
244
242
ReactSoftExceptionLogger .logSoftException (
245
243
TAG ,
246
244
new IllegalViewOperationException (
@@ -257,19 +255,18 @@ public <T extends View> int addRootView(final T rootView, final WritableMap init
257
255
if (ReactNativeFeatureFlags .enableFabricLogs ()) {
258
256
FLog .d (TAG , "Starting surface for module: %s and reactTag: %d" , moduleName , rootTag );
259
257
}
260
- // NULLSAFE_FIXME[Nullable Dereference]
258
+ Assertions . assertNotNull ( mBinding , "Binding in FabricUIManager is null" );
261
259
mBinding .startSurface (rootTag , moduleName , (NativeMap ) initialProps );
262
260
return rootTag ;
263
261
}
264
262
265
263
@ Override
266
264
@ AnyThread
267
265
@ ThreadConfined (ANY )
268
- // NULLSAFE_FIXME[Inconsistent Subclass Parameter Annotation]
269
266
public <T extends View > int startSurface (
270
267
final T rootView ,
271
268
final String moduleName ,
272
- final WritableMap initialProps ,
269
+ final @ Nullable WritableMap initialProps ,
273
270
int widthMeasureSpec ,
274
271
int heightMeasureSpec ) {
275
272
final int rootTag = ((ReactRoot ) rootView ).getRootViewTag ();
@@ -288,7 +285,7 @@ public <T extends View> int startSurface(
288
285
Point viewportOffset =
289
286
UiThreadUtil .isOnUiThread () ? RootViewUtil .getViewportOffset (rootView ) : new Point (0 , 0 );
290
287
291
- // NULLSAFE_FIXME[Nullable Dereference]
288
+ Assertions . assertNotNull ( mBinding , "Binding in FabricUIManager is null" );
292
289
mBinding .startSurfaceWithConstraints (
293
290
rootTag ,
294
291
moduleName ,
@@ -314,7 +311,7 @@ public void startSurface(
314
311
new ThemedReactContext (
315
312
mReactApplicationContext , context , surfaceHandler .getModuleName (), rootTag );
316
313
mMountingManager .startSurface (rootTag , reactContext , rootView );
317
- // NULLSAFE_FIXME[Nullable Dereference]
314
+ Assertions . assertNotNull ( mBinding , "Binding in FabricUIManager is null" );
318
315
mBinding .startSurfaceWithSurfaceHandler (rootTag , surfaceHandler , rootView != null );
319
316
}
320
317
@@ -339,7 +336,7 @@ public void stopSurface(final SurfaceHandlerBinding surfaceHandler) {
339
336
}
340
337
341
338
mMountingManager .stopSurface (surfaceHandler .getSurfaceId ());
342
- // NULLSAFE_FIXME[Nullable Dereference]
339
+ Assertions . assertNotNull ( mBinding , "Binding in FabricUIManager is null" );
343
340
mBinding .stopSurfaceWithSurfaceHandler (surfaceHandler );
344
341
}
345
342
@@ -359,7 +356,7 @@ public void stopSurface(final int surfaceID) {
359
356
// Communicate stopSurface to Cxx - causes an empty ShadowTree to be committed,
360
357
// but all mounting instructions will be ignored because stopSurface was called
361
358
// on the MountingManager
362
- // NULLSAFE_FIXME[Nullable Dereference]
359
+ Assertions . assertNotNull ( mBinding , "Binding in FabricUIManager is null" );
363
360
mBinding .stopSurface (surfaceID );
364
361
}
365
362
@@ -410,8 +407,9 @@ public void invalidate() {
410
407
mReactApplicationContext .removeLifecycleEventListener (this );
411
408
onHostPause ();
412
409
413
- // NULLSAFE_FIXME[Nullable Dereference]
414
- mBinding .unregister ();
410
+ if (mBinding != null ) {
411
+ mBinding .unregister ();
412
+ }
415
413
mBinding = null ;
416
414
417
415
ViewManagerPropertyUpdater .clear ();
@@ -455,7 +453,6 @@ public void prependUIBlock(UIBlock block) {
455
453
}
456
454
}
457
455
458
- @ NonNull
459
456
private InteropUIBlockListener getInteropUIBlockListener () {
460
457
if (mInteropUIBlockListener == null ) {
461
458
mInteropUIBlockListener = new InteropUIBlockListener ();
@@ -542,12 +539,13 @@ private long measure(
542
539
return 0 ;
543
540
}
544
541
context = surfaceMountingManager .getContext ();
542
+ Assertions .assertNotNull (
543
+ context , "Context in SurfaceMountingManager is null. surfaceId: " + surfaceId );
545
544
} else {
546
545
context = mReactApplicationContext ;
547
546
}
548
547
549
548
return mMountingManager .measure (
550
- // NULLSAFE_FIXME[Parameter Not Nullable]
551
549
context ,
552
550
componentName ,
553
551
localData ,
@@ -581,13 +579,14 @@ private long measureMapBuffer(
581
579
return 0 ;
582
580
}
583
581
context = surfaceMountingManager .getContext ();
582
+ Assertions .assertNotNull (
583
+ context , "Context in SurfaceMountingManager is null. surfaceId: " + surfaceId );
584
584
} else {
585
585
context = mReactApplicationContext ;
586
586
}
587
587
588
588
// TODO: replace ReadableNativeMap -> ReadableMapBuffer
589
589
return mMountingManager .measureMapBuffer (
590
- // NULLSAFE_FIXME[Parameter Not Nullable]
591
590
context ,
592
591
componentName ,
593
592
localData ,
@@ -624,13 +623,11 @@ public boolean getThemeData(int surfaceId, float[] defaultTextInputPadding) {
624
623
}
625
624
626
625
@ Override
627
- // NULLSAFE_FIXME[Inconsistent Subclass Parameter Annotation]
628
626
public void addUIManagerEventListener (UIManagerListener listener ) {
629
627
mListeners .add (listener );
630
628
}
631
629
632
630
@ Override
633
- // NULLSAFE_FIXME[Inconsistent Subclass Parameter Annotation]
634
631
public void removeUIManagerEventListener (UIManagerListener listener ) {
635
632
mListeners .remove (listener );
636
633
}
@@ -645,9 +642,7 @@ public void synchronouslyUpdateViewOnUIThread(
645
642
@ Override
646
643
@ UiThread
647
644
@ ThreadConfined (UI )
648
- // NULLSAFE_FIXME[Inconsistent Subclass Parameter Annotation]
649
- public void synchronouslyUpdateViewOnUIThread (
650
- final int reactTag , @ NonNull final ReadableMap props ) {
645
+ public void synchronouslyUpdateViewOnUIThread (final int reactTag , final ReadableMap props ) {
651
646
UiThreadUtil .assertOnUiThread ();
652
647
653
648
int commitNumber = mCurrentSynchronousCommitNumber ++;
@@ -678,7 +673,7 @@ public void synchronouslyUpdateViewOnUIThread(
678
673
MountItem synchronousMountItem =
679
674
new MountItem () {
680
675
@ Override
681
- public void execute (@ NonNull MountingManager mountingManager ) {
676
+ public void execute (MountingManager mountingManager ) {
682
677
try {
683
678
mountingManager .updateProps (reactTag , props );
684
679
} catch (Exception ex ) {
@@ -696,7 +691,6 @@ public int getSurfaceId() {
696
691
return View .NO_ID ;
697
692
}
698
693
699
- @ NonNull
700
694
@ Override
701
695
public String toString () {
702
696
String propsString =
@@ -801,11 +795,14 @@ private void scheduleMountItem(
801
795
// calls scheduleMountItems with a BatchMountItem.
802
796
long scheduleMountItemStartTime = SystemClock .uptimeMillis ();
803
797
boolean isBatchMountItem = mountItem instanceof BatchMountItem ;
804
- boolean shouldSchedule =
805
- // NULLSAFE_FIXME[Nullable Dereference]
806
- (isBatchMountItem && !((BatchMountItem ) mountItem ).isBatchEmpty ())
807
- || (!isBatchMountItem && mountItem != null );
808
-
798
+ boolean shouldSchedule = false ;
799
+ if (isBatchMountItem ) {
800
+ BatchMountItem batchMountItem = (BatchMountItem ) mountItem ;
801
+ Assertions .assertNotNull (batchMountItem , "BatchMountItem is null" );
802
+ shouldSchedule = !batchMountItem .isBatchEmpty ();
803
+ } else {
804
+ shouldSchedule = mountItem != null ;
805
+ }
809
806
// In case of sync rendering, this could be called on the UI thread. Otherwise,
810
807
// it should ~always be called on the JS thread.
811
808
for (UIManagerListener listener : mListeners ) {
@@ -821,7 +818,7 @@ private void scheduleMountItem(
821
818
}
822
819
823
820
if (shouldSchedule ) {
824
- // NULLSAFE_FIXME[Parameter Not Nullable]
821
+ Assertions . assertNotNull ( mountItem , "MountItem is null" );
825
822
mMountItemDispatcher .addMountItem (mountItem );
826
823
Runnable runnable =
827
824
new GuardedRunnable (mReactApplicationContext ) {
@@ -918,7 +915,7 @@ public void updateRootLayoutSpecs(
918
915
doLeftAndRightSwapInRTL = I18nUtil .getInstance ().doLeftAndRightSwapInRTL (context );
919
916
}
920
917
921
- // NULLSAFE_FIXME[Nullable Dereference]
918
+ Assertions . assertNotNull ( mBinding , "Binding in FabricUIManager is null" );
922
919
mBinding .setConstraints (
923
920
surfaceId ,
924
921
getMinSize (widthMeasureSpec ),
@@ -932,11 +929,10 @@ public void updateRootLayoutSpecs(
932
929
}
933
930
934
931
@ Override
935
- public View resolveView (int reactTag ) {
932
+ public @ Nullable View resolveView (int reactTag ) {
936
933
UiThreadUtil .assertOnUiThread ();
937
934
938
935
SurfaceMountingManager surfaceManager = mMountingManager .getSurfaceManagerForView (reactTag );
939
- // NULLSAFE_FIXME[Return Not Nullable]
940
936
return surfaceManager == null ? null : surfaceManager .getView (reactTag );
941
937
}
942
938
@@ -979,7 +975,7 @@ public void receiveEvent(
979
975
public void receiveEvent (
980
976
int surfaceId ,
981
977
int reactTag ,
982
- @ NonNull String eventName ,
978
+ String eventName ,
983
979
boolean canCoalesceEvent ,
984
980
@ Nullable WritableMap params ,
985
981
@ EventCategoryDef int eventCategory ,
@@ -1032,7 +1028,6 @@ public void onHostResume() {
1032
1028
}
1033
1029
1034
1030
@ Override
1035
- @ NonNull
1036
1031
public EventDispatcher getEventDispatcher () {
1037
1032
return mEventDispatcher ;
1038
1033
}
@@ -1145,7 +1140,7 @@ public void setJSResponder(
1145
1140
mMountItemDispatcher .addMountItem (
1146
1141
new MountItem () {
1147
1142
@ Override
1148
- public void execute (@ NonNull MountingManager mountingManager ) {
1143
+ public void execute (MountingManager mountingManager ) {
1149
1144
SurfaceMountingManager surfaceMountingManager =
1150
1145
mountingManager .getSurfaceManager (surfaceId );
1151
1146
if (surfaceMountingManager != null ) {
@@ -1162,7 +1157,6 @@ public int getSurfaceId() {
1162
1157
return surfaceId ;
1163
1158
}
1164
1159
1165
- @ NonNull
1166
1160
@ SuppressLint ("DefaultLocale" )
1167
1161
@ Override
1168
1162
public String toString () {
@@ -1179,7 +1173,7 @@ public void clearJSResponder() {
1179
1173
mMountItemDispatcher .addMountItem (
1180
1174
new MountItem () {
1181
1175
@ Override
1182
- public void execute (@ NonNull MountingManager mountingManager ) {
1176
+ public void execute (MountingManager mountingManager ) {
1183
1177
mountingManager .clearJSResponder ();
1184
1178
}
1185
1179
@@ -1188,7 +1182,6 @@ public int getSurfaceId() {
1188
1182
return View .NO_ID ;
1189
1183
}
1190
1184
1191
- @ NonNull
1192
1185
@ Override
1193
1186
public String toString () {
1194
1187
return "CLEAR_JS_RESPONDER" ;
@@ -1337,7 +1330,7 @@ private class DispatchUIFrameCallback extends GuardedFrameCallback {
1337
1330
@ ThreadConfined (UI )
1338
1331
private boolean mIsScheduled = false ;
1339
1332
1340
- private DispatchUIFrameCallback (@ NonNull ReactContext reactContext ) {
1333
+ private DispatchUIFrameCallback (ReactContext reactContext ) {
1341
1334
super (reactContext );
1342
1335
}
1343
1336
0 commit comments