31
31
import androidx .annotation .UiThread ;
32
32
import androidx .annotation .VisibleForTesting ;
33
33
import com .facebook .infer .annotation .Nullsafe ;
34
- import com .facebook .rendercore .Function ;
35
34
import com .facebook .rendercore .Host ;
36
35
import com .facebook .rendercore .MountDelegate ;
37
36
import com .facebook .rendercore .RenderCoreSystrace ;
@@ -334,12 +333,16 @@ private static void processVisibilityOutputsNonInc(
334
333
continue ;
335
334
}
336
335
337
- final Function <Void > visibleHandler = visibilityOutput .getOnVisible ();
338
- final Function <Void > focusedHandler = visibilityOutput .getOnFocusedVisible ();
339
- final Function <Void > unfocusedHandler = visibilityOutput .getOnUnfocusedVisible ();
340
- final Function <Void > fullImpressionHandler = visibilityOutput .getOnFullImpression ();
341
- final Function <Void > invisibleHandler = visibilityOutput .getOnInvisible ();
342
- final Function <Void > visibilityChangedHandler = visibilityOutput .getOnVisibilityChange ();
336
+ final @ Nullable VisibilityEventCallbackData onVisible = visibilityOutput .getOnVisible ();
337
+ final @ Nullable VisibilityEventCallbackData onFocusedVisible =
338
+ visibilityOutput .getOnFocusedVisible ();
339
+ final @ Nullable VisibilityEventCallbackData onUnfocusedVisible =
340
+ visibilityOutput .getOnUnfocusedVisible ();
341
+ final @ Nullable VisibilityEventCallbackData onFullImpression =
342
+ visibilityOutput .getOnFullImpression ();
343
+ final @ Nullable VisibilityEventCallbackData onInvisible = visibilityOutput .getOnInvisible ();
344
+ final @ Nullable VisibilityEventCallbackData onVisibilityChange =
345
+ visibilityOutput .getOnVisibilityChange ();
343
346
344
347
final boolean isCurrentlyVisible =
345
348
boundsIntersect
@@ -349,24 +352,25 @@ private static void processVisibilityOutputsNonInc(
349
352
350
353
// If we did a relayout due to e.g. a state update then the handlers will have changed,
351
354
// so we should keep them up to date.
352
- visibilityItem .setUnfocusedHandler (unfocusedHandler );
353
- visibilityItem .setInvisibleHandler (invisibleHandler );
355
+ visibilityItem .setUnfocusedHandler (onUnfocusedVisible );
356
+ visibilityItem .setInvisibleHandler (onInvisible );
354
357
355
358
if (!isCurrentlyVisible ) {
356
359
// Either the component is invisible now, but used to be visible, or the key on the
357
360
// component has changed so we should generate new visibility events for the new
358
361
// component.
359
362
maybeDispatchOnInvisible (extensionState .getRenderStateId (), visibilityItem );
360
363
361
- if (visibilityChangedHandler != null ) {
364
+ if (onVisibilityChange != null ) {
362
365
VisibilityUtils .dispatchOnVisibilityChanged (
363
- visibilityChangedHandler , 0 , 0 , 0 , 0 , 0 , 0 , 0f , 0f );
366
+ onVisibilityChange . getCallback () , 0 , 0 , 0 , 0 , 0 , 0 , 0f , 0f );
364
367
}
365
368
366
369
if (visibilityItem .isInFocusedRange ()) {
367
370
visibilityItem .setFocusedRange (false );
368
371
if (visibilityItem .getUnfocusedHandler () != null ) {
369
- VisibilityUtils .dispatchOnUnfocused (visibilityItem .getUnfocusedHandler ());
372
+ VisibilityUtils .dispatchOnUnfocused (
373
+ visibilityItem .getUnfocusedHandler ().getCallback ());
370
374
}
371
375
}
372
376
@@ -385,9 +389,9 @@ private static void processVisibilityOutputsNonInc(
385
389
visibilityItem =
386
390
new VisibilityItem (
387
391
globalKey ,
388
- invisibleHandler ,
389
- unfocusedHandler ,
390
- visibilityChangedHandler ,
392
+ onInvisible ,
393
+ onUnfocusedVisible ,
394
+ onVisibilityChange ,
391
395
visibilityOutput .getKey (),
392
396
visibilityOutput .renderUnitId ,
393
397
visibilityOutput .getBounds ());
@@ -396,7 +400,7 @@ private static void processVisibilityOutputsNonInc(
396
400
visibilityItem .setWasFullyVisible (isFullyVisible );
397
401
state .mVisibilityIdToItemMap .put (visibilityOutputId , visibilityItem );
398
402
399
- if (visibleHandler != null ) {
403
+ if (onVisible != null ) {
400
404
final Object content =
401
405
visibilityOutput .hasMountableContent
402
406
? getContentById (extensionState , visibilityOutput .renderUnitId )
@@ -413,7 +417,7 @@ private static void processVisibilityOutputsNonInc(
413
417
createVisibilityDebugAttributes (visibilityItem ));
414
418
}
415
419
416
- VisibilityUtils .dispatchOnVisible (visibleHandler , content );
420
+ VisibilityUtils .dispatchOnVisible (onVisible . getCallback () , content );
417
421
418
422
if (traceIdentifier != null ) {
419
423
DebugEventDispatcher .endTrace (traceIdentifier );
@@ -422,9 +426,9 @@ private static void processVisibilityOutputsNonInc(
422
426
}
423
427
424
428
Rect transformedViewportRect = null ;
425
- if (focusedHandler != null
426
- || unfocusedHandler != null
427
- || visibilityChangedHandler != null ) {
429
+ if (onFocusedVisible != null
430
+ || onUnfocusedVisible != null
431
+ || onVisibilityChange != null ) {
428
432
if (shouldUseTransformedVisibleRect && transformer != null ) {
429
433
final Host host = getRootHost (extensionState );
430
434
if (host != null && (host .getParent () instanceof View )) {
@@ -435,7 +439,7 @@ private static void processVisibilityOutputsNonInc(
435
439
}
436
440
437
441
// Check if the component has entered or exited the focused range.
438
- if (focusedHandler != null || unfocusedHandler != null ) {
442
+ if (onFocusedVisible != null || onUnfocusedVisible != null ) {
439
443
if (isInFocusedRange (
440
444
extensionState ,
441
445
visibilityOutputBounds ,
@@ -444,30 +448,30 @@ private static void processVisibilityOutputsNonInc(
444
448
transformedViewportRect )) {
445
449
if (!visibilityItem .isInFocusedRange ()) {
446
450
visibilityItem .setFocusedRange (true );
447
- if (focusedHandler != null ) {
448
- VisibilityUtils .dispatchOnFocused (focusedHandler );
451
+ if (onFocusedVisible != null ) {
452
+ VisibilityUtils .dispatchOnFocused (onFocusedVisible . getCallback () );
449
453
}
450
454
}
451
455
} else {
452
456
if (visibilityItem .isInFocusedRange ()) {
453
457
visibilityItem .setFocusedRange (false );
454
- if (unfocusedHandler != null ) {
455
- VisibilityUtils .dispatchOnUnfocused (unfocusedHandler );
458
+ if (onUnfocusedVisible != null ) {
459
+ VisibilityUtils .dispatchOnUnfocused (onUnfocusedVisible . getCallback () );
456
460
}
457
461
}
458
462
}
459
463
}
460
464
// If the component has not entered the full impression range yet, make sure to update the
461
465
// information about the visible edges.
462
- if (fullImpressionHandler != null && !visibilityItem .isInFullImpressionRange ()) {
466
+ if (onFullImpression != null && !visibilityItem .isInFullImpressionRange ()) {
463
467
visibilityItem .setVisibleEdges (visibilityOutputBounds , intersection );
464
468
465
469
if (visibilityItem .isInFullImpressionRange ()) {
466
- VisibilityUtils .dispatchOnFullImpression (fullImpressionHandler );
470
+ VisibilityUtils .dispatchOnFullImpression (onFullImpression . getCallback () );
467
471
}
468
472
}
469
473
470
- if (visibilityChangedHandler != null ) {
474
+ if (onVisibilityChange != null ) {
471
475
final int visibleWidth = getVisibleWidth (intersection );
472
476
final int visibleHeight = getVisibleHeight (intersection );
473
477
int rootHostViewWidth = getRootHostViewWidth (extensionState );
@@ -478,7 +482,7 @@ private static void processVisibilityOutputsNonInc(
478
482
}
479
483
480
484
VisibilityUtils .dispatchOnVisibilityChanged (
481
- visibilityChangedHandler ,
485
+ onVisibilityChange . getCallback () ,
482
486
getVisibleTop (visibilityOutputBounds , intersection ),
483
487
getVisibleLeft (visibilityOutputBounds , intersection ),
484
488
visibleWidth ,
@@ -539,7 +543,7 @@ private static void maybeDispatchOnInvisible(int renderStateId, VisibilityItem v
539
543
createVisibilityDebugAttributes (visibilityItem ));
540
544
}
541
545
542
- VisibilityUtils .dispatchOnInvisible (visibilityItem .getInvisibleHandler ());
546
+ VisibilityUtils .dispatchOnInvisible (visibilityItem .getInvisibleHandler (). getCallback () );
543
547
544
548
if (traceIdentifier != null ) {
545
549
DebugEventDispatcher .endTrace (traceIdentifier );
@@ -619,22 +623,23 @@ private static void clearVisibilityItemsNonincremental(
619
623
final VisibilityItem visibilityItem = state .mVisibilityIdToItemMap .get (key );
620
624
621
625
if (visibilityItem != null ) {
622
- final Function <Void > unfocusedHandler = visibilityItem .getUnfocusedHandler ();
623
- final Function <Void > visibilityChangedHandler =
626
+ final @ Nullable VisibilityEventCallbackData onUnfocused =
627
+ visibilityItem .getUnfocusedHandler ();
628
+ final @ Nullable VisibilityEventCallbackData onVisibilityChanged =
624
629
visibilityItem .getVisibilityChangedHandler ();
625
630
626
631
maybeDispatchOnInvisible (renderStateId , visibilityItem );
627
632
628
633
if (visibilityItem .isInFocusedRange ()) {
629
634
visibilityItem .setFocusedRange (false );
630
- if (unfocusedHandler != null ) {
631
- VisibilityUtils .dispatchOnUnfocused (unfocusedHandler );
635
+ if (onUnfocused != null ) {
636
+ VisibilityUtils .dispatchOnUnfocused (onUnfocused . getCallback () );
632
637
}
633
638
}
634
639
635
- if (visibilityChangedHandler != null ) {
640
+ if (onVisibilityChanged != null ) {
636
641
VisibilityUtils .dispatchOnVisibilityChanged (
637
- visibilityChangedHandler , 0 , 0 , 0 , 0 , 0 , 0 , 0f , 0f );
642
+ onVisibilityChanged . getCallback () , 0 , 0 , 0 , 0 , 0 , 0 , 0f , 0f );
638
643
}
639
644
640
645
visibilityItem .setWasFullyVisible (false );
0 commit comments