fragment/src/main/java/androidx/fragment/app/FragmentTransition.java
private static Object configureSharedElementsReordered(final FragmentTransitionImpl impl,
            final ViewGroup sceneRoot,
            final View nonExistentView, final ArrayMap<String, String> nameOverrides,
            final FragmentContainerTransition fragments,
            final ArrayList<View> sharedElementsOut,
            final ArrayList<View> sharedElementsIn,
            final Object enterTransition, final Object exitTransition) {
        final Fragment inFragment = fragments.lastIn;
        final Fragment outFragment = fragments.firstOut;
        if (inFragment != null) {
            inFragment.getView().setVisibility(View.VISIBLE);
        }
        if (inFragment == null || outFragment == null) {
            return null; // no shared element without a fragment
        }

        final boolean inIsPop = fragments.lastInIsPop;
        Object sharedElementTransition = nameOverrides.isEmpty() ? null
                : getSharedElementTransition(impl, inFragment, outFragment, inIsPop);

        final ArrayMap<String, View> outSharedElements = captureOutSharedElements(impl,
                nameOverrides, sharedElementTransition, fragments);

        final ArrayMap<String, View> inSharedElements = captureInSharedElements(impl,
                nameOverrides, sharedElementTransition, fragments);

        if (nameOverrides.isEmpty()) {
            sharedElementTransition = null;
            if (outSharedElements != null) {
                outSharedElements.clear();
            }
            if (inSharedElements != null) {
                inSharedElements.clear();
            }
        } else {
            addSharedElementsWithMatchingNames(sharedElementsOut, outSharedElements,
                    nameOverrides.keySet());
            addSharedElementsWithMatchingNames(sharedElementsIn, inSharedElements,
                    nameOverrides.values());
        }

        if (enterTransition == null && exitTransition == null && sharedElementTransition == null) {
            // don't call onSharedElementStart/End since there is no transition
            return null;
        }

        callSharedElementStartEnd(inFragment, outFragment, inIsPop, outSharedElements, true);

        final Rect epicenter;
        final View epicenterView;
        if (sharedElementTransition != null) {
            sharedElementsIn.add(nonExistentView);
            impl.setSharedElementTargets(sharedElementTransition,
                    nonExistentView, sharedElementsOut);
            final boolean outIsPop = fragments.firstOutIsPop;
            final BackStackRecord outTransaction = fragments.firstOutTransaction;
            setOutEpicenter(impl, sharedElementTransition, exitTransition, outSharedElements,
                    outIsPop, outTransaction);
            epicenter = new Rect();
            epicenterView = getInEpicenterView(inSharedElements, fragments,
                    enterTransition, inIsPop);
            if (epicenterView != null) {
                impl.setEpicenter(enterTransition, epicenter);
            }
        } else {
            epicenter = null;
            epicenterView = null;
        }

        OneShotPreDrawListener.add(sceneRoot, new Runnable() {
            @Override
            public void run() {
                callSharedElementStartEnd(inFragment, outFragment, inIsPop,
                        inSharedElements, false);
                if (epicenterView != null) {
                    impl.getBoundsOnScreen(epicenterView, epicenter);
                }
            }
        });
        return sharedElementTransition;
    }
/**
     * Configures the shared elements of a reordered fragment transaction's transition.
     * This retrieves the shared elements of the outgoing and incoming fragments, maps the
     * views, and sets up the epicenter on the transitions.
     * <p>
     * The epicenter of exit and shared element transitions is the first shared element
     * in the outgoing fragment. The epicenter of the entering transition is the first shared
     * element in the incoming fragment.
     *
     * @param sceneRoot The fragment container View
     * @param nonExistentView A View that does not exist in the hierarchy. This is used to
     *                        prevent transitions from acting on other Views when there is no
     *                        other target.
     * @param nameOverrides A map of the shared element names from the starting fragment to
     *                      the final fragment's Views as given in
     *                      {@link FragmentTransaction#addSharedElement(View, String)}.
     * @param fragments A structure holding the transitioning fragments in this container.
     * @param sharedElementsOut A list modified to contain the shared elements in the outgoing
     *                          fragment
     * @param sharedElementsIn A list modified to contain the shared elements in the incoming
     *                         fragment
     * @param enterTransition The transition used for entering Views, modified by applying the
     *                        epicenter
     * @param exitTransition The transition used for exiting Views, modified by applying the
     *                       epicenter
     * @return The shared element transition or null if no shared elements exist
     */
