Comments (3)
A bit more information after playing with, the crash only occurs when you perform the animation and try to scroll the list, from outside the cell you played the animation from, but not every time.
Example :
Animation on Item2 + Scroll the list with a touch from the item 2 = OK
Animation on Item4 + Scroll the list with a touch from the item 6 = Crash
from motionlayoutplayground.
I found your question on stackOverflow: https://stackoverflow.com/questions/59104740/using-motionlayout-onswipe-on-item-of-a-recyclerview
The answer from Samuel Grogan works for me. Here is the kotlin version that make null checks for MotionTracker functions:
`package com.piotrprus.motionlayoutplayground.helper
import android.content.Context
import android.util.AttributeSet
import android.view.MotionEvent
import android.view.VelocityTracker
import androidx.constraintlayout.motion.widget.MotionLayout
class CustomMotionLayout : MotionLayout {
constructor(context: Context?) : super(context)
constructor(context: Context?, attrs: AttributeSet?) : super(
context,
attrs
)
constructor(
context: Context?,
attrs: AttributeSet?,
defStyleAttr: Int
) : super(context, attrs, defStyleAttr)
override fun obtainVelocityTracker(): MotionTracker {
return MyTracker.obtain()
}
/**
* The only functional changes to this class are added null-checks and recursion avoidance in
*
* @see MyTracker.getYVelocity
*/
private class MyTracker private constructor() : MotionTracker {
var tracker: VelocityTracker? = null
override fun recycle() {
tracker?.let {
recycle()
tracker = null
}
}
override fun clear() {
tracker?.clear()
}
override fun addMovement(event: MotionEvent) {
tracker?.addMovement(event)
}
override fun computeCurrentVelocity(units: Int) {
tracker?.computeCurrentVelocity(units)
}
override fun computeCurrentVelocity(
units: Int,
maxVelocity: Float
) {
tracker?.computeCurrentVelocity(units, maxVelocity)
}
override fun getXVelocity(): Float {
return tracker?.xVelocity ?: 0f
}
override fun getYVelocity(): Float {
return tracker?.yVelocity ?: 0f
}
override fun getXVelocity(id: Int): Float {
return tracker?.getXVelocity(id) ?: 0f
}
override fun getYVelocity(id: Int): Float {
return tracker?.getYVelocity(id) ?: 0f
}
companion object {
private val me =
MyTracker()
fun obtain(): MyTracker {
me.tracker =
VelocityTracker.obtain()
return me
}
}
}
}`
from motionlayoutplayground.
@BBorombo Merged in PR number 4, currently on master. PLease test it out ;)
from motionlayoutplayground.
Related Issues (1)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from motionlayoutplayground.