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

Crashing on IOS after pressing TextInput after Expo Image Picker #155

Closed
shedworth opened this issue May 22, 2023 · 6 comments · Fixed by #157
Closed

Crashing on IOS after pressing TextInput after Expo Image Picker #155

shedworth opened this issue May 22, 2023 · 6 comments · Fixed by #157
Assignees
Labels
🐛 bug Something isn't working 🎯 crash Library triggers a crash of the app 🍎 iOS iOS specific

Comments

@shedworth
Copy link

shedworth commented May 22, 2023

Describe the bug
In my React Native app, on forms with a text input and Expo image picker, pressing a text input after opening/closing the image picker causes the app to crash. Simply wrapping the app in <KeyboardProvider> is enough to cause this behaviour, without using any other components from react-native-keyboard-controller.

Code snippet
Note, although this snippet uses react-hook-forms, the crashing behaviour happens elsewhere in the app where this isn't used.

...
  return (
    <ScrollView
      contentContainerStyle={styles.container}
      style={styles.background}
      showsVerticalScrollIndicator={false}
      >
        <View>
          <Controller
            control={control}
            name={"bannerImage"}
            render={renderBannerImagePicker}
          />
        </View>
      <View style={styles.formSection}>
        <Label
          required
          text={i18n.t("screens.birdingGroupCreateChallenge.name")}
        />
        <Controller name={"name"} control={control} render={renderName} />
      </View>
      </ScrollView>

App.tsx

...
  return (
    <KeyboardProvider>
      <GestureHandlerRootView style={styles.gestureView}>
        <LoginProvider
          isLoggedIn={isLoggedIn && !!currentUser}
          currentUser={currentUser}
        >
          <DatabaseProvider>
            <ApolloProvider client={client}>
              <CachePersistorProvider>
                <SafeAreaProvider>
                  <ActionSheetProvider>
                    <SuggestionsProvider>
                      <FeedWeightingProvider>
                        <>
                          <Navigation />
                          <StatusBar style="dark" />
                        </>
                      </FeedWeightingProvider>
                    </SuggestionsProvider>
                  </ActionSheetProvider>
                </SafeAreaProvider>
              </CachePersistorProvider>
            </ApolloProvider>
          </DatabaseProvider>
        </LoginProvider>
      </GestureHandlerRootView>
    </KeyboardProvider>
  );

Error copied from Apple console on Macbook (iPhone connected by USB):

runOperations: -[_UIKeyboardArbiter retrieveClientDebugInformationWithCompletion:] Failed to access <_UIKeyboardArbiterClientHandle: 0x28080e470; PID 14229: com.chirpbirding.birda-dev <<UIKBArbiterClientFocusContext: 0x283970640; contextID = 2f109a25; sceneIdentity = com.apple.frontboard.systemappservices::FBSceneManager:sceneID%3Acom.chirpbirding.birda-dev-default >>; hosting PIDs {(
)}; level 5.000000; active YES [wants YES]; suppression 0; iav 0.000000; on screen YES; isAcquiringFocus: NO> remote service: Error Domain=NSCocoaErrorDomain Code=4099 "The connection from pid 14229 on mach service named com.apple.UIKit.KeyboardManagement.hosted was invalidated: client is gone." UserInfo={NSDebugDescription=The connection from pid 14229 on mach service named com.apple.UIKit.KeyboardManagement.hosted was invalidated: client is gone.}

To Reproduce
Steps to reproduce the behavior:

  1. Go to a form with an image picker and text input
  2. Press the text input and type something - verify that it works correctly and doesn't crash
  3. Press the image picker. Picker opens
  4. Choose an image or press cancel (doesn't matter which). Returns to form
  5. Press text input. App crashes and closes immediately to the device desktop

Expected behavior

  1. Go to a form with an image picker and text input
  2. Press the text input and type something - verify that it works correctly and doesn't crash
  3. Press the image picker. Picker opens
  4. Choose an image or press cancel (doesn't matter which). Returns to form
  5. Press text input and type something - it works correctly and doesn't crash

Smartphone (please complete the following information):

  • Desktop OS: [e.g. Windows 10, MacOS 10.15.5]
  • Device: iPhone X
  • OS: IOS 16.4.1
  • RN version: 0.71.6
  • RN architecture: old
  • JS engine: Hermes
  • Library version: 1.5.3 (also tried 1.4.4 to no avail)
@shedworth shedworth added the 🐛 bug Something isn't working label May 22, 2023
@kirillzyusko kirillzyusko added the 🍎 iOS iOS specific label May 22, 2023
@kirillzyusko
Copy link
Owner

@shedworth so you are experiencing the problem on 1.5.3 and 1.4.4, right? Would you mind to create a small reproduction example?

For me it'll be hard to reproduce, because the setup looks complicated and I don't think I can craft proper repro just based on this information.

@kirillzyusko kirillzyusko added the 🎯 crash Library triggers a crash of the app label May 22, 2023
@kirillzyusko
Copy link
Owner

kirillzyusko commented May 30, 2023

@shedworth could you please check whether #157 fixes the problem or not?

@shedworth
Copy link
Author

Still happening unfortunately :(

@kirillzyusko
Copy link
Owner

kirillzyusko commented May 31, 2023

@shedworth that's strange... I added react-native-image-picker and added a button to open image-picker. It produced crash straight away after TextInput gets focused, but with this change it works fine 🤷‍♂️

I may suppose the problem is somewhere else, but in order to understand that I need to have a reproducible example 🙏

@shedworth just theoretically you can try to move call of setupKVObserver/removeKVObserver to keyboardDidAppear/keyboardDidDisappear and don't subscribe to window* events. Maybe it'll help, but since I don't have a reproducible example I can't say much more 😔

kirillzyusko added a commit that referenced this issue Jun 1, 2023
## 📜 Description

Use memoized `keyboardView` reference for removing observer.

## 💡 Motivation and Context

Since `keyboardView` is a getter there are some chances that it may
return a new reference to a view when we access it.

In some cases it may be a problem, because it can return a reference to
a view which doesn't contain an observer yet. As a result when we'll try
to remove an observer from a view which doesn't have it -> we'll get a
crash.

To prevent a crash in `removeKVObserver` we start to use `_keyboardView`
instead of `keyboardView`. It'll give us an access to old view and we
can safely remove the observer.

Fixes
#155

Potentially also fixes:
#152

## 📢 Changelog

### iOS
- use `_keyboardView` instead of `keyboardView` when remove observer;

## 🤔 How Has This Been Tested?

Tested on iPhone 14 (simulator, iOS 16.2) using following code:

```tsx
<Button title="show image picker" onPress={async () => {
  // You can also use as a promise without 'callback':
  const result = await launchImageLibrary();
}} />
```

## 📸 Screenshots (if appropriate):

|Before|After|
|------|-----|
|<video
src="https://github.com/kirillzyusko/react-native-keyboard-controller/assets/22820318/077f279e-f95b-4aea-ac09-41d8a7d4c846">|<video
src="https://github.com/kirillzyusko/react-native-keyboard-controller/assets/22820318/e5a5e9aa-2204-42cc-b767-07d43053bf7d">|

## 📝 Checklist

- [x] CI successfully passed
@kirillzyusko
Copy link
Owner

GitHub automatically closed this issue since PR that had a reference to this issue was merged.

I've published 1.5.4 to npm-registry. Hopefully the issue is resolved, but in any case feel free to re-open this issue or feel free to create a new one 🙂

@kirillzyusko
Copy link
Owner

@shedworth the similar problem was reported in #175

The reason why it couldn't be reproducible on my setup is the fact that I've used only iOS 16.2/16.3. However you were testing iOS 16.4

#175 was fixed and I published a new 1.5.7 version on npm. I re-tested my example (with image-picker and 1.5.7 version) and it works like a charm on iOS 16.4 too 🙂

So feel free to re-test it too 😎 Hopefully the problem has fully gone 🤞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working 🎯 crash Library triggers a crash of the app 🍎 iOS iOS specific
Projects
None yet
2 participants