Skip to content
This repository was archived by the owner on Feb 6, 2024. It is now read-only.

Commit 4c206a5

Browse files
feat: ios keyboard hack
1 parent 724c26a commit 4c206a5

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

studio/src/app/components/editor/slide/app-slide-preview/app-slide-preview.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
app-slide-preview {
44
position: absolute;
5+
top: var(--ios-top, 8px);
56
right: 8px;
67

78
transition: opacity 0.5s;

studio/src/app/components/editor/slide/app-slide-preview/app-slide-preview.tsx

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {Component, h, Host, Listen, State, Event, EventEmitter, Element, Prop} from '@stencil/core';
22

33
import {cleanContent} from '@deckdeckgo/deck-utils';
4-
import {debounce, isIPad} from '@deckdeckgo/utils';
4+
import {debounce, isIOS, isLandscape} from '@deckdeckgo/utils';
55

66
import {SlotUtils} from '../../../../utils/editor/slot.utils';
77

@@ -19,7 +19,7 @@ export class AppSlidePreview {
1919
private preview: boolean = false;
2020

2121
@State()
22-
private top: string = '8px';
22+
private iosPositionTop: string | undefined = undefined;
2323

2424
private deckPreviewRef!: HTMLDeckgoDeckElement;
2525

@@ -34,12 +34,7 @@ export class AppSlidePreview {
3434
}
3535

3636
@Listen('ionKeyboardDidShow', {target: 'window'})
37-
onKeyboardDidShow($event: CustomEvent<{keyboardHeight: number}>) {
38-
if (!isIPad()) {
39-
return;
40-
}
41-
this.top = `calc(100vh - ${$event.detail.keyboardHeight}px)`;
42-
}
37+
onKeyboardDidShow(_$event: CustomEvent<{keyboardHeight: number}>) {}
4338

4439
componentDidUpdate() {
4540
if (this.preview) {
@@ -67,6 +62,8 @@ export class AppSlidePreview {
6762

6863
const selectedElement: HTMLElement = $event.detail;
6964

65+
await this.stickyIOS(selectedElement);
66+
7067
this.preview =
7168
selectedElement?.parentElement?.nodeName?.toLowerCase().indexOf('deckgo-slide') >= 0 &&
7269
SlotUtils.isNodeEditable(selectedElement) &&
@@ -85,6 +82,12 @@ export class AppSlidePreview {
8582
}
8683
}
8784

85+
private async stickyIOS(selectedElement: HTMLElement) {
86+
if (isIOS()) {
87+
this.iosPositionTop = isLandscape() ? `calc(${selectedElement.offsetTop}px - (128px * 9 / 16) - 32px)` : undefined;
88+
}
89+
}
90+
8891
async initDeckPreview() {
8992
if (!this.deckRef) {
9093
return;
@@ -122,9 +125,11 @@ export class AppSlidePreview {
122125
}
123126

124127
render() {
128+
const style = {...(this.iosPositionTop && {'--ios-top': this.iosPositionTop})};
129+
125130
return (
126131
<Host
127-
style={{top: this.top}}
132+
style={style}
128133
class={{
129134
preview: this.preview,
130135
}}>

0 commit comments

Comments
 (0)