Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS] headerSearchBarOptions crashes app with KeyboardProvider in Release mode #784

Closed
fukuli053 opened this issue Jan 28, 2025 · 1 comment · Fixed by #785
Closed

[iOS] headerSearchBarOptions crashes app with KeyboardProvider in Release mode #784

fukuli053 opened this issue Jan 28, 2025 · 1 comment · Fixed by #785
Assignees
Labels
🎯 crash Library triggers a crash of the app 🏭 fabric Changes specific to new (fabric/jsi) architecture 🍎 iOS iOS specific

Comments

@fukuli053
Copy link

Describe the bug
When using Expo Router with Stack navigation, enabling headerSearchBarOptions in the Stack Screen options causes the app to crash immediately upon tapping the search bar. This issue only occurs in Release mode on iOS devices with KeyboardProvider.

Error Message:

*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<_UISearchBarSearchContainerView 0x15ac1d880> valueForUndefinedKey:]: this class is not key value coding-compliant for the key nativeId.'***

Code snippet

// _layout.tsx
export default function RootLayout() {
  return (
    <KeyboardProvider>
      <Stack.Screen
        name="index"
        options={{
          headerShown: true,
          headerLargeTitle: true,
          headerTitle: "Search",
          headerTransparent: true,
          headerBlurEffect: "light",
          headerStyle: {
            backgroundColor: colors.background,
          },
          headerSearchBarOptions: {
            hideWhenScrolling: false,
            placeholder: "Search",
          },
          contentStyle: {
            backgroundColor: colors.background,
          },
        }}
      />
    </KeyboardProvider>
  );
}
}

To Reproduce
Steps to reproduce the behavior:

1- Set up an Expo Router project with Stack navigation
2- Wrap your layout with KeyboardProvider
3- Enable headerSearchBarOptions in Stack.Screen options
4- Build the app in Release mode
5- Tap on the search bar

Smartphone (please complete the following information):

  • Device: iPhone 15 Pro
  • OS: iOS 18.0.1
  • React Native: 0.76.6 (Expo SDK 52)
  • React Native Architecture: New Architecture
  • Library version: 1.16.0

Additional context

"react-native-keyboard-controller": "1.16.0",
"react-native-screens": "^4.5.0",
"react-native-reanimated": "~3.16.1"
@kirillzyusko kirillzyusko added 🍎 iOS iOS specific 🎯 crash Library triggers a crash of the app 🏭 fabric Changes specific to new (fabric/jsi) architecture labels Jan 28, 2025
kirillzyusko added a commit that referenced this issue Jan 28, 2025
## 📜 Description

Fixed a crash when you tap on search input inside a header (native
stack).

## 💡 Motivation and Context

When accessing `nativeId` property in classes where it's not available
(for example `UISearchBarSearchContainerView`, but I assume other UIKit
classes as well), we will get a crash:

> *** Terminating app due to uncaught exception 'NSUnknownKeyException',
reason: '[<_UISearchBarSearchContainerView 0x15ac1d880>
valueForUndefinedKey:]: this class is not key value coding-compliant for
the key nativeId.'***

To overcome this problem I added a check whether this property is
defined, and if it is defined, only then we query an actual value.

Tested in `FabricExample` and it resolves a crash 🤞 

Closes
#784

## 📢 Changelog

<!-- High level overview of important changes -->
<!-- For example: fixed status bar manipulation; added new types
declarations; -->
<!-- If your changes don't affect one of platform/language below - then
remove this platform/language -->

### iOS

- check if view responds to `nativeId` selector before querying
`nativeId` value;

## 🤔 How Has This Been Tested?

Tested manually on iPhone 15 Pro (iOS 17.5) in native-stack example,
with adding next options:

```ts
    headerSearchBarOptions: {
      hideWhenScrolling: false,
      placeholder: "Search",
    },
```

And also tested Interactive keyboard on iOS (Fabric) to make sure it
works as before.

## 📸 Screenshots (if appropriate):


https://github.com/user-attachments/assets/f7393ec3-1ae7-4500-9fe4-e5857a302ec0

## 📝 Checklist

- [x] CI successfully passed
- [x] I added new mocks and corresponding unit-tests if library API was
changed
@kirillzyusko
Copy link
Owner

kirillzyusko commented Jan 28, 2025

Thanks, fixed it!

For now you can apply patch using patch-package or downgrade to 1.15.2

The fix will be published in 1.16.1 (hopefully at the end of the week or in the next week)!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🎯 crash Library triggers a crash of the app 🏭 fabric Changes specific to new (fabric/jsi) architecture 🍎 iOS iOS specific
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants