Git Product home page Git Product logo

Comments (5)

jafu888 avatar jafu888 commented on July 16, 2024

Could you provide more context?
Ideally a sample MotionScene and layout file.

from constraintlayout.

namanh11611 avatar namanh11611 commented on July 16, 2024

I think issue caused by I have custom motionInterpolator. When I remove it, Switch work fine.

<Transition
    motion:constraintSetEnd="@id/set_second"
    motion:constraintSetStart="@id/set_first"
    motion:motionInterpolator="cubic(0.34, 1.56, 0.64, 1)"
    motion:duration="300">
</Transition>

from constraintlayout.

jafu888 avatar jafu888 commented on July 16, 2024



Is this part of the starting constraint set or the ending constraint set?
What did you think would happen ?
You cannot animate between a true and a false.

from constraintlayout.

namanh11611 avatar namanh11611 commented on July 16, 2024

This is my scene file onboard_scene.xml:

<?xml version="1.0" encoding="utf-8"?>
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:motion="http://schemas.android.com/apk/res-auto">

    <ConstraintSet android:id="@+id/set_first" />

    <ConstraintSet android:id="@+id/set_second">
        <Constraint
            android:id="@id/switchDemo">
            <CustomAttribute
                motion:attributeName="checked"
                motion:customBoolean="true" />
        </Constraint>
    </ConstraintSet>
    
    <Transition
        motion:constraintSetEnd="@id/set_second"
        motion:constraintSetStart="@id/set_first"
        motion:motionInterpolator="cubic(0.34, 1.56, 0.64, 1)"
        motion:duration="300">
    </Transition>
    
</MotionScene>

This is my layout file onboard.xml:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.motion.widget.MotionLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/layoutOnboard"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layoutDescription="@xml/onboard_scene">
    
    <androidx.appcompat.widget.SwitchCompat
        android:id="@+id/switchDemo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
        
</androidx.constraintlayout.motion.widget.MotionLayout>

When animation start, switch change color first, then change state. You can run the code to observe.

from constraintlayout.

jafu888 avatar jafu888 commented on July 16, 2024

The behavior is a little different in 2.1. But I don't think it is what you expected.
You did not state how you triggered the transition.

In general for any bug state:

  1. What you did (sample code)
  2. What you expected.
  3. What happened.

Several issue with your code.

  1. You are not triggering the transition.
  2. Typically you have a CustomAttribute at the start and the end constraint set.
  3. You seem to expect something to happen at the start?

Generally the way MotionLayout works a transition has 3 phases:

  1. The starting constraintSet is applied (Progress = 0.0)
  2. Any floating/integer variables that are different between the start and end are repeatedly applied. (Progress = 0.0-1.0)
  3. The ending constraintSet is applied (Progress =1.0)

from constraintlayout.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.