Flip left and right animation is not working in ionic 2 - animation

I am working with ionic 2 application and facing the issue of flip animation.
I want to put a flip animation on ion-col (flip left and flip right), but the flip animation is not working sometimes.
I am referring the flip animation from below link-
Reference link - https://www.joshmorony.com/using-the-web-animations-api-in-ionic-2/
.html code
<ion-grid>
<ion-row>
<ion-col [#flip]="flipState" col-6
(swipe)="swipeEvent($event)">
</ion-col>
</ion-row>
</ion-grid>
.ts code
Set the animation first
animations: [
trigger('flip', [
state('flipped', style({
transform: 'rotateY(360deg)',
})),
transition('* => flipped', animate('500ms ease'))
]),
]
})
when swipeEvent method called
swipeEvent(ev) {
if ((ev.direction === 2 || ev.direction === 4)) {
this.flipState = 'flipped';
}
}

Try this one off of GitHub. This is the one I used as starting point
https://github.com/JesseSoldat/Flip-Card-Ionic-2.git

Related

How to only play animation while a sprite is moving in Phaser 3?

I'm creating a game in Phaser 3, using the matter physics, as I've done before. A problem I've never run into until now, however, involves animations and movement. I want my animation to only play while the player is moving, and stop when he stops moving, like a player would in a real game.
I've tried all sorts of do-while loops, using "animationcomplete" and without it. I've also tried having my animation on loop (repeat: -1) and having it set to only execute once.
I DO know that, .isDown tracks the key and does the following code as long as it as pressed, versus .JustDown only executing it once. I'm not really sure which to use there either.
Code for animation
//Animations
//Running right animation
var runRightFrameNames = this.anims.generateFrameNames('sheet', {
start: 14,
end: 16,
zeroPad: 4,
prefix: 'run_right/'
})
this.anims.create({
key: 'runRight',
frames: runRightFrameNames,
frameRate: 1,
repeat: 0
})
Current code inside update() function, not the only thing I've tried
//If the right arrowkey is pressed
if (this.arrowKeys.right.isDown) {
//Move player
this.hero.setVelocityX(5);
//Play animation
this.hero.anims.play('runRight');
//When animation is done, stop hero
this.hero.on("animationcomplete", () => {
this.hero.setVelocityX(0);
});
}
You can modify your code snippet like this:
//If the right arrowkey is pressed
if (this.arrowKeys.right._justDown) {
console.log('Cursor right is pressed!');
//Move player
this.hero.setVelocityX(5);
//Play animation
this.hero.anims.play('runRight');
} else if (this.arrowKeys.right._justUp) {
console.log('Cursor right is NOT pressed!');
}
EDIT:
To fix the hero's animation change this line this.hero.anims.play('runRight'); to this.hero.anims.play('runRight', true);
You should also change the repeat value to -1 like so:
this.anims.create({
key: 'runRight', frames: runRightFrameNames, frameRate: 6, repeat: -1
});

Animate a property back and forth (without jumping to the end)

I am using the following code to "zoom" a page in and out.
const doEffect = args => {
const screen = args.object.page.getViewById('mainScreen')
screen.animate({
scale: {
x: isSettingsShown ? 1 : .75,
y: isSettingsShown ? 1 : .75
},
duration: 2000
})
isSettingsShown = !isSettingsShown
}
There is a toggle button on the page that updates the isSettingsShown variable. However when I toggle the var before the animation has ended, it "jumps" to the end of the animation. Can I prevent this from happening? I would like to start the animation from the last position it was at.
Pausing the animation or retaining the state of animation is still an open feature request at the moment.
You may still be able to do this natively by operating on the nativeView's CALayer (iOS) / Animator (Android).

angular 2 animation is not working as expected

