1
0
mirror of https://github.com/flarum/core.git synced 2025-01-29 04:28:09 +01:00

Use absolute positioning for the Composer on Safari (#2660)

This commit is contained in:
Sami Mazouz 2021-03-07 22:31:46 +01:00 committed by GitHub
parent 3aa118ab94
commit 91d5d9c176
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 1 deletions

View File

@ -16,6 +16,7 @@ import NotificationListState from './states/NotificationListState';
import GlobalSearchState from './states/GlobalSearchState';
import DiscussionListState from './states/DiscussionListState';
import ComposerState from './states/ComposerState';
import isSafariMobile from './utils/isSafariMobile';
export default class ForumApplication extends Application {
/**
@ -138,6 +139,12 @@ export default class ForumApplication extends Application {
m.redraw();
}
});
if (isSafariMobile()) {
$(() => {
$('.App').addClass('mobile-safari');
});
}
}
/**

View File

@ -265,7 +265,10 @@ export default class Composer extends Component {
this.animateHeightChange().then(() => this.focus());
if (app.screen() === 'phone') {
this.$().css('top', 0);
// On safari fixed position doesn't properly work on mobile,
// So we use absolute and set the top value.
// https://github.com/flarum/core/issues/2652
this.$().css('top', $('.App').is('.mobile-safari') ? $(window).scrollTop() : 0);
this.showBackdrop();
}
}

View File

@ -0,0 +1,13 @@
/**
* @see https://stackoverflow.com/a/31732310
*/
export default function isSafariMobile(): boolean {
return (
'ontouchstart' in window &&
navigator.vendor &&
navigator.vendor.includes('Apple') &&
navigator.userAgent &&
!navigator.userAgent.includes('CriOS') &&
!navigator.userAgent.includes('FxiOS')
);
}

View File

@ -120,6 +120,12 @@
max-height: 100%;
padding-top: @header-height-phone;
// Fixes a bug where fixed position doesn't properly work in Safari mobile
// https://github.com/flarum/core/issues/2652
.mobile-safari & {
position: absolute;
}
&:before {
content: " ";
.header-background();