Skip to content

Commit

Permalink
fix: unmount OverKeyboardView from native side (#633)
Browse files Browse the repository at this point in the history
## 📜 Description

Fixed `OverKeyboardView` unmount if view is attached to `.lastWindow`.

## 💡 Motivation and Context

The key problem here is the fact that we unmount a view in JS, but
`visible` property remains `true`, as a result view keeps mounted.

It doesn't happen when keyboard is visible, because in this case
keyboard window gets destroyed and view gets destroyed as well. But when
we attache a view to `.lastWindow` then we catch a bug.

This bug doesn't happen in Android, because on Android we've implemented
`onDetachedFromWindow` where we call `hide`. I thought it would be
reasonable to implement the same approach, so I added
`didMoveToSuperview` method where I'm checking that unmount happened (i.
e. `superview` is `nil`) and if so then I call `hide`.

Closes
#632

## 📢 Changelog

### iOS

- add lifecycles regions;
- add `didMoveToSuperview` method implementation;
- check if `superview==nil` and call `hide` in this case.

## 🤔 How Has This Been Tested?

Tested manually on iPhone 15 Pro (iOS 17.5).

## 📸 Screenshots (if appropriate):


https://github.com/user-attachments/assets/b1f501fe-c20a-40c4-b1f8-c212552e7651

## 📝 Checklist

- [x] CI successfully passed
- [x] I added new mocks and corresponding unit-tests if library API was
changed
  • Loading branch information
kirillzyusko authored Oct 14, 2024
1 parent de98355 commit c068c2a
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ios/views/OverKeyboardViewManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge
}
#endif

// MARK: lifecycle methods
- (void)didMoveToSuperview
{
if (self.superview == nil) {
[self hide];
}
}

// MARK: touch handling
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
Expand Down

0 comments on commit c068c2a

Please sign in to comment.