Skip to content

Commit

Permalink
Use absolute positioning for the Composer on Safari (#2660)
Browse files Browse the repository at this point in the history
  • Loading branch information
SychO9 committed Mar 7, 2021
1 parent 3aa118a commit 91d5d9c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
7 changes: 7 additions & 0 deletions js/src/forum/ForumApplication.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand Down Expand Up @@ -138,6 +139,12 @@ export default class ForumApplication extends Application {
m.redraw();
}
});

if (isSafariMobile()) {
$(() => {
$('.App').addClass('mobile-safari');
});
}
}

/**
Expand Down
5 changes: 4 additions & 1 deletion js/src/forum/components/Composer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down
13 changes: 13 additions & 0 deletions js/src/forum/utils/isSafariMobile.ts
Original file line number Diff line number Diff line change
@@ -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')
);
}
6 changes: 6 additions & 0 deletions less/forum/Composer.less
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 91d5d9c

Please sign in to comment.