Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Help] Cupertino-pane & ion-fab buttons #30

Closed
Andranik0 opened this issue May 13, 2020 · 4 comments
Closed

[Help] Cupertino-pane & ion-fab buttons #30

Andranik0 opened this issue May 13, 2020 · 4 comments
Assignees
Labels
feature New feature or request question Further information is requested

Comments

@Andranik0
Copy link

Hi @roman-rr,

I would like to add an ion-fab button (https://ionicframework.com/docs/api/fab) at the bottom of my Ionic application, but right above the cupertino-pane division, in order to let this button dynamically follow the pane's moves.

→ Is there a simple way to do so?

HTML

<ion-content>
 <ion-fab horizontal="end">
    <ion-fab-button>
      <ion-icon name="add"></ion-icon>
    </ion-fab-button>
  </ion-fab>

  <div class="cupertino-pane">
    <h1>Header</h1>
    <p>Content</p>
  </div>
</ion-content>

CSS

.cupertino-pane{
    margin: 20px;
}

TS

  ngOnInit() {
    this.drawer = new CupertinoPane('.cupertino-pane', {
      onDrag: () => console.log('Drag event')
    });

    this.drawer.present();
  }

2020-05-13_20h24_23

Thanks in advance for your help!

Andra

@roman-rr roman-rr self-assigned this May 14, 2020
@roman-rr roman-rr added feature New feature or request question Further information is requested labels May 14, 2020
@roman-rr
Copy link
Collaborator

roman-rr commented May 16, 2020

@Andranik0

In this example ion-fab following pane onDrag events.
You can complete behavior for other events with similar way.
Feel free to ask if you stuck on some moment.

<ion-content [fullscreen]="true">
  <ion-fab horizontal="end" vertical="bottom" id="fab-button">
    <ion-fab-button>
      <ion-icon name="add"></ion-icon>
    </ion-fab-button>
  </ion-fab>

  <div class="cupertino-pane">
    <h1>Header</h1>
    <p>Content</p>
  </div>
</ion-content>
  public drawer: CupertinoPane;
  public fabButton: HTMLElement;
  constructor() {}

  ngOnInit() {
    this.fabButton = document.getElementById('fab-button');

    this.drawer = new CupertinoPane('.cupertino-pane', {
      onDrag: (ev) => {
        this.fabButton.style.bottom = `${window.innerHeight}px`;
        this.fabButton.style.transform = `translateY(${this.getPaneTransformY}px)`;
      }
    });
    this.drawer.present();
  }

  get getPaneTransformY():number {
    const translateYRegex = /\.*translateY\((.*)px\)/i;
    return parseFloat(translateYRegex.exec((<any>document.querySelector('.pane')).style.transform)[1]);
  }

@Andranik0
Copy link
Author

Hi @roman-rr,

Thanks for your answer.

Unfortunately, it seems it does not fully take into account the elasticity/bounce property of the pane's moves, and thus leads to unexpected behaviors at the end of the drag.

Could it be possible to directly integrate the fabButton to the pane component in order to display it right above the "draggable" section (to get something similar to the already existing "close button" but outside the pane)? Or maybe fix the behavior described above regarding the use of onDrag?

Some screenshots to let you understand my issue:
2020-05-17_11h11_01
(works while we drag: "bottom" of the fabButton is properly set)

2020-05-17_11h11_17
2020-05-17_11h11_22
(does not work once we stop dragging: "bottom" of the fabButton is set at the drag end and does not follow the animation / the pane's rebound)

TS code:

  drawer: CupertinoPane;
  fabButton: HTMLElement;

  constructor() {}

  ngOnInit() {
    this.fabButton = document.getElementById('fab-button');
    this.drawer = new CupertinoPane('.cuper', {
      onDrag: (ev) => {
        this.fabButton.style.bottom = `${window.innerHeight}px`;
        this.fabButton.style.transform = `translateY(${this.getPaneTransformY}px)`;
      },
      buttonClose: false,
      initialBreak: 'bottom',
      breaks: {
        top: { enabled: true, offset: 290 },
        middle: { enabled: false },
        bottom: { enabled: true, offset: 110 },
      },
    });

    this.drawer.present();
  }

  get getPaneTransformY(): number {
    const translateYRegex = /\.*translateY\((.*)px\)/i;
    return parseFloat(translateYRegex.exec((<any>document.querySelector('.pane')).style.transform)[1]);
  }

HTML code:

<ion-content [fullscreen]="true">
  <ion-fab id="fab-button" horizontal="end" vertical="bottom">
    <ion-fab-button size="small">
      <ion-icon name="add"></ion-icon>
    </ion-fab-button>
  </ion-fab>
  <div class="cuper">
    <h1>Header</h1>
    <p>Content</p>
  </div>
</ion-content>

Thanks a lot!

Andra

roman-rr added a commit that referenced this issue May 18, 2020
@roman-rr
Copy link
Collaborator

@Andranik0 Check out v.1.1.51
New property followerElement implemented.

Try it out:

  drawer: CupertinoPane;
  constructor() {}

  ngOnInit() {
    this.drawer = new CupertinoPane('.cuper', {
      followerElement: 'ion-fab',
      buttonClose: false,
      initialBreak: 'bottom',
      breaks: {
        top: { enabled: true, offset: 290 },
        middle: { enabled: false },
        bottom: { enabled: true, offset: 110 },
      },
    });

    this.drawer.present({animated: true});
  }
<ion-content [fullscreen]="true">
  <ion-fab horizontal="end" vertical="center">
    <ion-fab-button size="small">
      <ion-icon name="add"></ion-icon>
    </ion-fab-button>
  </ion-fab>

  <div class="cuper">
    <h1>Header</h1>
    <p>Content</p>
  </div>
</ion-content>

@Andranik0
Copy link
Author

Hi @roman-rr,

It works perfectly! Good job!

Thanks,

Andra

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants