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

Unable to get reactContext in MainActivity.kt #47647

Closed
saikrishnanamburi opened this issue Nov 17, 2024 · 5 comments
Closed

Unable to get reactContext in MainActivity.kt #47647

saikrishnanamburi opened this issue Nov 17, 2024 · 5 comments
Labels
Needs: Attention Issues where the author has responded to feedback. Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue.

Comments

@saikrishnanamburi
Copy link

Description

val reactContext: ReactContext? = this.reactNativeHost.reactInstanceManager.currentReactContext
ReactContext: null

Steps to reproduce

npm start

React Native Version

0.76.2

Affected Platforms

Runtime - Android

Output of npx react-native info

System:
  OS: macOS 15.0.1
  CPU: (8) arm64 Apple M3
  Memory: 91.66 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 20.0.0
    path: ~/.nvm/versions/node/v20.0.0/bin/node
  Yarn:
    version: 1.22.22
    path: /opt/homebrew/bin/yarn
  npm:
    version: 9.6.4
    path: ~/.nvm/versions/node/v20.0.0/bin/npm
  Watchman:
    version: 2024.10.21.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.15.2
    path: /opt/homebrew/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 24.0
      - iOS 18.0
      - macOS 15.0
      - tvOS 18.0
      - visionOS 2.0
      - watchOS 11.0
  Android SDK:
    API Levels:
      - "28"
      - "29"
      - "30"
      - "31"
      - "33"
      - "34"
      - "34"
      - "34"
      - "34"
      - "34"
      - "35"
    Build Tools:
      - 28.0.3
      - 30.0.3
      - 31.0.0
      - 33.0.0
      - 33.0.1
      - 33.0.2
      - 34.0.0
      - 35.0.0
    System Images:
      - android-30 | Intel x86 Atom_64
      - android-31 | Intel x86 Atom_64
      - android-33 | Google APIs ARM 64 v8a
    Android NDK: Not Found
IDEs:
  Android Studio: 2024.2 AI-242.23339.11.2421.12483815
  Xcode:
    version: 16.0/16A242d
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.13
    path: /opt/homebrew/opt/openjdk@17/libexec/openjdk.jdk/Contents/Home/bin/javac
  Ruby:
    version: 2.6.10
    path: /usr/bin/ruby
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-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: true
  newArchEnabled: true

Stacktrace or Logs

.

Reproducer

.

Screenshots and Videos

No response

@react-native-bot react-native-bot added Needs: Author Feedback Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. labels Nov 17, 2024
@react-native-bot
Copy link
Collaborator

Warning

Missing reproducer: We could not detect a reproducible example in your issue report. Please provide either:

@javache
Copy link
Member

javache commented Nov 18, 2024

reactInstanceManager is no longer supported in the new architecture. We could expose a currentReactContext on ReactDelegate if that would help you migrate?

javache added a commit to javache/react-native that referenced this issue Nov 18, 2024
Summary:
Fixes facebook#47647

There's no convenient way to access the current react context when using the new architecture. Exposing `getCurrentReactContext` allows for users to migrate without forcing the check downstream. 

Changelog: [Android][Added] ReactDelegate and ReactActivityDelegate#getCurrentReactContext can be used to access the current context

Differential Revision: D66094540
@saikrishnanamburi
Copy link
Author

okay
in which version does this fix gets released

@chenvvy
Copy link

chenvvy commented Jan 22, 2025

reactInstanceManager is no longer supported in the new architecture. We could expose a currentReactContext on ReactDelegate if that would help you migrate?

Is there any way to get reactContext in MainActivity.kt in 0.76.6?

akrupczynskirezolve pushed a commit to Bluedot-Innovation/Bluedot-React-Native-Plugin that referenced this issue Feb 10, 2025
@fgedlek
Copy link

fgedlek commented Feb 12, 2025

@saikrishnanamburi @chenvvy you can get the reactContext from reactActivityDelegate.reactHost.currentReactContext - works on version 0.76.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: Attention Issues where the author has responded to feedback. Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants