3131import androidx .annotation .UiThread ;
3232import androidx .annotation .VisibleForTesting ;
3333import com .facebook .infer .annotation .Nullsafe ;
34- import com .facebook .rendercore .Function ;
3534import com .facebook .rendercore .Host ;
3635import com .facebook .rendercore .MountDelegate ;
3736import com .facebook .rendercore .RenderCoreSystrace ;
@@ -334,12 +333,16 @@ private static void processVisibilityOutputsNonInc(
334333 continue ;
335334 }
336335
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 ();
343346
344347 final boolean isCurrentlyVisible =
345348 boundsIntersect
@@ -349,24 +352,25 @@ private static void processVisibilityOutputsNonInc(
349352
350353 // If we did a relayout due to e.g. a state update then the handlers will have changed,
351354 // so we should keep them up to date.
352- visibilityItem .setUnfocusedHandler (unfocusedHandler );
353- visibilityItem .setInvisibleHandler (invisibleHandler );
355+ visibilityItem .setUnfocusedHandler (onUnfocusedVisible );
356+ visibilityItem .setInvisibleHandler (onInvisible );
354357
355358 if (!isCurrentlyVisible ) {
356359 // Either the component is invisible now, but used to be visible, or the key on the
357360 // component has changed so we should generate new visibility events for the new
358361 // component.
359362 maybeDispatchOnInvisible (extensionState .getRenderStateId (), visibilityItem );
360363
361- if (visibilityChangedHandler != null ) {
364+ if (onVisibilityChange != null ) {
362365 VisibilityUtils .dispatchOnVisibilityChanged (
363- visibilityChangedHandler , 0 , 0 , 0 , 0 , 0 , 0 , 0f , 0f );
366+ onVisibilityChange . getCallback () , 0 , 0 , 0 , 0 , 0 , 0 , 0f , 0f );
364367 }
365368
366369 if (visibilityItem .isInFocusedRange ()) {
367370 visibilityItem .setFocusedRange (false );
368371 if (visibilityItem .getUnfocusedHandler () != null ) {
369- VisibilityUtils .dispatchOnUnfocused (visibilityItem .getUnfocusedHandler ());
372+ VisibilityUtils .dispatchOnUnfocused (
373+ visibilityItem .getUnfocusedHandler ().getCallback ());
370374 }
371375 }
372376
@@ -385,9 +389,9 @@ private static void processVisibilityOutputsNonInc(
385389 visibilityItem =
386390 new VisibilityItem (
387391 globalKey ,
388- invisibleHandler ,
389- unfocusedHandler ,
390- visibilityChangedHandler ,
392+ onInvisible ,
393+ onUnfocusedVisible ,
394+ onVisibilityChange ,
391395 visibilityOutput .getKey (),
392396 visibilityOutput .renderUnitId ,
393397 visibilityOutput .getBounds ());
@@ -396,7 +400,7 @@ private static void processVisibilityOutputsNonInc(
396400 visibilityItem .setWasFullyVisible (isFullyVisible );
397401 state .mVisibilityIdToItemMap .put (visibilityOutputId , visibilityItem );
398402
399- if (visibleHandler != null ) {
403+ if (onVisible != null ) {
400404 final Object content =
401405 visibilityOutput .hasMountableContent
402406 ? getContentById (extensionState , visibilityOutput .renderUnitId )
@@ -413,7 +417,7 @@ private static void processVisibilityOutputsNonInc(
413417 createVisibilityDebugAttributes (visibilityItem ));
414418 }
415419
416- VisibilityUtils .dispatchOnVisible (visibleHandler , content );
420+ VisibilityUtils .dispatchOnVisible (onVisible . getCallback () , content );
417421
418422 if (traceIdentifier != null ) {
419423 DebugEventDispatcher .endTrace (traceIdentifier );
@@ -422,9 +426,9 @@ private static void processVisibilityOutputsNonInc(
422426 }
423427
424428 Rect transformedViewportRect = null ;
425- if (focusedHandler != null
426- || unfocusedHandler != null
427- || visibilityChangedHandler != null ) {
429+ if (onFocusedVisible != null
430+ || onUnfocusedVisible != null
431+ || onVisibilityChange != null ) {
428432 if (shouldUseTransformedVisibleRect && transformer != null ) {
429433 final Host host = getRootHost (extensionState );
430434 if (host != null && (host .getParent () instanceof View )) {
@@ -435,7 +439,7 @@ private static void processVisibilityOutputsNonInc(
435439 }
436440
437441 // Check if the component has entered or exited the focused range.
438- if (focusedHandler != null || unfocusedHandler != null ) {
442+ if (onFocusedVisible != null || onUnfocusedVisible != null ) {
439443 if (isInFocusedRange (
440444 extensionState ,
441445 visibilityOutputBounds ,
@@ -444,30 +448,30 @@ private static void processVisibilityOutputsNonInc(
444448 transformedViewportRect )) {
445449 if (!visibilityItem .isInFocusedRange ()) {
446450 visibilityItem .setFocusedRange (true );
447- if (focusedHandler != null ) {
448- VisibilityUtils .dispatchOnFocused (focusedHandler );
451+ if (onFocusedVisible != null ) {
452+ VisibilityUtils .dispatchOnFocused (onFocusedVisible . getCallback () );
449453 }
450454 }
451455 } else {
452456 if (visibilityItem .isInFocusedRange ()) {
453457 visibilityItem .setFocusedRange (false );
454- if (unfocusedHandler != null ) {
455- VisibilityUtils .dispatchOnUnfocused (unfocusedHandler );
458+ if (onUnfocusedVisible != null ) {
459+ VisibilityUtils .dispatchOnUnfocused (onUnfocusedVisible . getCallback () );
456460 }
457461 }
458462 }
459463 }
460464 // If the component has not entered the full impression range yet, make sure to update the
461465 // information about the visible edges.
462- if (fullImpressionHandler != null && !visibilityItem .isInFullImpressionRange ()) {
466+ if (onFullImpression != null && !visibilityItem .isInFullImpressionRange ()) {
463467 visibilityItem .setVisibleEdges (visibilityOutputBounds , intersection );
464468
465469 if (visibilityItem .isInFullImpressionRange ()) {
466- VisibilityUtils .dispatchOnFullImpression (fullImpressionHandler );
470+ VisibilityUtils .dispatchOnFullImpression (onFullImpression . getCallback () );
467471 }
468472 }
469473
470- if (visibilityChangedHandler != null ) {
474+ if (onVisibilityChange != null ) {
471475 final int visibleWidth = getVisibleWidth (intersection );
472476 final int visibleHeight = getVisibleHeight (intersection );
473477 int rootHostViewWidth = getRootHostViewWidth (extensionState );
@@ -478,7 +482,7 @@ private static void processVisibilityOutputsNonInc(
478482 }
479483
480484 VisibilityUtils .dispatchOnVisibilityChanged (
481- visibilityChangedHandler ,
485+ onVisibilityChange . getCallback () ,
482486 getVisibleTop (visibilityOutputBounds , intersection ),
483487 getVisibleLeft (visibilityOutputBounds , intersection ),
484488 visibleWidth ,
@@ -539,7 +543,7 @@ private static void maybeDispatchOnInvisible(int renderStateId, VisibilityItem v
539543 createVisibilityDebugAttributes (visibilityItem ));
540544 }
541545
542- VisibilityUtils .dispatchOnInvisible (visibilityItem .getInvisibleHandler ());
546+ VisibilityUtils .dispatchOnInvisible (visibilityItem .getInvisibleHandler (). getCallback () );
543547
544548 if (traceIdentifier != null ) {
545549 DebugEventDispatcher .endTrace (traceIdentifier );
@@ -619,22 +623,23 @@ private static void clearVisibilityItemsNonincremental(
619623 final VisibilityItem visibilityItem = state .mVisibilityIdToItemMap .get (key );
620624
621625 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 =
624629 visibilityItem .getVisibilityChangedHandler ();
625630
626631 maybeDispatchOnInvisible (renderStateId , visibilityItem );
627632
628633 if (visibilityItem .isInFocusedRange ()) {
629634 visibilityItem .setFocusedRange (false );
630- if (unfocusedHandler != null ) {
631- VisibilityUtils .dispatchOnUnfocused (unfocusedHandler );
635+ if (onUnfocused != null ) {
636+ VisibilityUtils .dispatchOnUnfocused (onUnfocused . getCallback () );
632637 }
633638 }
634639
635- if (visibilityChangedHandler != null ) {
640+ if (onVisibilityChanged != null ) {
636641 VisibilityUtils .dispatchOnVisibilityChanged (
637- visibilityChangedHandler , 0 , 0 , 0 , 0 , 0 , 0 , 0f , 0f );
642+ onVisibilityChanged . getCallback () , 0 , 0 , 0 , 0 , 0 , 0 , 0f , 0f );
638643 }
639644
640645 visibilityItem .setWasFullyVisible (false );
0 commit comments