I am using angular 2 rc6 and I would like to have page transitions based on the route path. I am applying the following animation on two paths (as a test). I just want to animate the opacity and nothing else. But no matter what I do, I am unable to stop the page from translating on Y axis. The only option that I found which seemed to work is using style.position: absolute for host. I don't want to use that as that screws the position of all the elements on the page. I have also tried having just opactiy without the transform. That didn't work either.
host: {
'[#routeAnimation]': 'true',
'[style.display]': "'block'"
},
animations: [
trigger('routeAnimation', [
transition('void => *', [
style({opacity: 0, transform: 'translatey(0)'}),
animate('0.2s')
]),
transition('* => void', [
animate('0.2s', style({opacity: 0, transform: 'translatey(0)'}))
])
])
]
I am sure i am missing something here. not quite sure what? Thanks for the help.
1) As you can see you spelled transteY incorrectly the value of transform X or Y.
style({opacity: 0, transform: 'translatey(0)'}),
Should be uppercase like so:
style({opacity: 0, transform: 'translateY(0)'}),
2) Another thing I see in your code is that you binded your animation selector like so: [#routeAnimation]': 'true' if you used this selector exactly like this on your html you could never turn it on by toggling a boolean for example, try using a boolean like isMovingY = 'false' and place it in the selector like so [#routeAnimation]': isMovingY now when you toggle it with a click for example it could activate the "enter" / "leave" states you declared in the animation.

Xamarin.Forms - Animating 2 Things at the Same Time (Push Animation)

I have a Xamarin forms page that contains an absolute layout that wraps everything. Inside that, I have content that fills the whole space and has left padding of 80, and then I have a left nav sidebar that is 80 wide and sits on top of the main content:
I want a sort of modified "push" animation, which means doing two things:
Increase the width of left nav by 100 (to 180)
TranslateX the main content by 100
(Note that using TranslateTo() would be super easy, but the left nav needs to increase in width, not shift to the right, and there's no WidthTo() method).
I can do #1 by itself just fine.
I can do #2 by itself just fine.
But I can't get them to both animate. If I run the left nav animation first (via .Commit()), only the main content animates. If I run the main content animation first, neither animates. Strange! What is going on here?
Here's the basic code I'm using:
var leftNavAnimation = new Animation(
callback: x => leftNav.WidthRequest = x,
start: 80,
end: 180,
easing: Easing.Linear
);
var mainContentAnimation = new Animation(
callback: x => mainContent.TranslationX = x,
start: 0,
end: 100,
easing: Easing.Linear
);
leftNavAnimation.Commit(this, "leftNavAnimationName", length: animationLength);
pageContentAnimation.Commit(this, "mainContentAnimationName", length: animationLength);
I figured out that the first parameter of .Commit() needs to refer to the element you're animating. So changing from:
mainContentAnimation.Commit(this, "mainContentAnimationName", length: animationLength);
To:
mainContentAnimation.Commit(mainContent, "mainContentAnimationName", length: animationLength);
Fixed it.

How to make an animation infinite loop using CoffeeScript in Framer.js?

I am trying to make a simple pulsing animation of a on-screen element in Framer.js and now it looks like this:
element.animate
properties: scale:1.3
element.on Events.AnimationEnd,->
this.scale = 1
locationUn.animate
properties: scale:1.3
basically when the screen is loaded, the element will be enlarged and upon end of the animation, it's forced back to scale 1 and run the animation again; but this solution is not elegant and animation seems very abrupt.
I am new to CoffeeScript...is there anyway to write a infinite loop to check on some condition like this?
checker = true
while(checker == true){
run animation
if(some events occurs){
checker = false
}
}
....
How to realize this in CoffeeScript?
You can create a looping pulse like this:
circle = new Layer()
circle.style.borderRadius = "100%"
circle.backgroundColor = "white"
circle.center()
outwards = new Animation({
layer: circle,
properties: {scale: 1.3},
curve: "ease-in-out"
})
inwards = outwards.reverse()
outwards.on(Events.AnimationEnd, inwards.start)
inwards.on(Events.AnimationEnd, outwards.start)
outwards.start()

Resources