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

fix(Android, Paper): apps soft crash on exception due to detached context #2199

Merged
merged 2 commits into from
Jun 21, 2024

Conversation

kkafar
Copy link
Member

@kkafar kkafar commented Jun 20, 2024

Description

My recent PR:

introduced creation of dummy layout, which requires react context to be attached to activity, as we need access
to the activity. Unfortunately when running on Paper the context is not attached to the activity yet, resulting
in exception being thrown.

Exception
Failed to create NativeModule 'UIManager'
    java.lang.IllegalArgumentException: [RNScreens] Attempt to use context detached from activity
        at com.swmansion.rnscreens.utils.ScreenDummyLayoutHelper.ensureDummyLayoutWithHeader(ScreenDummyLayoutHelper.kt:68)
        at com.swmansion.rnscreens.utils.ScreenDummyLayoutHelper.<init>(ScreenDummyLayoutHelper.kt:53)
        at com.swmansion.rnscreens.RNScreensPackage.createViewManagers(RNScreensPackage.kt:28)
        at com.facebook.react.ReactInstanceManager.getOrCreateViewManagers(ReactInstanceManager.java:933)
        at com.swmansion.reanimated.ReanimatedPackage.createUIManager(ReanimatedPackage.java:78)
        at com.swmansion.reanimated.ReanimatedPackage.getModule(ReanimatedPackage.java:38)
        at com.facebook.react.BaseReactPackage$ModuleHolderProvider.get(BaseReactPackage.java:156)
        at com.facebook.react.BaseReactPackage$ModuleHolderProvider.get(BaseReactPackage.java:144)
        at com.facebook.react.bridge.ModuleHolder.create(ModuleHolder.java:186)
        at com.facebook.react.bridge.ModuleHolder.getModule(ModuleHolder.java:151)
        at com.facebook.react.bridge.NativeModuleRegistry.getModule(NativeModuleRegistry.java:148)
        at com.facebook.react.bridge.CatalystInstanceImpl.getNativeModule(CatalystInstanceImpl.java:469)
        at com.facebook.react.bridge.CatalystInstanceImpl.getNativeModule(CatalystInstanceImpl.java:445)
        at com.facebook.react.uimanager.UIManagerHelper.getUIManager(UIManagerHelper.java:88)
        at com.facebook.react.uimanager.UIManagerHelper.getUIManager(UIManagerHelper.java:46)
        at com.facebook.react.ReactInstanceManager.attachRootViewToInstance(ReactInstanceManager.java:1231)
        at com.facebook.react.ReactInstanceManager.setupReactContext(ReactInstanceManager.java:1180)
        at com.facebook.react.ReactInstanceManager.lambda$runCreateReactContextOnNewThread$1(ReactInstanceManager.java:1143)
        at com.facebook.react.ReactInstanceManager.$r8$lambda$FD-H2RG7CdgXPtYJUBikxLbd8MA(Unknown Source:0)
        at com.facebook.react.ReactInstanceManager$$ExternalSyntheticLambda4.run(Unknown Source:4)
        at android.os.Handler.handleCallback(Handler.java:958)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
        at android.os.Looper.loopOnce(Looper.java:205)
        at android.os.Looper.loop(Looper.java:294)
        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:233)

I'll need to sort that out when working on fix for jumping content on Android + Paper combination, however right now
it is more important for examples to work correctly.

Changes

Creating ScreenDummyLayoutHelper now only when running on new architecture.

Test code and steps to reproduce

Run TestsExample w/o this change, you will see the exception being thrown -> resulting in freeze on whitescreen.
With this change the example runs normally.

Checklist

  • Ensured that CI passes

@WoLewicki
Copy link
Member

So this exception is thrown always on Paper? Does it mean we did not test if the previous PR works correctly with old arch?

@kkafar
Copy link
Member Author

kkafar commented Jun 21, 2024

