Animating to a specific color using ExtJS - animation

I need to animate something on a web page with the ExtJS 3.4 library loaded. The specification is to animate an element's color to red. As far as I can see from the Ext.Fx documentation this is not possible. Is there a workaround?
Alternatively, this chaining of effects:
info.fadeOut({ endOpacity: .25, duration: 2}).setStyle('color','#FF0000');
would be acceptable if the color change happened after the fadeOut ended, but there seems to be no way to specify a callback function.

Try animate method and color animation type:
info
.animate(
{
opacity: { to: .25 }
},
0.5,
null,
'easeOut',
'run'
)
.animate(
{
color: { to: '#FF0000' }
},
0.5,
null,
'easeOut',
'color'
);
Working sample: http://jsfiddle.net/yRGUw/

Related

Framer motion complex scroll animation

Hello everyone I'm trying to make a complex animation And I'm new to the framer motion so I need help if it's possible.
I'm trying to do this animation
all the animation will be revealed when scrolling but I don't Know How?
I tried this example but I think it will not take me any where example
So, Any clue please?
Thanks in advance.
i think useAnimationControls will help, but i think there is another better solution or another way, but any way i wish this help you here is the documentation, it says that it returns a promise (and also can be used in async function with await).
like the following code:
import { useAnimationControls, motion } from "framer-motion"
export default function App() {
let controls = useAnimationControls()
controls
.start({
opacity: 1,
backgroundColor: "red",
color: "white",
})
.then(() =>
controls.start({
color: "black",
backgroundColor: "lightgreen",
x: -100,
})
)
.then(() => {
controls.start({
opacity: 0,
x: 100,
})
})
return (
<>
<motion.div initial={{ opacity: 0 }} animate={controls}>
hi there
</motion.div>
</>
)
}
the above code will do these things below respectively:
will increase the opacity to 1 and change the color & bg color
then it will change color & bg color again and change the x position
then will decrease the opacity to 0 and x position too
here is another animation library that is simple and also may be useful to use named animejs, and also they have a friend and non-boaring documentation you can check it here

How to set background color of Phaser 3 Game during runtime?

I am new to Phaser 3 Framework , but have expertise in Angular/Ngrx.
Currently , I am creating a Custom Phaser 3 Game Editor using Angular/Ngrx. Need to modify background color of the Phaser 3 Game at run time.
In Phaser 2+ version ,
Below code set background color of the game ,
game.stage.backgroundColor = "#4488AA";
But how to set game background color in Phaser 3 irrespective of scene ?
Do we need to set via Camera like below?
this.cameras.main.setBackgroundColor(0xbababa)
Please guide me.
If you want the same background color regardless of the active scene, Phaser 3 has a backgroundColor property in the GameConfig object. You can see the documentation here and a working version here.
const config = {
type: Phaser.AUTO,
width: 600,
height: 700,
backgroundColor: '#4488aa',
scene: {...}
};
You also have the option of creating a transparent canvas for the game and using a div underneath it to change the background color. To do this, you'll use the transparent property of the GameConfig object. You'll also want to make sure you use the parent property as well with a corresponding <div id="gameContainer"></div> in the HTML to make it easier to grab and modify the color beneath the canvas.
const config = {
type: Phaser.AUTO,
width: 600,
height: 700,
parent: 'gameContainer',
transparent: true,
scene: {...}
};
Then, in the create method, you'll grab that parent item and modify the color:
create() {
var div = document.getElementById('gameContainer');
div.style.backgroundColor = "#4488AA";
}
You can see a working version here.

animated opacity and hiding the widget so its not clickable

I'm using AnimatedOpacity to hide a the navbar based on a scroll event. I'm specifically having trouble making it animate in and out well, while also making the widget not clickable.
In order to hide my widget and prevent it from being clicked, I conditionally rendering the my CustomNavBar() component or Container() based on the visible state. However, this cuts my animation abruptly when i fade out. It works fading in, however.
AnimatedOpacity(
opacity: _isVisible ? 1.0 : 0.0,
duration: Duration(milliseconds: 300),
child: _isVisible
? CustomNavBar()
: Container(),
)
This is expected, since the component literally is not existing when _isVisible is false. That kills the whole animation. How do I get around this?
Thanks
There may be other ways to do this but you could use two variables for opacity and visibility. Make use of the AnimatedWidget's onEnd callback to change visibility. Also, you may want to use the Visibility widget for this. It lets you even maintain the child's state if you want.
/// somewhere outside of build in a StatefulWidget
bool _isVisible = true;
bool _isOpaque = true;
/// within the build method
AnimatedOpacity(
opacity: _isOpaque ? 1.0 : 0.0,
onEnd: (){
if(!_isOpaque)
setState((){
_isVisible = false;
});
},
child: Visibility(
child: child,
visible: _isVisible,
),
);
//then in some method to toggle the state...
setState((){
if(!_isVisible){
_isVisible = true;
_isOpaque = true;
}
else{
_isOpaque = false;
}
})
Come to think of it, you also have AnimatedSwitcher which is a LOT easier to do this. I will leave the above code for reference to the onEnd callback. Also, if maintaining state in the child widget is important then the above code would be better suited since you have that option. If it's not important then switch-away.
AnimatedSwitcher(
child: _isVisible ? child : SizedBox.shrink(),
)
IgnorePointer(
child: AnimatedOpacity(
child: child,
opacity: visible ? 1.0 : 0.0,
duration: const Duration(milliseconds: 200),
),
ignoring: !visible,
)
This is working for me like a charm. Basically, it says "ignore hit testing while child is invisible.
I also had a case for AppBar's particular action which I wanted to show / hide with animated opacity. After realizing that Opacity widget leaves child clickable I ended up using AnimatedSwitcher for the action Widget:
AnimatedSwitcher(
duration: Duration(milliseconds: 500),
child: !_visible
? SizedBox()
: IconButton(
icon: ... // more of the related code
),
)
I purposely negate the condition to put the empty SizedBox() to the top for the readability as the main widget can take a lot of lines in the code.
You can use your CustomNavBar instead of my IconButton:
AnimatedSwitcher(
duration: Duration(milliseconds: 500),
child: !_visible
? SizedBox()
: CustomNavBar(
... // more of the related code
),
)

