Comments (4)
You're onto something, but using shouldComponentUpdate
here is a breaking change and might lead to unintended bugs as child components might not be pure. We could perhaps introduce it in a major version bump. For the moment it's better to make your child components implement shouldComponentUpdate
/extend PureComponent
if they have heavy render()
functions.
from react-native-animatable.
I've decided that I don't want to implement this.
- It doesn't solve the propagation of updates/
render
when triggering an animation. - It's much better if this is up to the end user to decide where pure components makes sense.
from react-native-animatable.
the way i ended up making my animated component is simply with a forceUpdate
prop, which is compared in shouldComponentUpdate
to determine whether to render children. So basically I came to the same conclusions as you, but built first-class support for it into the solution. It does have its downsides (the main one being that it's basically a requirement to always provide a hash as the forceUpdate
prop), but I've found rendering on web using RNW just to be completely horrible compared to regular RN, so such things make a huge difference when animating and renderings happen at the same time.
from react-native-animatable.
for reference:
shouldComponentUpdate(nextProps, nextState) {
let shouldUpdate = true; //non-animation-related props changed (therefore we dont need to worry about rendering during animation, and should definitely update)
this.properties.forEach((prop) => {
if(this.props[prop] !== nextProps[prop]) {
shouldUpdate = false; //new props are related to animation, and therefore renderings should ideally be blocked
this.animate(this[prop], nextProps[prop], nextProps);
}
});
if(shouldUpdate === false) {
//allow calling code to specify that they should always update during animations (i.e. because nested children change at the same time)
if(this.props.updateOnAnimate) {
return true;
}
//allow calling code to provide a hash for efficient situation-specific comparison
if(nextProps.forceUpdate !== this.props.forceUpdate) {
return true;
}
return false;
}
return true;
}
from react-native-animatable.
Related Issues (20)
- Animation list supported by useNativeDriver
- Chaining two animations with a pause between, infinitely HOT 1
- Change anchor point for rotation animation?
- Slide animations not working on ios first time
- React Native Web support on new ejected create-react-app TypeScript project HOT 1
- Stop animating children.
- transition not working
- Animation repeating when I set something in useState hook HOT 1
- Suggestion: deprecate this library in favor of moti HOT 1
- onAnimationBegin and onAnimationEnd doesn't work. They are not fired HOT 1
- Cannot read property 'flushOperations' of null, js engine: hermes
- Cannot read property 'create' of undefined, js engine: hermes
- FadeIn issue on Android HOT 5
- Change the fadeIn to fadeOut once rendered
- Is this package still be maintained? HOT 2
- I am making application on RN facing issues...like HOT 2
- Incorrect ref type
- Slide down and push other elements HOT 1
- Slide Out animation broken on v1.4.0
- React Native TabView "Cannot read property 'setPage' of undefined" error on Android
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 react-native-animatable.