Yep, the #2169 wasn't supposed to impact Paper in any way, so I only builded the TestsExample w/o testing the runtime.

@WoLewicki
Copy link
Member

Ok so it's another example that we need the e2e tests to work correctly 😅

@kkafar
Copy link
Member Author

kkafar commented Jun 21, 2024

Yeah, +1.

There is this possible fix in works:

#2196

but we'll see whether it works out.

@kkafar kkafar merged commit 0405de1 into main Jun 21, 2024
4 checks passed
@kkafar kkafar deleted the @kkafar/fix-paper-examples branch June 21, 2024 09:05
alduzy pushed a commit that referenced this pull request Jun 28, 2024
…text (#2199)

## Description

My recent PR:

* #2169

introduced creation of dummy layout, which requires react context to be
attached to activity, as we need access
to the activity. Unfortunately when running on Paper the context is not
attached to the activity yet, resulting
in exception being thrown.

<details>
    <summary>Exception</summary>

```
Failed to create NativeModule 'UIManager'
    java.lang.IllegalArgumentException: [RNScreens] Attempt to use context detached from activity
        at com.swmansion.rnscreens.utils.ScreenDummyLayoutHelper.ensureDummyLayoutWithHeader(ScreenDummyLayoutHelper.kt:68)
        at com.swmansion.rnscreens.utils.ScreenDummyLayoutHelper.<init>(ScreenDummyLayoutHelper.kt:53)
        at com.swmansion.rnscreens.RNScreensPackage.createViewManagers(RNScreensPackage.kt:28)
        at com.facebook.react.ReactInstanceManager.getOrCreateViewManagers(ReactInstanceManager.java:933)
        at com.swmansion.reanimated.ReanimatedPackage.createUIManager(ReanimatedPackage.java:78)
        at com.swmansion.reanimated.ReanimatedPackage.getModule(ReanimatedPackage.java:38)
        at com.facebook.react.BaseReactPackage$ModuleHolderProvider.get(BaseReactPackage.java:156)
        at com.facebook.react.BaseReactPackage$ModuleHolderProvider.get(BaseReactPackage.java:144)
        at com.facebook.react.bridge.ModuleHolder.create(ModuleHolder.java:186)
        at com.facebook.react.bridge.ModuleHolder.getModule(ModuleHolder.java:151)
        at com.facebook.react.bridge.NativeModuleRegistry.getModule(NativeModuleRegistry.java:148)
        at com.facebook.react.bridge.CatalystInstanceImpl.getNativeModule(CatalystInstanceImpl.java:469)
        at com.facebook.react.bridge.CatalystInstanceImpl.getNativeModule(CatalystInstanceImpl.java:445)
        at com.facebook.react.uimanager.UIManagerHelper.getUIManager(UIManagerHelper.java:88)
        at com.facebook.react.uimanager.UIManagerHelper.getUIManager(UIManagerHelper.java:46)
        at com.facebook.react.ReactInstanceManager.attachRootViewToInstance(ReactInstanceManager.java:1231)
        at com.facebook.react.ReactInstanceManager.setupReactContext(ReactInstanceManager.java:1180)
        at com.facebook.react.ReactInstanceManager.lambda$runCreateReactContextOnNewThread$1(ReactInstanceManager.java:1143)
        at com.facebook.react.ReactInstanceManager.$r8$lambda$FD-H2RG7CdgXPtYJUBikxLbd8MA(Unknown Source:0)
        at com.facebook.react.ReactInstanceManager$$ExternalSyntheticLambda4.run(Unknown Source:4)
        at android.os.Handler.handleCallback(Handler.java:958)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
        at android.os.Looper.loopOnce(Looper.java:205)
        at android.os.Looper.loop(Looper.java:294)
        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:233)
```

</details>

I'll need to sort that out when working on fix for jumping content on
Android + Paper combination, however right now
it is more important for examples to work correctly.

## Changes

Creating `ScreenDummyLayoutHelper` now only when running on new
architecture.

## Test code and steps to reproduce

Run `TestsExample` w/o this change, you will see the exception being
thrown -> resulting in freeze on whitescreen.
With this change the example runs normally.

## Checklist

- [x] Ensured that CI passes
ja1ns pushed a commit to WiseOwlTech/react-native-screens that referenced this pull request Oct 9, 2024
…text (software-mansion#2199)

## Description

My recent PR:

* software-mansion#2169

introduced creation of dummy layout, which requires react context to be
attached to activity, as we need access
to the activity. Unfortunately when running on Paper the context is not
attached to the activity yet, resulting
in exception being thrown.

<details>
    <summary>Exception</summary>

```
Failed to create NativeModule 'UIManager'
    java.lang.IllegalArgumentException: [RNScreens] Attempt to use context detached from activity
        at com.swmansion.rnscreens.utils.ScreenDummyLayoutHelper.ensureDummyLayoutWithHeader(ScreenDummyLayoutHelper.kt:68)
        at com.swmansion.rnscreens.utils.ScreenDummyLayoutHelper.<init>(ScreenDummyLayoutHelper.kt:53)
        at com.swmansion.rnscreens.RNScreensPackage.createViewManagers(RNScreensPackage.kt:28)
        at com.facebook.react.ReactInstanceManager.getOrCreateViewManagers(ReactInstanceManager.java:933)
        at com.swmansion.reanimated.ReanimatedPackage.createUIManager(ReanimatedPackage.java:78)
        at com.swmansion.reanimated.ReanimatedPackage.getModule(ReanimatedPackage.java:38)
        at com.facebook.react.BaseReactPackage$ModuleHolderProvider.get(BaseReactPackage.java:156)
        at com.facebook.react.BaseReactPackage$ModuleHolderProvider.get(BaseReactPackage.java:144)
        at com.facebook.react.bridge.ModuleHolder.create(ModuleHolder.java:186)
        at com.facebook.react.bridge.ModuleHolder.getModule(ModuleHolder.java:151)
        at com.facebook.react.bridge.NativeModuleRegistry.getModule(NativeModuleRegistry.java:148)
        at com.facebook.react.bridge.CatalystInstanceImpl.getNativeModule(CatalystInstanceImpl.java:469)
        at com.facebook.react.bridge.CatalystInstanceImpl.getNativeModule(CatalystInstanceImpl.java:445)
        at com.facebook.react.uimanager.UIManagerHelper.getUIManager(UIManagerHelper.java:88)
        at com.facebook.react.uimanager.UIManagerHelper.getUIManager(UIManagerHelper.java:46)
        at com.facebook.react.ReactInstanceManager.attachRootViewToInstance(ReactInstanceManager.java:1231)
        at com.facebook.react.ReactInstanceManager.setupReactContext(ReactInstanceManager.java:1180)
        at com.facebook.react.ReactInstanceManager.lambda$runCreateReactContextOnNewThread$1(ReactInstanceManager.java:1143)
        at com.facebook.react.ReactInstanceManager.$r8$lambda$FD-H2RG7CdgXPtYJUBikxLbd8MA(Unknown Source:0)
        at com.facebook.react.ReactInstanceManager$$ExternalSyntheticLambda4.run(Unknown Source:4)
        at android.os.Handler.handleCallback(Handler.java:958)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
        at android.os.Looper.loopOnce(Looper.java:205)
        at android.os.Looper.loop(Looper.java:294)
        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:233)
```

</details>

I'll need to sort that out when working on fix for jumping content on
Android + Paper combination, however right now
it is more important for examples to work correctly.

## Changes

Creating `ScreenDummyLayoutHelper` now only when running on new
architecture.

## Test code and steps to reproduce

Run `TestsExample` w/o this change, you will see the exception being
thrown -> resulting in freeze on whitescreen.
With this change the example runs normally.

## Checklist

- [x] Ensured that CI passes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants