-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28469 from hurali97/perf/refactor-heavy-operation…
…s-for-draft perf: refactor heavy operations when user starts to type
- Loading branch information
Showing
9 changed files
with
82 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,38 @@ | ||
import {InteractionManager} from 'react-native'; | ||
import Onyx from 'react-native-onyx'; | ||
import _ from 'underscore'; | ||
import * as ReportUtils from '@libs/ReportUtils'; | ||
import CONST from '@src/CONST'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import updateUnread from './updateUnread/index'; | ||
|
||
let previousUnreadCount = 0; | ||
|
||
Onyx.connect({ | ||
key: ONYXKEYS.COLLECTION.REPORT, | ||
waitForCollectionCallback: true, | ||
callback: (reportsFromOnyx) => { | ||
const unreadReports = _.filter(reportsFromOnyx, (report) => ReportUtils.isUnread(report) && report.notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN); | ||
updateUnread(_.size(unreadReports)); | ||
if (!reportsFromOnyx) { | ||
return; | ||
} | ||
|
||
/** | ||
* We need to wait until after interactions have finished to update the unread count because otherwise | ||
* the unread count will be updated while the interactions/animations are in progress and we don't want | ||
* to put more work on the main thread. | ||
* | ||
* For eg. On web we are manipulating DOM and it makes it a better candidate to wait until after interactions | ||
* have finished. | ||
* | ||
* More info: https://reactnative.dev/docs/interactionmanager | ||
*/ | ||
InteractionManager.runAfterInteractions(() => { | ||
const unreadReports = _.filter(reportsFromOnyx, (report) => ReportUtils.isUnread(report) && report.notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN); | ||
const unreadReportsCount = _.size(unreadReports); | ||
if (previousUnreadCount !== unreadReportsCount) { | ||
previousUnreadCount = unreadReportsCount; | ||
updateUnread(unreadReportsCount); | ||
} | ||
}); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters