Commit e22e64c
fix(iOS): unregister tabs accessory observer from observed wrapper (#3948)
## Description
Fixes a possible iOS 26 bottom accessory crash during invalidation.
The helper registers KVO for `center` on `self.nativeWrapperView`, but
invalidation removed the observer from
`_bottomAccessoryView.superview.superview` at teardown time. UIKit can
detach or swap the bottom accessory wrapper before invalidation runs, so
the teardown path may attempt to remove the observer from a different
wrapper view and raise an `NSRangeException` because that object was
never observed.
I do not see an existing issue for this exact stack, but we observed it
in production on `react-native-screens` 4.23.0, and the same
registration/removal pattern is present on current `main`.
## Changes
- Stores the exact native wrapper view that was registered for KVO.
- Makes `registerForAccessoryFrameChanges` idempotent for the same
wrapper and unregisters the previous wrapper if the wrapper changes.
- Removes the observer from the stored observed wrapper during
invalidation instead of resolving the current superview chain again.
- Uses a dedicated KVO context and forwards unrelated observations to
`super`.
## Test plan
- `yarn install --immutable`
- `yarn prepare`
- `yarn check-types`
- `xcrun clang-format -i
ios/tabs/bottom-accessory/RNSTabsBottomAccessoryHelper.mm`
- `git diff --check`
Existing examples that exercise bottom accessory behavior:
- `apps/src/tests/issue-tests/Test3288.tsx`
- `apps/src/tests/single-feature-tests/tabs/bottom-accessory-layout.tsx`
I did not add a JS unit test for this because the failure is caused by
UIKit/KVO object identity during native view invalidation. A meaningful
automated regression test would need a native iOS XCTest harness or an
iOS integration/e2e test that drives bottom accessory mount, detach, and
invalidation lifecycle. This repository does not appear to have an iOS
native unit-test target for library internals today.
I attempted `yarn test:unit` after initializing the `react-navigation`
submodule, but the root Jest command also collects the submodule's own
test suites and fails on unrelated submodule Jest setup / React version
issues before exercising this native change.
## Checklist
- [ ] Included code example that can be used to test this change.
Existing bottom accessory examples are listed above; no new JS example
was added for this native KVO lifecycle fix.
- [x] For visual changes, included screenshots / GIFs / recordings
documenting the change. N/A, no visual changes.
- [x] For API changes, updated relevant public types. N/A, no API
changes.
- [x] Ensured that CI passes
---------
Co-authored-by: Krzysztof Ligarski <[email protected]>1 parent d3abbe7 commit e22e64c
1 file changed
Lines changed: 34 additions & 5 deletions
Lines changed: 34 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
| 12 | + | |
11 | 13 | | |
12 | 14 | | |
| 15 | + | |
13 | 16 | | |
14 | 17 | | |
15 | 18 | | |
| |||
35 | 38 | | |
36 | 39 | | |
37 | 40 | | |
| 41 | + | |
38 | 42 | | |
39 | 43 | | |
40 | 44 | | |
| |||
110 | 114 | | |
111 | 115 | | |
112 | 116 | | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
113 | 130 | | |
114 | 131 | | |
115 | | - | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
116 | 143 | | |
117 | 144 | | |
118 | 145 | | |
119 | 146 | | |
120 | 147 | | |
121 | 148 | | |
122 | 149 | | |
123 | | - | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
124 | 155 | | |
125 | 156 | | |
126 | 157 | | |
| |||
192 | 223 | | |
193 | 224 | | |
194 | 225 | | |
195 | | - | |
196 | | - | |
197 | | - | |
| 226 | + | |
198 | 227 | | |
199 | 228 | | |
200 | 229 | | |
| |||
0 commit comments