Fix NPE when combining pop with add transaction.

Bug 35832085

When pop transactions and an add transaction are acting
in the same frame, optimized tranactions can work properly,
but unoptimized transactions have no guarantees. This fixes
a crash with unoptimized transactions so they will at least
not break.

Test: I996f54ae2540f31134e6a9a28870826a73ea1610
Change-Id: I3890dd30e9aff70f4ac142773de8479f1a9dffc8
This commit is contained in:
George Mount
2017-03-01 15:38:02 -08:00
parent 43d059bf48
commit f05db56f24

View File

@@ -780,8 +780,10 @@ class FragmentTransition {
names = inTransaction.mSharedElementTargetNames;
}
inSharedElements.retainAll(names);
if (sharedElementCallback != null) {
if (names != null) {
inSharedElements.retainAll(names);
}
if (names != null && sharedElementCallback != null) {
sharedElementCallback.onMapSharedElements(names, inSharedElements);
for (int i = names.size() - 1; i >= 0; i--) {
String name = names.get(i);
@@ -830,8 +832,9 @@ class FragmentTransition {
FragmentContainerTransition fragments,
Transition enterTransition, boolean inIsPop) {
BackStackRecord inTransaction = fragments.lastInTransaction;
if (enterTransition != null && inTransaction.mSharedElementSourceNames != null &&
!inTransaction.mSharedElementSourceNames.isEmpty()) {
if (enterTransition != null && inSharedElements != null
&& inTransaction.mSharedElementSourceNames != null
&& !inTransaction.mSharedElementSourceNames.isEmpty()) {
final String targetName = inIsPop
? inTransaction.mSharedElementSourceNames.get(0)
: inTransaction.mSharedElementTargetNames.get(0);
@@ -1096,7 +1099,9 @@ class FragmentTransition {
if (transition != null) {
viewList = new ArrayList<>();
View root = fragment.getView();
root.captureTransitioningViews(viewList);
if (root != null) {
root.captureTransitioningViews(viewList);
}
if (sharedElements != null) {
viewList.removeAll(sharedElements);
}