react-native-ui-lib icon indicating copy to clipboard operation
react-native-ui-lib copied to clipboard

Attempt to invoke virtual method 'void.com.facebook.react.uimanager.UIManagerModule.onBatchComplete()' on a null object reference

Open muzhaqi16 opened this issue 1 year ago • 32 comments

Description

Attempt to invoke virtual method 'void.com.facebook.react.uimanager.UIManagerModule.onBatchComplete()' on a null object reference

Related to

  • [x] Components
  • [ ] Demo
  • [ ] Docs
  • [ ] Typings

Steps to reproduce

Steps to reproduce the behavior:

  1. Create a new project with react-native": "^0.76"
  2. Setup react-native-ui-lib
  3. Add a TextField from react-native-ui-lib
  4. See error Attempt to invoke virtual method 'void.com.facebook.react.uimanager.UIManagerModule.onBatchComplete()' on a null object reference

Expected behavior

For the app not to crash

Actual behavior

App crashes

More Info

Code snippet

      <View flex paddingH-25 paddingT-120>
        <Text blue50 text20>
          Welcome
        </Text>
        <TextField text50 placeholder="username" grey10 />
        <TextField text50 placeholder="password" secureTextEntry grey10 />
        <View marginT-100 center>
          <Button text70 white background-orange30 label="Login" />
          <Button link text70 orange30 label="Sign Up" marginT-20 />
        </View>
      </View>

Screenshots/Video

Screenshot_20241116_193631_SousChefRN

Environment

System:
  OS: Windows 11 10.0.26100
  CPU: (20) x64 12th Gen Intel(R) Core(TM) i9-12900HK
  Memory: 14.56 GB / 31.69 GB
Binaries:
  Node:
    version: 20.18.0
    path: C:\Program Files\nodejs\node.EXE
  Yarn:
    version: 1.22.22
    path: C:\Program Files\nodejs\yarn.CMD
  npm:
    version: 10.8.2
    path: C:\Program Files\nodejs\npm.CMD
  Watchman:
    version: 20241103.093242.0
    path: C:\ProgramData\chocolatey\bin\watchman.EXE
SDKs:
  Android SDK:
    API Levels:
      - "34"
      - "35"
    Build Tools:
      - 34.0.0
      - 35.0.0
    System Images:
      - android-35 | Google Play Intel x86_64 Atom
    Android NDK: Not Found
  Windows SDK:
    AllowDevelopmentWithoutDevLicense: Enabled
IDEs:
  Android Studio: AI-242.23339.11.2421.12550806
  Visual Studio: Not Found
Languages:
  Java:
    version: 17.0.13
    path: /c/Program Files/Microsoft/jdk-17.0.13.11-hotspot/bin/javac
  Ruby: Not Found
npmPackages:
  "@react-native-community/cli":
    installed: 15.0.1
    wanted: 15.0.1
  react:
    installed: 18.3.1
    wanted: 18.3.1
  react-native:
    installed: 0.76.2
    wanted: 0.76.2
  react-native-windows: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found
  • React Native version: "0.76.2"
  • React Native UI Lib version: "^7.34.2"
  • "react-native-gesture-handler": "^2.21.2",
  • "react-native-reanimated": "^3.16.1",

Affected platforms

  • [x] Android
  • [ ] iOS
  • [ ] Web

muzhaqi16 avatar Nov 20 '24 03:11 muzhaqi16

Commenting out the following line in RuntimeUtils.java fixes the issue:

ReactContextHolder.getContext().getNativeModule(UIManagerModule.class).onBatchComplete();

Not sure what the long term solution is.

package com.wix.reactnativeuilib.keyboardinput.utils;

import com.facebook.react.uimanager.UIManagerModule;
import com.wix.reactnativeuilib.keyboardinput.ReactContextHolder;

public class RuntimeUtils {

    // TODO Switch to GuardedRunnable when upgrading RN's minimal ver
    private static final Runnable sUIUpdateClosure = new Runnable() {
        @Override
        public void run() {
            ReactContextHolder.getContext().getNativeModule(UIManagerModule.class).onBatchComplete();
        }
    };

    public static void runOnUIThread(Runnable runnable) {
        if (ReactContextHolder.getContext() != null) {
            ReactContextHolder.getContext().runOnUiQueueThread(runnable);
        }
    }

    public static void dispatchUIUpdates(final Runnable userRunnable) {
        runOnUIThread(new Runnable() {
            @Override
            public void run() {
                userRunnable.run();
                if (ReactContextHolder.getContext() != null) {
                    ReactContextHolder.getContext().runOnNativeModulesQueueThread(sUIUpdateClosure);
                }
            }
        });
    }
}