React Native: Creating an Animated View that slides directly with finger drag

Desired Effect:
I want to create a basic animation of a smooth sliding View (left or right) in sync with the drag pace of my finger.(e.g. sliding an off- canvas menu into and out of view)
Currently I'm using Animated.spring in a parent component that handles all gestures. Then I'm using transform,translateX in a child component to slide a View left or right.
For Example:
Root.js(Parent Component that handles gestures)
_handlePanResponderMove(e: Object, gestureState: Object) {
let dx = gestureState.moveX - this.state.swipeStart;
Animated.spring(
this.state.slideValue,
{
toValue: newValue,
velocity: gestureState.vx,
tension: 2,
friction: 8,
}).start();
}
Navigation.js(Child Component that slides)
render(){
<Animated.View style={[styles.navigation,{transform: [{translateX: this.props.slideValue}]}]}>
<View >
</View>
</Animated.View>
}
The Problem:
There is sticky/lagging behavior with animation instead of a smooth movement that paces the finger sliding guesture.
My reasoning so far:
From my limited Animation experience - Animated.spring, Animated.ease and Animated.timing don't really describe well the equally paced sliding movement I'm after - but I suppose I need to be using one of them to get optimized native performance
(otherwise I'd just use .setState(slideValue) and do some math with the current location of my finger to figure the position of the View.)
Question:
What would be the preferred way to describe this type of smooth sliding animation using the optimized React-Native Animated library?
What I've tried out:
1) Using Animated.timing and setting duration low and easing to linear(my best guess at what I should do)
Animated.timing(
this.state.navSlideValue,
{
toValue: newValue,
duration: 10,
easing: Easing.linear
}).start();
2) Moving up the tension on Animated.spring
Animated.spring(
this.state.navSlideValue,
{
toValue: newValue,
velocity: (gestureState.vx),
tension: 300,
friction: 30,
}).start();
The preset functions timing, spring are useful for running animations to a specified value with a given easing. If you want to tie an Animated value to an event, you can use Animated.event instead:
PanResponder.create({
// on each move event, set slideValue to gestureState.dx -- the
// first value `null` ignores the first `event` argument
onPanResponderMove: Animated.event([
null, {dx: this.state.slideValue}
])
// ...rest of your panResponder handlers
});

React Native: Triggering Animation on hide

I have an element controlling the rendering of a child element. (A TouchableHighlight that sets some state in its onPress.) In the child element's componentDidMount method I construct an Animated.spring and start it. This works for entry, but I need to do the same animation in reverse to exit (it's like a drawer). componentWillUnmount executes too quickly for Animated.spring to even start working.
How would I handle animating the child's exit?
I have implemented a FadeInOut component that will animate a component in or out when its isVisible property changes. I made it because I wanted to avoid explicitly handling the visibility state in the components that should enter/exit with an animation.
<FadeInOut isVisible={this.state.someBooleanProperty} style={styles.someStyle}>
<Text>Something...</Text>
</FadeInOut>
This implementation uses a delayed fade, because I use it for showing progress indicator, but you can change it to use any animation you want, or generalise it to accept the animation parameters as props:
'use strict';
import React from 'react-native';
const {
View,
Animated,
PropTypes
} = React;
export default React.createClass({
displayName: 'FadeInOut',
propTypes: {
isVisible: PropTypes.bool.isRequired,
children: PropTypes.node.isRequired,
style: View.propTypes.style
},
getInitialState() {
return {
view: this.props.children,
opacity: new Animated.Value(this.props.isVisible ? 1 : 0)
};
},
componentWillReceiveProps(nextProps) {
const isVisible = this.props.isVisible;
const shouldBeVisible = nextProps.isVisible;
if (isVisible && !shouldBeVisible) {
Animated.timing(this.state.opacity, {
toValue: 0,
delay: 500,
duration: 200
}).start(this.removeView);
}
if (!isVisible && shouldBeVisible) {
this.insertView();
Animated.timing(this.state.opacity, {
toValue: 1,
delay: 500,
duration: 200
}).start();
}
},
insertView() {
this.setState({
view: this.props.children
});
},
removeView() {
this.setState({
view: null
});
},
render() {
return (
<Animated.View
pointerEvents={this.props.isVisible ? 'auto' : 'none'}
style={[this.props.style, {opacity: this.state.opacity}]}>
{this.state.view}
</Animated.View>
);
}
});
I think you have the animation ownership inverted. If you move your animation logic to the parent that is opening and closing the child, the problem becomes much simpler. Rather than beginning the animation on componentDidMount, do it on the click of your TouchableHighlight in addition to, but independent of, whatever prop manipulations on the child you need to do.
Then when the user clicks to close, you can simply reverse the animation as per normal and you don't really even need to unload it. Also this would allow you to have a reusable drawer (the thing that slides up and down) and it's abstracted away from the content within it. So you can have a single drawer mechanism supporting multiple different types of content.

Resources