项目作者: WhatsThatItsPat

项目描述 :
Directive for Ionic 2 to cause headers to shrink & reveal, in parallactic fashion, based on user scrolling.
高级语言: TypeScript
项目地址: git://github.com/WhatsThatItsPat/ionic-shrinkage.git
创建时间: 2016-09-25T19:36:01Z
项目社区:https://github.com/WhatsThatItsPat/ionic-shrinkage

开源协议:ISC License

下载


ionic-shrinkage

ionic-shrinkage is a directive for Ionic 2 to cause headers to shrink & reveal, in parallactic fashion, based on user scrolling.

NOTE: This was built alongside Beta.11 of Ionic, and will be updated to Ionic 2.0 when it’s final (or perhaps the release candidates, but we’ll see).

I was in the pool

Installation

  1. npm install ionic-shrinkage --save

Usage Example

home.ts

  1. import { Component, ViewChild } from '@angular/core';
  2. import { Content } from 'ionic-angular';
  3. import { Shrinkage } from 'ionic-shrinkage';
  4. @Component({
  5. templateUrl: 'build/pages/home/home.html',
  6. directives: [ Shrinkage ]
  7. })
  8. export class HomePage {
  9. // We bind content to the shrinkage attribute in the HTML template
  10. @ViewChild(Content) content: Content;
  11. // Necessary for the change() method below
  12. @ViewChild(Shrinkage) shrinkage;
  13. constructor() {}
  14. // If you use Structural Directives to add or remove items in the header,
  15. // you'll have to call resize() on both content and the shrinkage directive.
  16. change(e) {
  17. this.content.resize();
  18. this.shrinkage.resize();
  19. }
  20. }

home.html

  1. <ion-header [shrinkage]="content">
  2. <ion-navbar>
  3. <ion-title>I was in the pool!</ion-title>
  4. </ion-navbar>
  5. <!--Structural Directives need to be accounted for with the resize() method -->
  6. <ion-toolbar no-border-top *ngIf="showSearch">
  7. <ion-searchbar></ion-searchbar>
  8. </ion-toolbar>
  9. </ion-header>
  10. <!--Note the fullscreen attribute-->
  11. <ion-content class="home" fullscreen>
  12. <!--Enough content to scroll-->
  13. <ion-item>
  14. <ion-label>Search</ion-label>
  15. <!--change() will resize the content and header via the directive-->
  16. <ion-toggle [(ngModel)]="showSearch" (ionChange)="change()"></ion-toggle>
  17. </ion-item>
  18. </ion-content>

Requirements & Notes

  • WKWebView - With UIWebView, scroll events don’t continue firing after your finger has left the screen, and while scroll momentum is still in effect. This works in WKWebView.
  • Crosswalk - I looked at Android without Crosswalk for about 2 minutes and doubt I’ll spent more that that.
  • Windows? - I don’t know and haven’t tested it at all.

TODO

  1. Resize method.
  2. Improve performance or provide fallback animation / cancellation for older devices.
    • Shrinkage works like butter on an iPhone 6s, but is janky on iPhone 5 and Galaxy S3 (with Crosswalk). Though both of those devices are from 2012, and possibly not worth fussing about.
    • Perfomance advice and device testing are welcome.
  3. Hide footers & tabs.
  4. Consider independently hiding toolbars within a header.

Author

Patrick McDonald (Github / Twitter)

Licence

This project is licensed under the ISC license. See the LICENSE file for more info.