5151import android .graphics .drawable .Drawable ;
5252import android .os .Build .VERSION ;
5353import android .os .Build .VERSION_CODES ;
54+ import androidx .core .view .ViewCompat ;
55+ import android .util .Log ;
56+ import android .view .View ;
57+ import android .view .ViewGroup ;
5458import androidx .annotation .ColorInt ;
5559import androidx .annotation .FloatRange ;
5660import androidx .annotation .IdRes ;
5963import androidx .annotation .Nullable ;
6064import androidx .annotation .RestrictTo ;
6165import androidx .annotation .StyleRes ;
62- import androidx .core .view .ViewCompat ;
63- import android .view .View ;
64- import android .view .ViewGroup ;
6566import androidx .transition .ArcMotion ;
6667import androidx .transition .PathMotion ;
6768import androidx .transition .Transition ;
@@ -181,6 +182,7 @@ public final class MaterialContainerTransform extends Transition {
181182 @ Retention (RetentionPolicy .SOURCE )
182183 public @interface FitMode {}
183184
185+ private static final String TAG = MaterialContainerTransform .class .getSimpleName ();
184186 private static final String PROP_BOUNDS = "materialContainerTransition:bounds" ;
185187 private static final String PROP_SHAPE_APPEARANCE = "materialContainerTransition:shapeAppearance" ;
186188 private static final String [] TRANSITION_PROPS =
@@ -866,6 +868,22 @@ public Animator createAnimator(
866868 return null ;
867869 }
868870
871+ RectF startBounds = (RectF ) startValues .values .get (PROP_BOUNDS );
872+ ShapeAppearanceModel startShapeAppearanceModel =
873+ (ShapeAppearanceModel ) startValues .values .get (PROP_SHAPE_APPEARANCE );
874+ if (startBounds == null || startShapeAppearanceModel == null ) {
875+ Log .w (TAG , "Skipping due to null start bounds. Ensure start view is laid out and measured." );
876+ return null ;
877+ }
878+
879+ RectF endBounds = (RectF ) endValues .values .get (PROP_BOUNDS );
880+ ShapeAppearanceModel endShapeAppearanceModel =
881+ (ShapeAppearanceModel ) endValues .values .get (PROP_SHAPE_APPEARANCE );
882+ if (endBounds == null || endShapeAppearanceModel == null ) {
883+ Log .w (TAG , "Skipping due to null end bounds. Ensure end view is laid out and measured." );
884+ return null ;
885+ }
886+
869887 final View startView = startValues .view ;
870888 final View endView = endValues .view ;
871889 final View drawingView ;
@@ -879,21 +897,6 @@ public Animator createAnimator(
879897 boundingView = null ;
880898 }
881899
882- RectF startBounds = (RectF ) startValues .values .get (PROP_BOUNDS );
883- if (startBounds == null ) {
884- throw new IllegalStateException (
885- "Start view bounds must not be null, make sure the start view is laid out and measured." );
886- }
887- RectF endBounds = (RectF ) endValues .values .get (PROP_BOUNDS );
888- if (endBounds == null ) {
889- throw new IllegalStateException (
890- "End view bounds must not be null, make sure the end view is laid out and measured" );
891- }
892- ShapeAppearanceModel startShapeAppearanceModel =
893- (ShapeAppearanceModel ) startValues .values .get (PROP_SHAPE_APPEARANCE );
894- ShapeAppearanceModel endShapeAppearanceModel =
895- (ShapeAppearanceModel ) endValues .values .get (PROP_SHAPE_APPEARANCE );
896-
897900 // Calculate drawable bounds and offset start/end bounds as needed
898901 RectF drawingViewBounds = getLocationOnScreen (drawingView );
899902 float offsetX = -drawingViewBounds .left ;
0 commit comments