Comments (3)
ConstraintSets are not designed for frame by frame apply.
ConstraintLayout is a linear equation solver. It will be slow if you update every frame managing 28 widgets.
If you are changing visibility frequently (especially to Gone).
Reactive frameworks like compose work by doing a diff on your update.
ConstraintSet it not built that way. (And to some extent ConstraintLayout could be slow to)
You could reduce your change by using ConstraintProperties which are per view.
from constraintlayout.
I need a little more details:
I am not sure ConstraintSet.VISIBILITY_MODE_IGNORE is relevant to ConstraintLayout
What are you hoping to achieve by setting it?
Why are you maintaining the ConstraintSet?
Why
if (isFirstRender) {
constraintSet.setVisibility(view.id, View.GONE)
} else {
view.visibility = View.GONE
}
Not
constraintSet.setVisibility(view.id, View.GONE)
view.visibility = View.GONE
?
from constraintlayout.
Yep, i didin't mention that during init i setting up relations between generated views. e.g.
constraintSet.connect(labelId, ConstraintSet.START, inputId, ConstraintSet.START)
Overall overview:
There is a virtualFlow with couple inputs in a chain, each of input has "connected" label and error TextViews.
UI is driven by state: LiveData + monolith state of whole screen which renders on every change. Current View Framework doesn't friendly for such approach so there is a lot of optimisations inside my observe function aka "render state". For example, i can "calculate diff" between old and new states and update only small part of my view tree, e.g. one input + connected label and error.
So render state will looks like:
val itemToUpdate = magicDiffAlrgorithm(state)
if (itemToUpdate.isVisible) {
view.visibility = View.VISIBLE
} else {
view.visibility = View.GONE
}
...
view.text = itemToUpdate.title
// and so on
In this case view.visibility = View.GONE will works fast, while constraintSet.setVisibility(view.id, View.GONE) breaks this idea due to nature of constraintSet.applyTo(..). I can't use it for frequent changes cuz it leads to performance issues.
P.S. issue partially solved by checks on false-positive updates e.g.
fun View.show(): View {
if (visibility == View.VISIBLE) return
visibility = View.VISIBLE
} // or similar via ConstraintSet.getVisibility(int viewId)
But it doesn't helps if you realy need to change visibility frequintly. The worst part is that i forced to use both approaches: ConstraintSet for first frame draw and eficient for rest ones.MVI
P.S. i chose such architecture with manual diffing to more seamless migration to compose wihtout diving in heavy frameworks like MVICore or Litho
from constraintlayout.
Related Issues (20)
- MotionLayout OnSwipe only animated after first ACTION_UP HOT 2
- topMargin is abnormal HOT 8
- In Android8.1 (27), the round setting is too large, and the ImageFilterView cannot be displayed HOT 2
- Comprehensive guide/documentation for swing constraintlayout HOT 2
- Carousel changes views randomly if used inside a RecyclerView HOT 1
- setDragScale method in OnSwipe only accepts integer values
- [Compose] Multiple transitions onSwipe HOT 4
- [Compose] Layout not behaving as expected when using Dimension.fillToConstraints.atLeastWrapContent HOT 5
- I think this is definitely a bug HOT 6
- ConstraintLayoutReference.id is internal in alpha version
- MotionLayout produces incorrect animation
- Setting match_parent in a child causes display and stability problems in its descendant views
- Jetpack Compose Constraint Layout. Constraint in preview are shifted
- [Compose] MotionLayout cannot animate the circle angle and distance together HOT 2
- MotionLayout bug with Recyclerview ( setTransition programmatically and back, Recyclerview Scroll did not attach to MotionLayout OnSwipe )
- onSwipe not work when sub composable item with clickable Modifier
- Layer can't work with MotionLayout!
- MotionCompose Not Working with RememberSaveable
- App crashes when trying to animate fontSize in MotionScene for Compose
- ConstriantLayout Landscape stretching
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 constraintlayout.