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

Fixed: Chat header goes out of the view after opening keyboard #13801

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/libs/VisualViewport/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,22 @@ function addViewportResizeListener(onViewportResize) {
return () => window.visualViewport.removeEventListener('resize', onViewportResize);
}

export default addViewportResizeListener;
/**
* Add a visual viewport scroll listener if available. Return a function to remove the listener.
*
* @param {Function} onViewportScroll
* @returns {Function}
*/
function addViewportScrollListener(onViewportScroll) {
if (!window.visualViewport) {
return () => {};
}

window.visualViewport.addEventListener('scroll', onViewportScroll);
return () => window.visualViewport.removeEventListener('scroll', onViewportScroll);
}

export default {
addViewportResizeListener,
addViewportScrollListener,
};
15 changes: 13 additions & 2 deletions src/libs/VisualViewport/index.native.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/**
* Visual Viewport is not available on native, so return an empty function.
*
Expand All @@ -8,4 +7,16 @@ function addViewportResizeListener() {
return () => {};
}

export default addViewportResizeListener;
/**
* Visual Viewport is not available on native, so return an empty function.
*
* @returns {Function}
*/
function addViewportScrollListener() {
return () => {};
}

export default {
addViewportResizeListener,
addViewportScrollListener,
};
13 changes: 11 additions & 2 deletions src/pages/home/ReportScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import CONST from '../../CONST';
import ReportActionsSkeletonView from '../../components/ReportActionsSkeletonView';
import reportActionPropTypes from './report/reportActionPropTypes';
import toggleReportActionComposeView from '../../libs/toggleReportActionComposeView';
import addViewportResizeListener from '../../libs/VisualViewport';
import VisualViewport from '../../libs/VisualViewport';
import {withNetwork} from '../../components/OnyxProvider';
import compose from '../../libs/compose';
import networkPropTypes from '../../components/networkPropTypes';
Expand Down Expand Up @@ -111,6 +111,7 @@ class ReportScreen extends React.Component {
this.chatWithAccountManager = this.chatWithAccountManager.bind(this);
this.dismissBanner = this.dismissBanner.bind(this);
this.removeViewportResizeListener = () => {};
this.removeViewportScrollListener = () => {};

this.state = {
skeletonViewContainerHeight: reportActionsListViewHeight,
Expand All @@ -122,7 +123,14 @@ class ReportScreen extends React.Component {
componentDidMount() {
this.fetchReportIfNeeded();
toggleReportActionComposeView(true);
this.removeViewportResizeListener = addViewportResizeListener(this.updateViewportOffsetTop);

// In order to keep the header always at the top
// we add two events listeners to detect the change in the visual viewport and apply marginTop = offsetTop
// Usually the resize event would be enough however on Chrome the offsetTop is changed after resize i.e. on scroll
// More info: https://github.com/Expensify/App/issues/13491
this.removeViewportResizeListener = VisualViewport.addViewportResizeListener(this.updateViewportOffsetTop);
this.removeViewportScrollListener = VisualViewport.addViewportScrollListener(this.updateViewportOffsetTop);

Navigation.setIsReportScreenIsReady();
}

Expand All @@ -137,6 +145,7 @@ class ReportScreen extends React.Component {

componentWillUnmount() {
this.removeViewportResizeListener();
this.removeViewportScrollListener();
}

/**
Expand Down