11import { Component , h , Host , Listen , State , Event , EventEmitter , Element , Prop } from '@stencil/core' ;
22
33import { cleanContent } from '@deckdeckgo/deck-utils' ;
4- import { debounce , isIPad } from '@deckdeckgo/utils' ;
4+ import { debounce , isIOS , isLandscape } from '@deckdeckgo/utils' ;
55
66import { 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