question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bug: iOS back transitions between <ion-tabs> pages not animating

See original GitHub issue

Bug Report

Ionic version:

[x] 4.3.1

Current behavior:

Demo app confirgured with { mode: ‘ios’ } and has 2 <ion-tabs> pages. Navigating forward from Tabs A to Tabs B pages animates as expected. Navigating back from Tabs B to Tabs A does not animate. Removing the { mode: ‘ios’ } config line shows Android style animations working correctly forwards and back.

Expected behavior:

Navigating back from Tabs B to Tabs A page should animate.

Steps to reproduce:

  • Create a new app
  • Change app.module to run in iOS mode
  • Create 2 <ion-tabs> pages, and navigate forward and back between each one

Related code:

Basic demo is available at: https://github.com/benmarsh/ionic-multi-tabs-test

Other information:

Ionic info:

Ionic:

   ionic (Ionic CLI)             : 4.12.0 (/usr/local/lib/node_modules/ionic)
   Ionic Framework               : @ionic/angular 4.3.1
   @angular-devkit/build-angular : 0.13.8
   @angular-devkit/schematics    : 7.3.8
   @angular/cli                  : 7.3.8
   @ionic/angular-toolkit        : 1.5.1

System:

   NodeJS : v11.12.0 (/usr/local/Cellar/node/11.12.0/bin/node)
   npm    : 6.7.0
   OS     : macOS Mojave

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:8
  • Comments:26 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
tobiasbambulliscommented, Apr 2, 2020

@gggiiia: i found a solution for ionic5.

include this in app.module.ts:

IonicModule.forRoot({ 
  navAnimation: fixAnimation
}),

and this in a new file:

import { Animation, NavOptions, createAnimation } from '@ionic/core';

const DURATION = 500;
const EASING = 'cubic-bezier(0.36,0.66,0.04,1)';

export function fixAnimation(_: HTMLElement, navEl: TransitionOptions): Animation {
	
	let transitionElement: any = navEl;

    const enteringEl = transitionElement.enteringEl;
    const leavingEl = transitionElement.leavingEl;

	const backDirection = (transitionElement.direction === 'back');
	const rootTransition: Animation = createAnimation('')
	if(!backDirection) {

		const squareA: Animation = createAnimation('')
			.addElement(enteringEl)
			.duration(transitionElement.duration || DURATION)
			.easing(EASING)
			.beforeStyles({ 'opacity': 1 })
            .fromTo('transform', 'translateX(99.5%)', 'translateX(0%)');

		const squareB: Animation = createAnimation('')
			.addElement(leavingEl)
			.duration(transitionElement.duration || DURATION)
			.easing(EASING)
            .fromTo('transform', 'translateX(0%)', 'translateX(-20%)')
			.fromTo('opacity', '1', '0.8')

		rootTransition.addAnimation([squareA, squareB]);
	}
	else {

		const squareA: Animation = createAnimation('')
			.addElement(leavingEl)
			.duration(transitionElement.duration || DURATION)
			.easing(transitionElement.easing || EASING)
            .fromTo('transform', 'translateX(0%)', 'translateX(99.5%)');


		const squareB: Animation = createAnimation('')
			.addElement(enteringEl)
			.duration(transitionElement.duration || DURATION)
			.easing(transitionElement.easing || EASING)
			.fromTo('opacity', '0.8', '1')
            .fromTo('transform', 'translateX(-20%)', 'translateX(0%)');

		rootTransition.addAnimation([squareA, squareB]);

	}

    return rootTransition;

};

export interface TransitionOptions extends NavOptions {
  progressCallback?: ((ani: Animation | undefined) => void);
  baseEl: any;
  enteringEl: HTMLElement;
  leavingEl: HTMLElement | undefined;
}

export const getIonPageElement = (element: HTMLElement) => {
  if (element.classList.contains('ion-page')) {
    return element;
  }

  const ionPage = element.querySelector(':scope > .ion-page, :scope > ion-nav, :scope > ion-tabs');
  if (ionPage) {
    return ionPage;
  }
  // idk, return the original element so at least something animates and we don't have a null pointer
  return element;
};
5reactions
benmarshcommented, Oct 9, 2019

@lincolnthree Check out https://gist.github.com/benmarsh/6401a4c58a4b48e305c217c6552c182e for the simplified version of the transition. It’s based on the included Ionic transition and I’ve left in the commented out code so you can see what has been removed. I’ve not had any animation problems with using this reduced down version. Add { navAnimation: simpleTransitionAnimation } to the app config to override the default (https://ionicframework.com/docs/utilities/config)

Read more comments on GitHub >

github_iconTop Results From Across the Web

bug: iOS back transitions between <ion-tabs> pages ... - GitHub
Demo app confirgured with { mode: 'ios' } and has 2 <ion-tabs> pages. Navigating forward from Tabs A to Tabs B pages animates...
Read more >
Ionic Back Button not displaying in TAB Page and animation is ...
I have a problem with displaying back button and smooth transition into tabbed page after button click from main menu of the app....
Read more >
How to animate between states that are not nested? - ionic-v1
I need to animate between 2 states that are not nested under each ... how <ion-tabs> transitions to and from pages that aren't...
Read more >
Ionic 5 Animations Controller & Custom Page Transitions
Let's explore the Ionic 5 Animations API to animate simple objects and even build custom page transitions ! Learn Ionic faster with...
Read more >
Ionic App Navigation with Login, Guards & Tabs Area
So if needed, we directly transition to the introduction without even showing the login page. That means, no flash of a page you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found