Repository navigation
Commit 8771d39
authored
Don't report IntersectionObserver targets fully clipped by an ancestor as intersecting
## Summary:
When an ancestor between the target and the root (a `ScrollView` or an `overflow: hidden` view) clips the target away entirely, `getClippedTargetBoundingRect` returned `Rect{}`: a zero-size rect at the origin. `intersectOrNull` then treated that as an edge-adjacent intersection whenever the root rectangle contained the origin. That's always the case for the implicit root (the origin is its corner), and almost always for an explicit root (the empty rect is translated to the root's origin).
Because an intersection ratio of 0 crosses a threshold of 0, observers with the default `threshold` (or an `rnRootThreshold` containing 0) reported these targets with `isIntersecting: true`, as long as their unclipped bounding box overlapped the root. `rootMargin` makes this easy to hit because it widens that overlap. For example, with `rootMargin: '500px 0px'`, every item of a `ScrollView` within 500px of the viewport is reported as intersecting, even though the `ScrollView` clips it.
A fully clipped target now produces no intersection, so it's reported as not intersecting with an empty `intersectionRect`. This matches the [`intersection-observer/clip-path.html`](https://github.com/web-platform-tests/wpt/blob/master/intersection-observer/clip-path.html) Web Platform Test: a target fully clipped by an ancestor, while its bounding box is still inside the viewport, expects `isIntersecting: false`.
Observers with thresholds above 0 are unaffected. They already reported these targets as not intersecting, with the same entry values.
Found while working on `scrollMargin` support, which is stacked on top of this.
## Changelog:
[GENERAL] [FIXED] - IntersectionObserver no longer reports targets fully clipped by an ancestor as intersecting
## Test Plan:
Added Fantom tests for a target fully clipped by an intermediate `ScrollView`, with the default threshold and with `rootMargin`. Both fail without this change.
```
yarn fantom packages/react-native/src/private/webapis/intersectionobserver/
```
110 passed, 1 skipped.
```
yarn flow-check
yarn lint
```
Clean.
Differential Revision: D133249484
Pull Request resolved: #601521 parent 4634366 commit 8771d39
2 files changed
Lines changed: 77 additions & 5 deletions
File tree
- packages/react-native
- ReactCommon/react/renderer/observers/intersection
- src/private/webapis/intersectionobserver/__tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
150 | 150 | | |
151 | 151 | | |
152 | 152 | | |
153 | | - | |
| 153 | + | |
| 154 | + | |
154 | 155 | | |
155 | 156 | | |
156 | 157 | | |
| |||
159 | 160 | | |
160 | 161 | | |
161 | 162 | | |
162 | | - | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
163 | 167 | | |
164 | 168 | | |
165 | 169 | | |
| |||
212 | 216 | | |
213 | 217 | | |
214 | 218 | | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
215 | 224 | | |
216 | 225 | | |
217 | 226 | | |
218 | 227 | | |
219 | | - | |
220 | | - | |
221 | | - | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
222 | 231 | | |
223 | 232 | | |
224 | 233 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3976 | 3976 | | |
3977 | 3977 | | |
3978 | 3978 | | |
| 3979 | + | |
| 3980 | + | |
| 3981 | + | |
| 3982 | + | |
| 3983 | + | |
| 3984 | + | |
| 3985 | + | |
| 3986 | + | |
| 3987 | + | |
| 3988 | + | |
| 3989 | + | |
| 3990 | + | |
| 3991 | + | |
| 3992 | + | |
| 3993 | + | |
| 3994 | + | |
| 3995 | + | |
| 3996 | + | |
| 3997 | + | |
| 3998 | + | |
| 3999 | + | |
| 4000 | + | |
| 4001 | + | |
| 4002 | + | |
| 4003 | + | |
| 4004 | + | |
| 4005 | + | |
| 4006 | + | |
| 4007 | + | |
| 4008 | + | |
| 4009 | + | |
| 4010 | + | |
| 4011 | + | |
| 4012 | + | |
| 4013 | + | |
| 4014 | + | |
| 4015 | + | |
| 4016 | + | |
| 4017 | + | |
| 4018 | + | |
| 4019 | + | |
| 4020 | + | |
| 4021 | + | |
| 4022 | + | |
| 4023 | + | |
| 4024 | + | |
| 4025 | + | |
| 4026 | + | |
| 4027 | + | |
| 4028 | + | |
| 4029 | + | |
| 4030 | + | |
| 4031 | + | |
| 4032 | + | |
| 4033 | + | |
| 4034 | + | |
| 4035 | + | |
| 4036 | + | |
| 4037 | + | |
| 4038 | + | |
| 4039 | + | |
| 4040 | + | |
| 4041 | + | |
3979 | 4042 | | |
3980 | 4043 | | |
3981 | 4044 | | |
| |||
0 commit comments