Skip to content

Android: events are no longer received after reload from bundler #113

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

Closed
rikardg opened this issue Feb 8, 2023 · 9 comments · Fixed by #117
Closed

Android: events are no longer received after reload from bundler #113

rikardg opened this issue Feb 8, 2023 · 9 comments · Fixed by #117
Assignees
Labels
🤖 android Android specific 🐛 bug Something isn't working

Comments

@rikardg
Copy link

rikardg commented Feb 8, 2023

First, thank you for your work on providing this package, it is much appreciated!

Issue

On Android, after a reload from the bundler, the keyboard events are no longer received. Steps to reproduce:

  1. Build and start the example Android app from this repo.
  2. Go to "3. Events".
  3. Activate the text input. A notification is displayed that the keyboard is shown. Hide the keyboard, and a corresponding hide notification is shown.
  4. Reload the app from the bundler, e.g. by pressing Cmd/Ctrl+M or via the dev menu.
  5. Now repeat from step 2 above, but note that no notifications are displayed, indicating that no events are received.

Expected behaviour is that events are still received after a reload.

Platform information

  • Desktop OS: macOS 13.1
  • Device/OS: Android emulator/API level 31, Huawei P10/Android 7.0, and others.
  • RN version: 0.70.5
  • RN architecture: default from example app
  • JS engine: default from example app
  • Library version: 1.4.2

I have not built the example app for iOS, but the events are working properly in the app where the problem was discovered. This seems to be Android specific.

@rikardg rikardg added the 🐛 bug Something isn't working label Feb 8, 2023
@kirillzyusko
Copy link
Owner

Thanks @rikardg
I will have a look on the problem!

@kirillzyusko
Copy link
Owner

I'm able to reproduce a problem. Looking for a solution 👀

@kirillzyusko
Copy link
Owner

@rikardg would you mind to check if #114 fixes the issue?

I've tested locally and everything seems to be working fine after these changes, but just want to ask double confirmation 🙂

@kirillzyusko kirillzyusko added the 🤖 android Android specific label Feb 9, 2023
@rikardg
Copy link
Author

rikardg commented Feb 9, 2023

Hi!

The unmodified example from the repository works now. 👍

However, if I move the text input to the front page so that there is no screen navigation before it is displayed, it doesn't work for me on API level 28 and 24. It seems like the first show event is not received after a reload. However, the following hide event as well as subsequent show/hide events are all received. I've tested on:

  • Android 7 (24, physical device): first event not received.
  • Android 9 (28, physical device and emulator): first event not received.
  • Android 12 (31, emulator): first event is received.

To reproduce:

  1. Build and run app with the modified App.tsx below.
  2. Check that show/hide events give a notificiation.
  3. Reload app.
  4. Focus text input. On Android 7 and 9 (at least), the first show event doesn't give a notification. Check that subsequent events are received (they are for me).

My modified App.tsx:

import 'react-native-gesture-handler';

import * as React from 'react';
import { KeyboardProvider } from 'react-native-keyboard-controller';
import {
  SafeAreaProvider,
  initialWindowMetrics,
} from 'react-native-safe-area-context';
import Events from './screens/Examples/Events';

const spacerStyle = { marginVertical: 50 };

export default function App() {
  return (
    <SafeAreaProvider initialMetrics={initialWindowMetrics} style={spacerStyle}>
      <KeyboardProvider statusBarTranslucent>
        <Events />
      </KeyboardProvider>
    </SafeAreaProvider>
  );
}

@kirillzyusko
Copy link
Owner

kirillzyusko commented Feb 9, 2023

@rikardg okay, thanks. I will try to test your example tomorrow 👍
Thanks for the great explanation of the issue 😊

kirillzyusko added a commit that referenced this issue Feb 10, 2023
#114)

## 📜 Description

Use context provided by `createViewInstance` for view creation.

## 💡 Motivation and Context

Partially fixes the problem described in
#113

We need to use actual context provided by `createViewInstance`.
Otherwise after hot reloading context may be invalid and keyboard events
will not be send to JS thread (since UIManager will be invalid).

## 📢 Changelog

### Android
- use `reactContext` from params instead of constructor value;

## 🤔 How Has This Been Tested?

Tested manually on Pixel 7 Pro and Xiaomi Redmi Note 5 Pro (real
devices).

## 📝 Checklist

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

Hi @rikardg
I merged one PR and created a new one (#117), since the issue looks similar from dev perspective, but has absolutely different fixes and I would like to keep them separate just for more transparency
Could you please check if #117 fixes the problem?
I've rebased this branch on latest main branch, so it has both fixes. Hopefully everything should work fine 😊

@rikardg
Copy link
Author

rikardg commented Feb 10, 2023

Hi,

I've tested on a few different Android versions now (API level 24/physical, 31/33/emulator) with both the modified example from above as well as the app I'm working on. Works perfectly everywhere. So 👍 from me.

Thank you for fixing this so quickly!

@kirillzyusko
Copy link
Owner

@rikardg awesome! Then I will merge PR and will release 1.4.3 in the beginning of next week☺️

@kirillzyusko
Copy link
Owner

Closed since https://github.com/kirillzyusko/react-native-keyboard-controller/releases/tag/1.4.3 has been published.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖 android Android specific 🐛 bug Something isn't working
Projects
None yet
2 participants