ionic 3角4动画不工作。

时间:2022-05-12 19:50:13

I have a component where I am trying to animate an accordion list.. I have made all the changes such as including import { BrowserModule } from "@angular/platform-browser"; and import { BrowserAnimationsModule } from "@angular/platform-browser/animations"; as well importing both module in imports

我有一个组件,在那里我想要动画一个手风琴列表。我已经做了所有的更改,包括从“@角度/平台浏览器”导入{BrowserModule};从“@角度/平台浏览器/动画”导入{BrowserAnimationsModule};同时导入两个模块的导入。

the following piece of code used to work in ionic 2 angular 2 but now, it does not throw any error or what so ever , it just does not animate and the item is not hidden at all (meaning height does not go to 0`)

下面这段代码用于ionic 2角2,但是现在,它不会抛出任何错误,它只是没有动画,而且这个项目也没有隐藏(意思是高度不等于0)

.ts

.ts

@Component({
  selector: 'page-test-comp',
  templateUrl: 'test-comp.html',
  styles:[
       `
       .item-block{
       min-height: 0;
       transition: 0.09s all linear;
      }
      `
  ],
  animations: [
    trigger('expand', [
      state('true', style({ height: '*'})),
      state('false', style({ height: '0'})),
      transition('void => *', animate('0s')),
      transition('* <=> *', animate('250ms ease-in-out'))
    ])
  ]
})

export class TestComp {
 activeGroup= false;

 constructor(public navCtrl: NavController) {}

 toggleGroup(){
   this.activeGroup = !this.activeGroup;
 }
}

.html

. html

<ion-content>
 <ion-item-group>
  <ion-item-divider color="light" (click)="toggleGroup()">
    Job Summary
   <ion-icon style="padding-right: 10px;"  item-right name="ios-arrow-up" *ngIf="!activeGroup"></ion-icon>
   <ion-icon style="padding-right: 10px;"  item-right name="ios-arrow-down" *ngIf="activeGroup"></ion-icon>
  </ion-item-divider>

  <ion-item no-lines [@expand]="activeGroup">
    <p>
      hello world
    </p>
  </ion-item>

 </ion-item-group>
</ion-content>

I also included web-animations because it seems that animations does not work on IOS from what I read , I also read that void does not work in ionic3 but some people say differently

我还包括了网络动画,因为看起来动画在IOS中不像我所读的那样,我也读到,void在ionic3中不起作用,但有些人说的不同。

1 个解决方案

#1


2  

Ok after many hours of headache and failure I made a better one

好几个小时的头痛和失败后,我做了一个更好的。

.ts

.ts

@Component({
  selector: "page-job-details",
  templateUrl: "job-details.html",
  animations: [
    trigger('expand', [
      state('ActiveGroup', style({opacity: '1', height: '*'})),
      state('NotActiveGroup', style({opacity: '0', height: '0', overflow: 'hidden'})),
      transition('ActiveGroup <=> NotActiveGroup', animate('300ms ease-in-out'))
    ])
  ]
})

ionViewDidLoad() {
  this.items = [
    {title: 'First Button', data: 'First-content', activeGroup: 'NotActiveGroup'},
    {title: 'Second Button', data: 'Second-content', activeGroup: 'NotActiveGroup'},
    {title: 'Third Button', data: 'Third-content', activeGroup: 'NotActiveGroup'}
  ];
}

expandItem(item){

  this.items.map(listItem => {
    if (item == listItem){
      listItem.activeGroup = listItem.activeGroup === 'ActiveGroup' ? 'NotActiveGroup' : 'ActiveGroup';
    }
    return listItem;
  });
}

.html

. html

<ion-content>
  <ion-item-group *ngFor="let item of items">
    <button ion-item no-lines (tap)="expandItem(item)">
     <ion-icon item-right name="ios-arrow-down" *ngIf="item.activeGroup === 'NotActiveGroup'"></ion-icon>
     <ion-icon item-right name="ios-arrow-up" *ngIf="item.activeGroup === 'ActiveGroup'"></ion-icon>    
    {{item.title}}
   </button>

   <div [@expand]="item.activeGroup"> 
     <div>   
      {{item.data}}
     </div>   
   </div> 
 </ion-item-group>
</ion-content>

#1


2  

Ok after many hours of headache and failure I made a better one

好几个小时的头痛和失败后,我做了一个更好的。

.ts

.ts

@Component({
  selector: "page-job-details",
  templateUrl: "job-details.html",
  animations: [
    trigger('expand', [
      state('ActiveGroup', style({opacity: '1', height: '*'})),
      state('NotActiveGroup', style({opacity: '0', height: '0', overflow: 'hidden'})),
      transition('ActiveGroup <=> NotActiveGroup', animate('300ms ease-in-out'))
    ])
  ]
})

ionViewDidLoad() {
  this.items = [
    {title: 'First Button', data: 'First-content', activeGroup: 'NotActiveGroup'},
    {title: 'Second Button', data: 'Second-content', activeGroup: 'NotActiveGroup'},
    {title: 'Third Button', data: 'Third-content', activeGroup: 'NotActiveGroup'}
  ];
}

expandItem(item){

  this.items.map(listItem => {
    if (item == listItem){
      listItem.activeGroup = listItem.activeGroup === 'ActiveGroup' ? 'NotActiveGroup' : 'ActiveGroup';
    }
    return listItem;
  });
}

.html

. html

<ion-content>
  <ion-item-group *ngFor="let item of items">
    <button ion-item no-lines (tap)="expandItem(item)">
     <ion-icon item-right name="ios-arrow-down" *ngIf="item.activeGroup === 'NotActiveGroup'"></ion-icon>
     <ion-icon item-right name="ios-arrow-up" *ngIf="item.activeGroup === 'ActiveGroup'"></ion-icon>    
    {{item.title}}
   </button>

   <div [@expand]="item.activeGroup"> 
     <div>   
      {{item.data}}
     </div>   
   </div> 
 </ion-item-group>
</ion-content>