andkulikov / Transitions-Everywhere

Set of extra Transitions on top of Jetpack Transitions Library
Apache License 2.0
4.82k stars 487 forks source link

Issue with ChangeText() preventing the text from being changed #68

Closed droidluv closed 6 years ago

droidluv commented 7 years ago

My code is as I have given below, the issue is the animation happens properly but the text doesn't change, I found this weird behaviour today, and its weird because similar code in another part of my project works fine, so I did some digging and found out that the

outAnim.addListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        if (startText.equals(view.getText())) {
                            // Only set if it hasn't been changed since anim started
                            view.setText(endText);
                            if (view instanceof EditText) {
                                setSelection(((EditText) view), endSelectionStart,
                                        endSelectionEnd);
                            }
                        }
                        // restore opaque alpha and correct end color
                        view.setTextColor(endColor);
                    }
                });

in the library is not getting called for some reason, and the end text is never getting set, also your outAnim and inAnim onAnimationUpdate listeners are working fine, any suggestions on the reason why the onAnimationEnd listener is never called?

//Code in Activity TransitionManager.beginDelayedTransition(constraintLayout, new ChangeText().setChangeBehavior(ChangeText.CHANGE_BEHAVIOR_OUT_IN));//Commenting this line makes the update happen properly title.setText(title);

// My Container

<android.support.constraint.ConstraintLayout
    android:id="@+id/constraintLayout"
    android:layout_width="0dp"
    android:layout_height="50dp"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent">
    <ImageView
        android:id="@+id/btn_a"
        android:layout_width="50dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>

    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/home"
        android:textSize="16sp"
        app:layout_constraintRight_toLeftOf="@+id/btn_a"
        app:layout_constraintLeft_toRightOf="@+id/btn_b"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageView
        android:id="@+id/btn_b"
        android:layout_width="50dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>

</android.support.constraint.ConstraintLayout>
andkulikov commented 7 years ago

Hi. Unfortunately right now I don't have any ideas why it's happening. Maybe you can try to create new project to reproduce it and then share it with me? So with stable steps to reproduce I will be able to debug. Thanks

droidluv commented 7 years ago

Ok I'll try with a new project, but I myself am also a little confused why it is not working in that particular part of the code, its as I said the onAnimationEnd is never called ONLY THERE.. sigh

ggajews commented 6 years ago

Guys I run into the same issue. The problem is with comparison: startText.equals(view.getText()) It calls equals on startText which has String type with view.getText() which returns Charsequence and it fails even if text is the same. simply calling toString() solves the issue. startText.equals(view.getText().toString())

andkulikov commented 6 years ago

Hi @ggajews. But startText is CharSequence. And it saved to map by calling the same textview.getText() which returns CharSequence

ggajews commented 6 years ago

Sorry, you're right. The real issue was view.getText() was returning SpannableStringBuilder. Unfortunately I cannot reproduce it now :(.