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

        final SharedElementCallback sharedElementCallback;
        final ArrayList<String> names;
        final BackStackRecord inTransaction = fragments.lastInTransaction;
        if (fragments.lastInIsPop) {
            sharedElementCallback = inFragment.getExitTransitionCallback();
            names = inTransaction.mSharedElementSourceNames;
        } else {
            sharedElementCallback = inFragment.getEnterTransitionCallback();
            names = inTransaction.mSharedElementTargetNames;
        }

        if (names != null) {
            inSharedElements.retainAll(names);
            inSharedElements.retainAll(nameOverrides.values());
        }
        if (sharedElementCallback != null) {
            sharedElementCallback.onMapSharedElements(names, inSharedElements);
            for (int i = names.size() - 1; i >= 0; i--) {
                String name = names.get(i);
                View view = inSharedElements.get(name);
                if (view == null) {
                    String key = findKeyForValue(nameOverrides, name);
                    if (key != null) {
                        nameOverrides.remove(key);
                    }
                } else if (!name.equals(ViewCompat.getTransitionName(view))) {
                    String key = findKeyForValue(nameOverrides, name);
                    if (key != null) {
                        nameOverrides.put(key, ViewCompat.getTransitionName(view));
                    }
                }
            }
        } else {
            retainValues(nameOverrides, inSharedElements);
        }
        return inSharedElements;
    }
/**
     * Finds the shared elements in the incoming 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 incoming 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 incoming 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> captureInSharedElements(FragmentTransitionImpl impl,
            ArrayMap<String, String> nameOverrides, Object sharedElementTransition,
            FragmentContainerTransition fragments) {
        Fragment inFragment = fragments.lastIn;
        final View fragmentView = inFragment.getView();
        if (nameOverrides.isEmpty() || sharedElementTransition == null || fragmentView == null) {
            nameOverrides.clear();
            return null;
        }
        final ArrayMap<String, View> inSharedElements = new ArrayMap<>();
        impl.findNamedViews(inSharedElements, fragmentView);
        final SharedElementCallback sharedElementCallback;
        final ArrayList<String> names;
        final BackStackRecord inTransaction = fragments.lastInTransaction;
        if (fragments.lastInIsPop) {
            sharedElementCallback = inFragment.getExitTransitionCallback();
            names = inTransaction.mSharedElementSourceNames;
        } else {
            sharedElementCallback = inFragment.getEnterTransitionCallback();
            names = inTransaction.mSharedElementTargetNames;
        }
        if (names != null) {
            inSharedElements.retainAll(names);
            inSharedElements.retainAll(nameOverrides.values());
        }
        if (sharedElementCallback != null) {
            sharedElementCallback.onMapSharedElements(names, inSharedElements);
            for (int i = names.size() - 1; i >= 0; i--) {
                String name = names.get(i);
                View view = inSharedElements.get(name);
                if (view == null) {
                    String key = findKeyForValue(nameOverrides, name);
                    if (key != null) {
                        nameOverrides.remove(key);
                    }
                } else if (!name.equals(ViewCompat.getTransitionName(view))) {
                    String key = findKeyForValue(nameOverrides, name);
                    if (key != null) {
                        nameOverrides.put(key, ViewCompat.getTransitionName(view));
                    }
                }
            }
        } else {
            retainValues(nameOverrides, inSharedElements);
        }
        return inSharedElements;
    }
private static ArrayMap < String , View > captureInSharedElements ( FragmentTransitionImpl impl , ArrayMap < String , String > nameOverrides , Object sharedElementTransition , FragmentContainerTransition fragments ) { Fragment inFragment = fragments . lastIn ; final View fragmentView = inFragment . getView ( ) ; if ( nameOverrides . isEmpty ( ) || sharedElementTransition == null || fragmentView == null ) { nameOverrides . clear ( ) ; return null ; } final ArrayMap < String , View > inSharedElements = new ArrayMap < > ( ) ; impl . findNamedViews ( inSharedElements , fragmentView ) ; final SharedElementCallback sharedElementCallback ; final ArrayList < String > names ; final BackStackRecord inTransaction = fragments . lastInTransaction ; if ( fragments . lastInIsPop ) { sharedElementCallback = inFragment . getExitTransitionCallback ( ) ; names = inTransaction . mSharedElementSourceNames ; } else { sharedElementCallback = inFragment . getEnterTransitionCallback ( ) ; names = inTransaction . mSharedElementTargetNames ; } if ( names != null ) { inSharedElements . retainAll ( names ) ; inSharedElements . retainAll ( nameOverrides . values ( ) ) ; } if ( sharedElementCallback != null ) { sharedElementCallback . onMapSharedElements ( names , inSharedElements ) ; for ( int i = names . size ( ) - 1 ; i >= 0 ; i -- ) { String name = names . get ( i ) ; View view = inSharedElements . get ( name ) ; if ( view == null ) { String key = findKeyForValue ( nameOverrides , name ) ; if ( key != null ) { nameOverrides . remove ( key ) ; } } else if ( ! name . equals ( ViewCompat . getTransitionName ( view ) ) ) { String key = findKeyForValue ( nameOverrides , name ) ; if ( key != null ) { nameOverrides . put ( key , ViewCompat . getTransitionName ( view ) ) ; } } } } else { retainValues ( nameOverrides , inSharedElements ) ; } return inSharedElements ; }
Finds the shared elements in the incoming fragment.
Finds the shared elements in the incoming fragment .