jameskennethrobinson avatar Dec 03 '24 01:12 jameskennethrobinson

Hi @muzhaqi16 does it reproduce on project with RN 0.73 ?

adids1221 avatar Dec 17 '24 13:12 adids1221

still not fixed? 🙁

matice2 avatar Dec 18 '24 13:12 matice2

Waiting for this fix

JoseAIG avatar Dec 20 '24 16:12 JoseAIG

Having the same error can anybody recommend a fix till they resolve the issue

AhmedMaqbool avatar Dec 21 '24 05:12 AhmedMaqbool

@matice2 @JoseAIG @AhmedMaqbool Does the issue reproduce on RN 0.73? Currently we are supporting RN 0.73, we will try to check this issue.

adids1221 avatar Dec 22 '24 08:12 adids1221

@matice2 @JoseAIG @AhmedMaqbool Does the issue reproduce on RN 0.73? Currently we are supporting RN 0.73, we will try to check this issue.

Okay this only works on 0.73 my project is using 0.76 any sort of timeline when you guys will start supporting 0.76

AhmedMaqbool avatar Dec 22 '24 09:12 AhmedMaqbool

I am getting the same error kindly fix it. i am only using the Carousel component

subhranshuchoudhury avatar Dec 27 '24 10:12 subhranshuchoudhury

Same problem

Astremy avatar Jan 02 '25 09:01 Astremy

I have the same problem. I have this error when input field on focus, and when hide application, and come back i get this error

d1kssS avatar Jan 14 '25 19:01 d1kssS

Same problem here for TextField. "react": "^18.3.1", "react-native": "0.76.6", "react-native-ui-lib": "^7.0.0",

AnthonyCerdasAnalisis avatar Jan 16 '25 01:01 AnthonyCerdasAnalisis

Same issue. Please, when will this problem be fixed??

sadewole avatar Jan 20 '25 10:01 sadewole

@matice2 @JoseAIG @AhmedMaqbool Does the issue reproduce on RN 0.73? Currently we are supporting RN 0.73, we will try to check this issue.

So when will this issue be fixed for latest react-native: 0.76.6 ??

sadewole avatar Jan 20 '25 11:01 sadewole

I needed to update sUIUpdateClosure at this paths: node_modules/react-native-ui-lib/lib/android/src/main/java/com/wix/reactnativeuilib/keyboardinput/utils/RuntimeUtils.java and /home/vito/GitHub/mobile-apps/apps/user-mobile/node_modules/uilib-native/android/src/main/java/com/wix/reactnativeuilib/keyboardinput/utils/RuntimeUtils.java

From this:

    private static final Runnable sUIUpdateClosure = new Runnable() {
        @Override
        public void run() {
            ReactContextHolder.getContext().getNativeModule(UIManagerModule.class).onBatchComplete();
        }
    };

