Skip to content

Commit

Permalink
fix(android): fixed transition when end-element was fetched first
Browse files Browse the repository at this point in the history
  • Loading branch information
IjzerenHein committed Sep 4, 2019
1 parent 67de699 commit 92a999c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
Expand Up @@ -38,6 +38,7 @@ enum Item {
private float mNodePosition = 0.0f;
private boolean mReactLayoutSet = false;
private boolean mInitialLayoutPassCompleted = false;
private boolean mInitialNodePositionSet = false;
private ArrayList<RNSharedElementTransitionItem> mItems = new ArrayList<RNSharedElementTransitionItem>();
private int[] mParentOffset = new int[2];
private boolean mRequiresClipping = false;
Expand Down Expand Up @@ -90,8 +91,9 @@ public void setAlign(final RNSharedElementAlign align) {

public void setNodePosition(final float nodePosition) {
if (mNodePosition != nodePosition) {
mNodePosition = nodePosition;
//Log.d(LOG_TAG, "setNodePosition " + nodePosition + ", mInitialLayoutPassCompleted: " + mInitialLayoutPassCompleted);
mNodePosition = nodePosition;
mInitialNodePositionSet = true;
updateLayout();
}
}
Expand Down Expand Up @@ -207,6 +209,10 @@ private void updateLayout() {
interpolatedStyle = startStyle;
interpolatedClipInsets = startClipInsets;
} else {
if (!mInitialNodePositionSet) {
mNodePosition = 1.0f;
mInitialNodePositionSet = true;
}
interpolatedLayout = endLayout;
interpolatedStyle = endStyle;
interpolatedClipInsets = endClipInsets;
Expand All @@ -221,7 +227,7 @@ private void updateLayout() {
// Calculate clipped layout
mRequiresClipping = !parentLayout.contains(interpolatedLayout);

//Log.d(LOG_TAG, "mRequiresClipping: " +mRequiresClipping + ", " + endClippedLayout + ", " + endClipInsets);
Log.d(LOG_TAG, "updateLayout: " + mNodePosition);

// Update outer viewgroup layout. The outer viewgroup hosts 2 inner views
// which draw the content & elevation. The outer viewgroup performs additional
Expand All @@ -242,7 +248,7 @@ private void updateLayout() {
switch (mAnimation) {
case MOVE:
startAlpha = interpolatedStyle.opacity;
endAlpha = 0.0f;
endAlpha = (startStyle == null) ? interpolatedStyle.opacity : 0.0f;
break;
case FADE:
startAlpha = ((startStyle != null) ? startStyle.opacity : 1) * (1 - mNodePosition);
Expand Down Expand Up @@ -275,7 +281,10 @@ private void updateLayout() {
}

// Render the end view as well for the "cross-fade" animations
if ((mAnimation == RNSharedElementAnimation.FADE) || (mAnimation == RNSharedElementAnimation.FADE_IN)) {
if ((mAnimation == RNSharedElementAnimation.FADE)
|| (mAnimation == RNSharedElementAnimation.FADE_IN)
|| ((mAnimation == RNSharedElementAnimation.MOVE) && (startStyle == null))
) {
mEndView.updateViewAndDrawable(
interpolatedLayout,
parentLayout,
Expand All @@ -301,6 +310,8 @@ private void updateLayout() {
mEndView.setOutlineSpotShadowColor(Color.argb(endAlpha, 0, 0, 0));
}
}
} else {
mEndView.reset();
}

// Fire events
Expand All @@ -316,9 +327,9 @@ private void updateLayout() {

private void updateNodeVisibility() {
for (RNSharedElementTransitionItem item : mItems) {
boolean hidden = mInitialLayoutPassCompleted &&
(item.getStyle() != null) &&
(item.getContent() != null);
boolean hidden = mInitialLayoutPassCompleted
&& (item.getStyle() != null)
&& (item.getContent() != null);
if (hidden && (mAnimation == RNSharedElementAnimation.FADE_IN) && item.getName().equals("start")) hidden = false;
if (hidden && (mAnimation == RNSharedElementAnimation.FADE_OUT) && item.getName().equals("end")) hidden = false;
item.setHidden(hidden);
Expand Down
Expand Up @@ -24,6 +24,10 @@ public boolean hasOverlappingRendering() {
return mViewType == RNSharedElementDrawable.ViewType.GENERIC;
}

void reset() {
setAlpha(0.0f);
}

void updateViewAndDrawable(
Rect layout,
Rect parentLayout,
Expand Down

0 comments on commit 92a999c

Please sign in to comment.