fragment/src/main/java/androidx/fragment/app/FragmentTransition.java
private static ArrayMap<String, View> captureOutSharedElements(FragmentTransitionImpl impl,
            ArrayMap<String, String> nameOverrides, Object sharedElementTransition,
            FragmentContainerTransition fragments) {
        if (nameOverrides.isEmpty() || sharedElementTransition == null) {
            nameOverrides.clear();
            return null;
        }
        final Fragment outFragment = fragments.firstOut;
        final ArrayMap<String, View> outSharedElements = new ArrayMap<>();
        impl.findNamedViews(outSharedElements, outFragment.getView());

        final SharedElementCallback sharedElementCallback;
        final ArrayList<String> names;
        final BackStackRecord outTransaction = fragments.firstOutTransaction;
        if (fragments.firstOutIsPop) {
            sharedElementCallback = outFragment.getEnterTransitionCallback();
            names = outTransaction.mSharedElementTargetNames;
        } else {
            sharedElementCallback = outFragment.getExitTransitionCallback();
            names = outTransaction.mSharedElementSourceNames;
        }

        outSharedElements.retainAll(names);
        if (sharedElementCallback != null) {
            sharedElementCallback.onMapSharedElements(names, outSharedElements);
            for (int i = names.size() - 1; i >= 0; i--) {
                String name = names.get(i);
                View view = outSharedElements.get(name);
                if (view == null) {
                    nameOverrides.remove(name);
                } else if (!name.equals(ViewCompat.getTransitionName(view))) {
                    String targetValue = nameOverrides.remove(name);
                    nameOverrides.put(ViewCompat.getTransitionName(view), targetValue);
                }
            }
        } else {
            nameOverrides.retainAll(outSharedElements.keySet());
        }
        return outSharedElements;
    }
/**
     * Finds the shared elements in the outgoing fragment. It also calls
     * {@link SharedElementCallback#onMapSharedElements(List, Map)} to allow more control
     * of the shared element mapping. {@code nameOverrides} is updated to match the
     * actual transition name of the mapped shared elements.
     *
     * @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 sharedElementTransition The shared element transition
     * @param fragments A structure holding the transitioning fragments in this container.
     * @return The mapping of shared element names to the Views in the hierarchy or null
     * if there is no shared element transition.
     */
Finds the shared elements in the outgoing fragment. It also calls
SharedElementCallback#onMapSharedElements(List, Map) to allow more control
of the shared element mapping.  nameOverrides is updated to match the
actual transition name of the mapped shared elements.

@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 sharedElementTransition The shared element transition
@param fragments A structure holding the transitioning fragments in this container.
@return The mapping of shared element names to the Views in the hierarchy or null
if there is no shared element transition.
Finds the shared elements in the outgoing fragment . It also calls SharedElementCallback#onMapSharedElements ( List Map ) to allow more control of the shared element mapping . nameOverrides is updated to match the actual transition name of the mapped shared elements . @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 sharedElementTransition The shared element transition @param fragments A structure holding the transitioning fragments in this container . @return The mapping of shared element names to the Views in the hierarchy or null if there is no shared element transition .
private static ArrayMap<String, View> captureOutSharedElements(FragmentTransitionImpl impl,
            ArrayMap<String, String> nameOverrides, Object sharedElementTransition,
            FragmentContainerTransition fragments) {
        if (nameOverrides.isEmpty() || sharedElementTransition == null) {
            nameOverrides.clear();
            return null;
        }
        final Fragment outFragment = fragments.firstOut;
        final ArrayMap<String, View> outSharedElements = new ArrayMap<>();
        impl.findNamedViews(outSharedElements, outFragment.getView());
        final SharedElementCallback sharedElementCallback;
        final ArrayList<String> names;
        final BackStackRecord outTransaction = fragments.firstOutTransaction;
        if (fragments.firstOutIsPop) {
            sharedElementCallback = outFragment.getEnterTransitionCallback();
            names = outTransaction.mSharedElementTargetNames;
        } else {
            sharedElementCallback = outFragment.getExitTransitionCallback();
            names = outTransaction.mSharedElementSourceNames;
        }
        outSharedElements.retainAll(names);
        if (sharedElementCallback != null) {
            sharedElementCallback.onMapSharedElements(names, outSharedElements);
            for (int i = names.size() - 1; i >= 0; i--) {
                String name = names.get(i);
                View view = outSharedElements.get(name);
                if (view == null) {
                    nameOverrides.remove(name);
                } else if (!name.equals(ViewCompat.getTransitionName(view))) {
                    String targetValue = nameOverrides.remove(name);
                    nameOverrides.put(ViewCompat.getTransitionName(view), targetValue);
                }
            }
        } else {
            nameOverrides.retainAll(outSharedElements.keySet());
        }
        return outSharedElements;
    }
private static ArrayMap < String , View > captureOutSharedElements ( FragmentTransitionImpl impl , ArrayMap < String , String > nameOverrides , Object sharedElementTransition , FragmentContainerTransition fragments ) { if ( nameOverrides . isEmpty ( ) || sharedElementTransition == null ) { nameOverrides . clear ( ) ; return null ; } final Fragment outFragment = fragments . firstOut ; final ArrayMap < String , View > outSharedElements = new ArrayMap < > ( ) ; impl . findNamedViews ( outSharedElements , outFragment . getView ( ) ) ; final SharedElementCallback sharedElementCallback ; final ArrayList < String > names ; final BackStackRecord outTransaction = fragments . firstOutTransaction ; if ( fragments . firstOutIsPop ) { sharedElementCallback = outFragment . getEnterTransitionCallback ( ) ; names = outTransaction . mSharedElementTargetNames ; } else { sharedElementCallback = outFragment . getExitTransitionCallback ( ) ; names = outTransaction . mSharedElementSourceNames ; } outSharedElements . retainAll ( names ) ; if ( sharedElementCallback != null ) { sharedElementCallback . onMapSharedElements ( names , outSharedElements ) ; for ( int i = names . size ( ) - 1 ; i >= 0 ; i -- ) { String name = names . get ( i ) ; View view = outSharedElements . get ( name ) ; if ( view == null ) { nameOverrides . remove ( name ) ; } else if ( ! name . equals ( ViewCompat . getTransitionName ( view ) ) ) { String targetValue = nameOverrides . remove ( name ) ; nameOverrides . put ( ViewCompat . getTransitionName ( view ) , targetValue ) ; } } } else { nameOverrides . retainAll ( outSharedElements . keySet ( ) ) ; } return outSharedElements ; }
Finds the shared elements in the outgoing fragment.
Finds the shared elements in the outgoing fragment .