To this:

    private static final Runnable sUIUpdateClosure = new Runnable() {
        @Override
        public void run() {
            try {
                UIManagerModule uiManager = ReactContextHolder.getContext()
                        .getNativeModule(UIManagerModule.class);
                if (uiManager != null) {
                    uiManager.onBatchComplete();
                } else {
                    // Log the error or handle it accordingly
                    System.err.println("UIManagerModule is null, cannot call onBatchComplete");
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };

And it works to me.

I need to add this to patch-package too

vitoalmeida avatar Jan 22 '25 13:01 vitoalmeida

Any update on this? I have installed the lastest version 7.36.0 and still the issue persists.

Thanks!

relez avatar Jan 30 '25 15:01 relez

As was already said (and is mentioned in the first paragraph of the repo's README) — this library only supports RN 0.73. They'll support 0.77 at some point (no timeline given)

Clarity aside, being over a year behind the official RN releases is a deal breaker for us, so we have to remove our dep on this lib

mihaibulic2 avatar Feb 15 '25 23:02 mihaibulic2

The fix I suggested earlier works great. No problem using with 0.77

On Sat, Feb 15, 2025 at 16:06 mihaibulic2 @.***> wrote:

As was already said — this library only supports RN 0.73. They'll support 0.77 at some point (no timeline given)

Personally, being over a year behind the official RN releases is a deal breaker, so I'm removing my dep on RN UI lib.

— Reply to this email directly, view it on GitHub https://github.com/wix/react-native-ui-lib/issues/3397#issuecomment-2661140239, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB53IRJTBUMYKPRA43M2YPL2P7B53AVCNFSM6AAAAABSDRUKGSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMNRRGE2DAMRTHE . You are receiving this because you were mentioned.Message ID: @.***> [image: mihaibulic2]mihaibulic2 left a comment (wix/react-native-ui-lib#3397) https://github.com/wix/react-native-ui-lib/issues/3397#issuecomment-2661140239

As was already said — this library only supports RN 0.73. They'll support 0.77 at some point (no timeline given)

Personally, being over a year behind the official RN releases is a deal breaker, so I'm removing my dep on RN UI lib.

— Reply to this email directly, view it on GitHub https://github.com/wix/react-native-ui-lib/issues/3397#issuecomment-2661140239, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB53IRJTBUMYKPRA43M2YPL2P7B53AVCNFSM6AAAAABSDRUKGSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMNRRGE2DAMRTHE . You are receiving this because you were mentioned.Message ID: @.***>

jameskennethrobinson avatar Feb 15 '25 23:02 jameskennethrobinson

` diff --git a/lib/android/src/main/java/com/wix/reactnativeuilib/keyboardinput/utils/RuntimeUtils.java b/lib/android/src/main/java/com/wix/reactnativeuilib/keyboardinput/utils/RuntimeUtils.java index 95c5e8ea473c83e2b95a47b42945befe13e69de2..cddcab08cc6c00f49612b7db56f446c1605f84aa 100644 --- a/lib/android/src/main/java/com/wix/reactnativeuilib/keyboardinput/utils/RuntimeUtils.java +++ b/lib/android/src/main/java/com/wix/reactnativeuilib/keyboardinput/utils/RuntimeUtils.java @@ -9,7 +9,10 @@ public class RuntimeUtils { private static final Runnable sUIUpdateClosure = new Runnable() { @Override public void run() {

  •        ReactContextHolder.getContext().getNativeModule(UIManagerModule.class).onBatchComplete();
    
  •        var nativeModule = ReactContextHolder.getContext().getNativeModule(UIManagerModule.class);
    
  •        if (nativeModule != null) {
    
  •            nativeModule.onBatchComplete();
    
  •        }
       }
    
    };

`

i didcthis patch and still facing the smae issues

deidine avatar Feb 17 '25 09:02 deidine

hey @deidine also patch uilib-native package. its dependency

iwalker7 avatar Feb 18 '25 00:02 iwalker7

@iwalker7 > hey @deidine also patch uilib-native package. its dependency what you mean can you explain pls

deidine avatar Feb 18 '25 09:02 deidine

@iwalker7 > hey @deidine also patch uilib-native package. its dependency what you mean can you explain pls

check it out https://github.com/wix/react-native-ui-lib/issues/3397#issuecomment-2607309623

iwalker7 avatar Feb 18 '25 10:02 iwalker7

I applied the fix and used patch-package, but it still gives me the same error Rn: 0.77 expo: 0.52 react-native-ui-lib: ^7.37.2

@iwalker7 @vitoalmeida

WraithIT avatar Feb 25 '25 15:02 WraithIT

I applied the fix and used patch-package, but it still gives me the same error Rn: 0.77 expo: 0.52 react-native-ui-lib: ^7.37.2

@iwalker7 @vitoalmeida

patch the uilib-native too.

vyvodev avatar Feb 28 '25 02:02 vyvodev

I applied the patch, works great but now my Dialogs on Android don't work correctly. Anyone else have this issue?

TweetyBoop1990 avatar Mar 02 '25 02:03 TweetyBoop1990

I applied the patch, works great but now my Dialogs on Android don't work correctly. Anyone else have this issue?

What issue did you run into? I applied the patch to both react-native-ui-lib and uilib-native and it works perfectly fine, I tested with a RNUI Dialog.

ferretwithaberet avatar Mar 02 '25 22:03 ferretwithaberet

For those who still have the bug after patching files, cleaning npm cache may help :

rm -rf node_modules
rm package-lock.json
npm cache clean --force
npm start -- --reset-cache

olivier-nerot avatar Mar 23 '25 23:03 olivier-nerot

Still same issue

Image

I tried the patch, but it's not working with 'react-native': '0.78.1' and 'react-native-ui-lib': '^7.39.1'.

dhruvpaobs avatar Apr 05 '25 05:04 dhruvpaobs

The patch worked well in my environment.

expo: 52.0.42 react-native: 0.76.9 react-native-ui-lib: 7.39.0

As already mentioned, the patch needs to be applied not only to react-native-ui-lib but also to uilib-native. Just to be safe, I applied patches to both. The directory structure looks like this:

📁patches
┣ 📄react-native-ui-lib+7.39.0.patch
┗ 📄uilib-native+4.5.1.patch

t-yag avatar Apr 12 '25 09:04 t-yag

"expo": "^53.0.9",
"react-native": "0.79.2",
"react-native-ui-lib": "^7.41.1",

Bug still there. Patch worked.

TheForsakenSpirit avatar May 09 '25 12:05 TheForsakenSpirit