Configures the shared elements of a reordered fragment transaction's transition.
This retrieves the shared elements of the outgoing and incoming fragments, maps the
views, and sets up the epicenter on the transitions.

The epicenter of exit and shared element transitions is the first shared element
in the outgoing fragment. The epicenter of the entering transition is the first shared
element in the incoming fragment.

@param sceneRoot The fragment container View
@param nonExistentView A View that does not exist in the hierarchy. This is used to
prevent transitions from acting on other Views when there is no
other target.
@param nameOverrides A map of the shared element names from the starting fragment to
the final fragment's Views as given in
FragmentTransaction#addSharedElement(View, String).
@param fragments A structure holding the transitioning fragments in this container.
Configures the shared elements of a reordered fragment transaction ' s transition . This retrieves the shared elements of the outgoing and incoming fragments maps the views and sets up the epicenter on the transitions . The epicenter of exit and shared element transitions is the first shared element in the outgoing fragment . The epicenter of the entering transition is the first shared element in the incoming fragment . @param sceneRoot The fragment container View @param nonExistentView A View that does not exist in the hierarchy . This is used to prevent transitions from acting on other Views when there is no other target . @param nameOverrides A map of the shared element names from the starting fragment to the final fragment ' s Views as given in FragmentTransaction#addSharedElement ( View String ) . @param fragments A structure holding the transitioning fragments in this container .
private static Object configureSharedElementsReordered(final FragmentTransitionImpl impl,
            final ViewGroup sceneRoot,
            final View nonExistentView, final ArrayMap<String, String> nameOverrides,
            final FragmentContainerTransition fragments,
            final ArrayList<View> sharedElementsOut,
            final ArrayList<View> sharedElementsIn,
            final Object enterTransition, final Object exitTransition) {
        final Fragment inFragment = fragments.lastIn;
        final Fragment outFragment = fragments.firstOut;
        if (inFragment != null) {
            inFragment.getView().setVisibility(View.VISIBLE);
        }
        if (inFragment == null || outFragment == null) {
            return null; 
        }
        final boolean inIsPop = fragments.lastInIsPop;
        Object sharedElementTransition = nameOverrides.isEmpty() ? null
                : getSharedElementTransition(impl, inFragment, outFragment, inIsPop);
        final ArrayMap<String, View> outSharedElements = captureOutSharedElements(impl,
                nameOverrides, sharedElementTransition, fragments);
        final ArrayMap<String, View> inSharedElements = captureInSharedElements(impl,
                nameOverrides, sharedElementTransition, fragments);
        if (nameOverrides.isEmpty()) {
            sharedElementTransition = null;
            if (outSharedElements != null) {
                outSharedElements.clear();
            }
            if (inSharedElements != null) {
                inSharedElements.clear();
            }
        } else {
            addSharedElementsWithMatchingNames(sharedElementsOut, outSharedElements,
                    nameOverrides.keySet());
            addSharedElementsWithMatchingNames(sharedElementsIn, inSharedElements,
                    nameOverrides.values());
        }
        if (enterTransition == null && exitTransition == null && sharedElementTransition == null) {
            return null;
        }
        callSharedElementStartEnd(inFragment, outFragment, inIsPop, outSharedElements, true);
        final Rect epicenter;
        final View epicenterView;
        if (sharedElementTransition != null) {
            sharedElementsIn.add(nonExistentView);
            impl.setSharedElementTargets(sharedElementTransition,
                    nonExistentView, sharedElementsOut);
            final boolean outIsPop = fragments.firstOutIsPop;
            final BackStackRecord outTransaction = fragments.firstOutTransaction;
            setOutEpicenter(impl, sharedElementTransition, exitTransition, outSharedElements,
                    outIsPop, outTransaction);
            epicenter = new Rect();
            epicenterView = getInEpicenterView(inSharedElements, fragments,
                    enterTransition, inIsPop);
            if (epicenterView != null) {
                impl.setEpicenter(enterTransition, epicenter);
            }
        } else {
            epicenter = null;
            epicenterView = null;
        }
        OneShotPreDrawListener.add(sceneRoot, new Runnable() {
            @Override
            public void run() {
                callSharedElementStartEnd(inFragment, outFragment, inIsPop,
                        inSharedElements, false);
                if (epicenterView != null) {
                    impl.getBoundsOnScreen(epicenterView, epicenter);
                }
            }
        });
        return sharedElementTransition;
    }
