mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Add jni target to ReactCxxPlatform (#51898)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/51898 changelog: [internal] Reviewed By: andrewdacenko Differential Revision: D76240376 fbshipit-source-id: bbae620dde69261e6d26d088471601e7d7e9a074
This commit is contained in:
committed by
Facebook GitHub Bot
parent
89cb7ea600
commit
43ba9df55f
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#include <fbjni/Context.h>
|
||||
#include <fbjni/fbjni.h>
|
||||
|
||||
namespace facebook::react {
|
||||
|
||||
jobject getApplication(JNIEnv* env) {
|
||||
auto activityThreadClass = env->FindClass("android/app/ActivityThread");
|
||||
auto currentApplicationMethodID = env->GetStaticMethodID(
|
||||
activityThreadClass, "currentApplication", "()Landroid/app/Application;");
|
||||
return env->CallStaticObjectMethod(
|
||||
activityThreadClass, currentApplicationMethodID);
|
||||
}
|
||||
|
||||
jni::alias_ref<jni::AContext> getContext() {
|
||||
auto env = facebook::jni::Environment::ensureCurrentThreadIsAttached();
|
||||
auto application = getApplication(env);
|
||||
return facebook::jni::wrap_alias(
|
||||
static_cast<facebook::jni::AContext::javaobject>(application));
|
||||
}
|
||||
|
||||
} // namespace facebook::react
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <fbjni/Context.h>
|
||||
#include <fbjni/fbjni.h>
|
||||
|
||||
namespace facebook::react {
|
||||
|
||||
jobject getApplication(JNIEnv* env);
|
||||
|
||||
jni::alias_ref<jni::AContext> getContext();
|
||||
|
||||
} // namespace facebook::react
|
||||
Reference in New Issue
Block a user