Skip to content

Commit 7f65f9a

Browse files
Ahmed Sbaisbaiahmed1
authored andcommitted
fix: improve child view management in mount/unmount methods
1 parent 6014c34 commit 7f65f9a

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

ios/MenuView.mm

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,29 +38,38 @@ - (instancetype)initWithFrame:(CGRect)frame
3838

3939
- (void)mountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index
4040
{
41-
[super mountChildComponentView:childComponentView index:index];
42-
4341
// Only use the first child as the menu trigger
4442
if (index == 0) {
45-
// Remove old child view if exists
46-
if (_childView) {
47-
[_childView removeFromSuperview];
43+
// Clean up old child view if exists
44+
if (_childView && _childView != childComponentView) {
45+
// Remove from our manual tracking without calling removeFromSuperview
46+
// since React will handle the view hierarchy cleanup
4847
_childView = nil;
48+
_menuButton = nil;
4949
}
5050

5151
_childView = (UIView *)childComponentView;
52+
}
53+
54+
// Let React handle the mounting first
55+
[super mountChildComponentView:childComponentView index:index];
56+
57+
// Setup menu trigger after React has properly mounted the view
58+
if (index == 0) {
5259
[self setupChildViewAsMenuTrigger:_childView];
5360
}
5461
}
5562

5663
- (void)unmountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index
5764
{
58-
[super unmountChildComponentView:childComponentView index:index];
59-
65+
// Clean up our references before React unmounts
6066
if (index == 0 && _childView == childComponentView) {
6167
_childView = nil;
6268
_menuButton = nil;
6369
}
70+
71+
// Let React handle the unmounting
72+
[super unmountChildComponentView:childComponentView index:index];
6473
}
6574

6675
- (void)setupChildViewAsMenuTrigger:(UIView *)childView

0 commit comments

Comments
 (0)