private static Object configureSharedElementsReordered ( final FragmentTransitionImpl impl , final ViewGroup sceneRoot , final View nonExistentView , final ArrayMap < String , String > nameOverrides , final FragmentContainerTransition fragments , final ArrayList < View > sharedElementsOut , final ArrayList < View > sharedElementsIn , final Object enterTransition , final Object exitTransition ) { final Fragment inFragment = fragments . lastIn ; final Fragment outFragment = fragments . firstOut ; if ( inFragment != null ) { inFragment . getView ( ) . setVisibility ( View . VISIBLE ) ; } if ( inFragment == null || outFragment == null ) { return null ; } final boolean inIsPop = fragments . lastInIsPop ; Object sharedElementTransition = nameOverrides . isEmpty ( ) ? null : getSharedElementTransition ( impl , inFragment , outFragment , inIsPop ) ; final ArrayMap < String , View > outSharedElements = captureOutSharedElements ( impl , nameOverrides , sharedElementTransition , fragments ) ; final ArrayMap < String , View > inSharedElements = captureInSharedElements ( impl , nameOverrides , sharedElementTransition , fragments ) ; if ( nameOverrides . isEmpty ( ) ) { sharedElementTransition = null ; if ( outSharedElements != null ) { outSharedElements . clear ( ) ; } if ( inSharedElements != null ) { inSharedElements . clear ( ) ; } } else { addSharedElementsWithMatchingNames ( sharedElementsOut , outSharedElements , nameOverrides . keySet ( ) ) ; addSharedElementsWithMatchingNames ( sharedElementsIn , inSharedElements , nameOverrides . values ( ) ) ; } if ( enterTransition == null && exitTransition == null && sharedElementTransition == null ) { return null ; } callSharedElementStartEnd ( inFragment , outFragment , inIsPop , outSharedElements , true ) ; final Rect epicenter ; final View epicenterView ; if ( sharedElementTransition != null ) { sharedElementsIn . add ( nonExistentView ) ; impl . setSharedElementTargets ( sharedElementTransition , nonExistentView , sharedElementsOut ) ; final boolean outIsPop = fragments . firstOutIsPop ; final BackStackRecord outTransaction = fragments . firstOutTransaction ; setOutEpicenter ( impl , sharedElementTransition , exitTransition , outSharedElements , outIsPop , outTransaction ) ; epicenter = new Rect ( ) ; epicenterView = getInEpicenterView ( inSharedElements , fragments , enterTransition , inIsPop ) ; if ( epicenterView != null ) { impl . setEpicenter ( enterTransition , epicenter ) ; } } else { epicenter = null ; epicenterView = null ; } OneShotPreDrawListener . add ( sceneRoot , new Runnable ( ) { @ Override public void run ( ) { callSharedElementStartEnd ( inFragment , outFragment , inIsPop , inSharedElements , false ) ; if ( epicenterView != null ) { impl . getBoundsOnScreen ( epicenterView , epicenter ) ; } } } ) ; return sharedElementTransition ; }
Configures the shared elements of a reordered fragment transaction's transition.
Configures the shared elements of a reordered fragment transaction ' s transition .
// no shared element without a fragment // don't call onSharedElementStart/End since there is no transition