-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TW-334: Create ADR for sticky timestamp
- Loading branch information
Showing
2 changed files
with
49 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# 16. Sticky timestamp inside chat | ||
|
||
Date: 2024-02-07 | ||
|
||
## Status | ||
|
||
Accepted | ||
|
||
## Context | ||
|
||
We need to update timestamp stick to header of Chat screen | ||
|
||
## Decision | ||
|
||
- Using [inview_notifier_list](https://pub.dev/packages/inview_notifier_list) combine with `ScrollNotification` | ||
- Building a `ViewPort` is `InViewNotifierList` and item `InViewNotifierWidget` to wrap each message | ||
- Whenever a message scroll to `ViewPort` a callback will be called to update timestamp stick to header of Chat screen | ||
- The condition to receive the callback is `isInViewPortCondition` to the InViewNotifierList widget. | ||
This is the function that defines the area where the widgets overlap should be notified as currently in-view. | ||
|
||
```dart | ||
typedef bool IsInViewPortCondition( | ||
double deltaTop, | ||
double deltaBottom, | ||
double viewPortDimension, | ||
); | ||
``` | ||
|
||
- In this case, we will use `deltaTop` and `deltaBottom` to check if the message is in the view port or not. | ||
Because list is **reversed**, so we change `deltaTopReversed` and `deltaBottomReversed`. | ||
|
||
```dart | ||
bool isInViewPortCondition(deltaTopReversed, deltaBottomReversed, viewPortDimension) { | ||
final stickyTimestampHeight = stickyTimestampKey.globalPaintBoundsRect?.height ?? 0; | ||
return deltaTopReversed < viewPortDimension - stickyTimestampHeight && | ||
deltaBottomReversed > viewPortDimension - stickyTimestampHeight; | ||
} | ||
``` | ||
|
||
- When the message is in the viewport and new timestamp is different from the previous one, | ||
we will update the timestamp sticky to header of Chat screen. | ||
|
||
## Consequences | ||
|
||
- The timestamp will be updated when the message is in the viewport and new timestamp is different from the previous one. |
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