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

Only bind a single Keyboard.addListener('keyboardDidShow') event #567

Merged
merged 1 commit into from
Sep 30, 2020
Merged
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
13 changes: 10 additions & 3 deletions src/page/home/report/ReportActionsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ class ReportActionsView extends React.Component {
}

componentDidMount() {
this.keyboardEvent = Keyboard.addListener('keyboardDidShow', this.scrollToListBottom);
if (this.props.isActiveReport) {
this.keyboardEvent = Keyboard.addListener('keyboardDidShow', this.scrollToListBottom);
}

fetchActions(this.props.reportID);
}

Expand All @@ -69,14 +72,18 @@ class ReportActionsView extends React.Component {
return;
}

// If we are switching from not active to active report then mark comments as read
// If we are switching from not active to active report then mark comments as
// read and bind the keyboard listener for this report
if (!prevProps.isActiveReport && this.props.isActiveReport) {
this.recordMaxAction();
this.keyboardEvent = Keyboard.addListener('keyboardDidShow', this.scrollToListBottom);
}
}

componentWillUnmount() {
this.keyboardEvent.remove();
if (this.keyboardEvent) {
this.keyboardEvent.remove();
}
}

/**
Expand Down
41 changes: 22 additions & 19 deletions src/page/home/sidebar/SidebarLinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ class SidebarLinks extends React.Component {
// Updates the page title to indicate there are unread reports
PageTitleUpdater(_.any(reports, report => report.isUnread));

// Update styles to hide the report links if they should not be visible
const sidebarLinksStyle = this.state.areReportLinksVisible
? [styles.sidebarListContainer]
: [styles.sidebarListContainer, styles.dNone];

return (
<View style={[styles.flex1, {marginTop: this.props.insets.top}]}>
<View style={[styles.sidebarHeader]}>
Expand All @@ -80,26 +85,24 @@ class SidebarLinks extends React.Component {
/>
</View>

{this.state.areReportLinksVisible && (
<View style={[styles.sidebarListContainer]}>
<View style={[styles.sidebarListItem]}>
<Text style={[styles.sidebarListHeader]}>
Chats
</Text>
</View>
{/* A report will not have a report name if it hasn't been fetched from the server yet */}
{/* so nothing is rendered */}
{_.map(reportsToDisplay, report => report.reportName && (
<SidebarLink
key={report.reportID}
reportID={report.reportID}
reportName={report.reportName}
isUnread={report.isUnread}
onLinkClick={onLinkClick}
/>
))}
<View style={sidebarLinksStyle}>
<View style={[styles.sidebarListItem]}>
<Text style={[styles.sidebarListHeader]}>
Chats
</Text>
</View>
)}
{/* A report will not have a report name if it hasn't been fetched from the server yet */}
{/* so nothing is rendered */}
{_.map(reportsToDisplay, report => report.reportName && (
<SidebarLink
key={report.reportID}
reportID={report.reportID}
reportName={report.reportName}
isUnread={report.isUnread}
onLinkClick={onLinkClick}
/>
))}
</View>
</View>
);
}
Expand Down