@@ -24,10 +24,10 @@ import { toPx } from "../../../utils/units";
24
24
import MemberAvatar from "../avatars/MemberAvatar" ;
25
25
import { READ_AVATAR_SIZE } from "./ReadReceiptGroup" ;
26
26
27
- export interface IReadReceiptInfo {
27
+ // The top & right from the bounding client rect of each read receipt
28
+ export interface IReadReceiptPosition {
28
29
top ?: number ;
29
30
right ?: number ;
30
- parent ?: Element ;
31
31
}
32
32
33
33
interface IProps {
@@ -48,7 +48,7 @@ interface IProps {
48
48
suppressAnimation ?: boolean ;
49
49
50
50
// an opaque object for storing information about this user's RR in this room
51
- readReceiptInfo ?: IReadReceiptInfo ;
51
+ readReceiptPosition ?: IReadReceiptPosition ;
52
52
53
53
// A function which is used to check if the parent panel is being
54
54
// unmounted, to avoid unnecessary work. Should return true if we
@@ -90,7 +90,7 @@ export default class ReadReceiptMarker extends React.PureComponent<IProps, IStat
90
90
public componentWillUnmount ( ) : void {
91
91
// before we remove the rr, store its location in the map, so that if
92
92
// it reappears, it can be animated from the right place.
93
- const rrInfo = this . props . readReceiptInfo ;
93
+ const rrInfo = this . props . readReceiptPosition ;
94
94
if ( ! rrInfo ) {
95
95
return ;
96
96
}
@@ -121,63 +121,39 @@ export default class ReadReceiptMarker extends React.PureComponent<IProps, IStat
121
121
}
122
122
}
123
123
124
- private buildReadReceiptInfo ( target : IReadReceiptInfo = { } ) : IReadReceiptInfo {
124
+ private buildReadReceiptInfo ( target : IReadReceiptPosition = { } ) : IReadReceiptPosition {
125
125
const element = this . avatar . current ;
126
126
// this is the mx_ReadReceiptsGroup_container
127
127
const horizontalContainer = element ?. offsetParent ;
128
- if ( ! horizontalContainer || ! ( horizontalContainer instanceof HTMLElement ) ) {
128
+ if ( ! horizontalContainer || ! horizontalContainer . getBoundingClientRect ) {
129
129
// this seems to happen sometimes for reasons I don't understand
130
130
// the docs for `offsetParent` say it may be null if `display` is
131
131
// `none`, but I can't see why that would happen.
132
132
logger . warn ( `ReadReceiptMarker for ${ this . props . fallbackUserId } has no valid horizontalContainer` ) ;
133
133
134
134
target . top = 0 ;
135
135
target . right = 0 ;
136
- target . parent = undefined ;
137
136
return target ;
138
137
}
139
- // this is the mx_ReadReceiptsGroup
140
- const verticalContainer = horizontalContainer . offsetParent ;
141
- if ( ! verticalContainer || ! ( verticalContainer instanceof HTMLElement ) ) {
142
- // this seems to happen sometimes for reasons I don't understand
143
- // the docs for `offsetParent` say it may be null if `display` is
144
- // `none`, but I can't see why that would happen.
145
- logger . warn ( `ReadReceiptMarker for ${ this . props . fallbackUserId } has no valid verticalContainer` ) ;
146
138
147
- target . top = 0 ;
148
- target . right = 0 ;
149
- target . parent = undefined ;
150
- return target ;
151
- }
139
+ const elementRect = element . getBoundingClientRect ( ) ;
152
140
153
- target . top = element . offsetTop ;
154
- target . right = element . getBoundingClientRect ( ) . right - horizontalContainer . getBoundingClientRect ( ) . right ;
155
- target . parent = verticalContainer ;
141
+ target . top = elementRect . top ;
142
+ target . right = elementRect . right - horizontalContainer . getBoundingClientRect ( ) . right ;
156
143
return target ;
157
144
}
158
145
159
- private readReceiptPosition ( info : IReadReceiptInfo ) : number {
160
- if ( ! info . parent ) {
161
- // this seems to happen sometimes for reasons I don't understand
162
- // the docs for `offsetParent` say it may be null if `display` is
163
- // `none`, but I can't see why that would happen.
164
- logger . warn ( `ReadReceiptMarker for ${ this . props . fallbackUserId } has no offsetParent` ) ;
165
- return 0 ;
166
- }
167
-
168
- return ( info . top ?? 0 ) + info . parent . getBoundingClientRect ( ) . top ;
169
- }
170
-
171
146
private animateMarker ( ) : void {
172
- const oldInfo = this . props . readReceiptInfo ;
147
+ const oldInfo = this . props . readReceiptPosition ;
173
148
const newInfo = this . buildReadReceiptInfo ( ) ;
174
149
175
- const newPosition = this . readReceiptPosition ( newInfo ) ;
176
- const oldPosition = oldInfo
177
- ? // start at the old height and in the old h pos
178
- this . readReceiptPosition ( oldInfo )
179
- : // treat new RRs as though they were off the top of the screen
180
- - READ_AVATAR_SIZE ;
150
+ const newPosition = newInfo . top ?? 0 ;
151
+ const oldPosition =
152
+ oldInfo && oldInfo . top !== undefined
153
+ ? // start at the old height and in the old h pos
154
+ oldInfo . top
155
+ : // treat new RRs as though they were off the top of the screen
156
+ - READ_AVATAR_SIZE ;
181
157
182
158
const startStyles : IReadReceiptMarkerStyle [ ] = [ ] ;
183
159
if ( oldInfo ?. right ) {
0 commit comments