-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Android: Introduce RN$LegacyInterop_UIManager_getConstants (#38153)
Summary: Pull Request resolved: #38153 This diff adds Android specific implementation of `RN$LegacyInterop_UIManager_getConstants` and binds it to JS runtime. It is supposed to be used as a substitute to UIManager.getConstants in bridgeless mode. Changelog: [Internal] - Introduce RN$LegacyInterop_UIManager_getConstants in Android. Reviewed By: RSNara Differential Revision: D45773342 fbshipit-source-id: 194aa5e940743b4d2c242798764a4207e8b1334f
- Loading branch information
1 parent
6eeb81a
commit f7f5b49
Showing
11 changed files
with
238 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...t-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIConstantsProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package com.facebook.react.uimanager; | ||
|
||
import com.facebook.proguard.annotations.DoNotStripAny; | ||
import com.facebook.react.bridge.NativeMap; | ||
|
||
@DoNotStripAny | ||
public interface UIConstantsProvider { | ||
|
||
/* Returns UIManager's constants. */ | ||
NativeMap getConstants(); | ||
} |
41 changes: 41 additions & 0 deletions
41
...e/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIConstantsProviderManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package com.facebook.react.uimanager; | ||
|
||
import com.facebook.jni.HybridData; | ||
import com.facebook.proguard.annotations.DoNotStrip; | ||
import com.facebook.proguard.annotations.DoNotStripAny; | ||
import com.facebook.react.bridge.RuntimeExecutor; | ||
import com.facebook.soloader.SoLoader; | ||
|
||
@DoNotStripAny | ||
public class UIConstantsProviderManager { | ||
|
||
static { | ||
staticInit(); | ||
} | ||
|
||
@DoNotStrip | ||
@SuppressWarnings("unused") | ||
private final HybridData mHybridData; | ||
|
||
public UIConstantsProviderManager( | ||
RuntimeExecutor runtimeExecutor, Object uiConstantsProviderManager) { | ||
mHybridData = initHybrid(runtimeExecutor, uiConstantsProviderManager); | ||
installJSIBindings(); | ||
} | ||
|
||
private native HybridData initHybrid( | ||
RuntimeExecutor runtimeExecutor, Object uiConstantsProviderManager); | ||
|
||
private native void installJSIBindings(); | ||
|
||
private static void staticInit() { | ||
SoLoader.loadLibrary("uimanagerjni"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...ges/react-native/ReactAndroid/src/main/jni/react/uimanager/UIConstantsProviderManager.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* 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 <string> | ||
|
||
#include <fbjni/fbjni.h> | ||
#include <jsi/JSIDynamic.h> | ||
#include <jsi/jsi.h> | ||
#include <react/jni/NativeMap.h> | ||
|
||
#include <react/bridgeless/nativeviewconfig/LegacyUIManagerConstantsProviderBinding.h> | ||
#include "UIConstantsProviderManager.h" | ||
|
||
namespace facebook::react { | ||
|
||
using namespace facebook::jni; | ||
|
||
UIConstantsProviderManager::UIConstantsProviderManager( | ||
jni::alias_ref<UIConstantsProviderManager::javaobject> jThis, | ||
RuntimeExecutor runtimeExecutor, | ||
jni::alias_ref<jobject> uiConstantsProvider) | ||
: javaPart_(jni::make_global(jThis)), | ||
runtimeExecutor_(runtimeExecutor), | ||
uiConstantsProvider_(jni::make_global(uiConstantsProvider)) {} | ||
|
||
jni::local_ref<UIConstantsProviderManager::jhybriddata> | ||
UIConstantsProviderManager::initHybrid( | ||
jni::alias_ref<jhybridobject> jThis, | ||
jni::alias_ref<JRuntimeExecutor::javaobject> runtimeExecutor, | ||
jni::alias_ref<jobject> uiConstantsProvider) { | ||
return makeCxxInstance( | ||
jThis, runtimeExecutor->cthis()->get(), uiConstantsProvider); | ||
} | ||
|
||
void UIConstantsProviderManager::registerNatives() { | ||
registerHybrid({ | ||
makeNativeMethod("initHybrid", UIConstantsProviderManager::initHybrid), | ||
makeNativeMethod( | ||
"installJSIBindings", UIConstantsProviderManager::installJSIBindings), | ||
}); | ||
} | ||
|
||
void UIConstantsProviderManager::installJSIBindings() { | ||
runtimeExecutor_([thizz = this](jsi::Runtime &runtime) { | ||
auto uiConstantsProvider = [thizz, &runtime]() -> jsi::Value { | ||
static auto getConstants = | ||
jni::findClassStatic( | ||
UIConstantsProviderManager::UIConstantsProviderJavaDescriptor) | ||
->getMethod<jni::alias_ref<NativeMap::jhybridobject>()>( | ||
"getConstants"); | ||
auto constants = getConstants(thizz->uiConstantsProvider_.get()); | ||
return jsi::valueFromDynamic(runtime, constants->cthis()->consume()); | ||
}; | ||
|
||
LegacyUIManagerConstantsProviderBinding::install( | ||
runtime, std::move(uiConstantsProvider)); | ||
}); | ||
} | ||
|
||
} // namespace facebook::react |
47 changes: 47 additions & 0 deletions
47
packages/react-native/ReactAndroid/src/main/jni/react/uimanager/UIConstantsProviderManager.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* 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 <ReactCommon/RuntimeExecutor.h> | ||
#include <fbjni/fbjni.h> | ||
#include <react/jni/JRuntimeExecutor.h> | ||
|
||
namespace facebook::react { | ||
|
||
class UIConstantsProviderManager | ||
: public facebook::jni::HybridClass<UIConstantsProviderManager> { | ||
public: | ||
static auto constexpr kJavaDescriptor = | ||
"Lcom/facebook/react/uimanager/UIConstantsProviderManager;"; | ||
|
||
constexpr static auto UIConstantsProviderJavaDescriptor = | ||
"com/facebook/react/uimanager/UIConstantsProvider"; | ||
|
||
static facebook::jni::local_ref<jhybriddata> initHybrid( | ||
facebook::jni::alias_ref<jhybridobject> jThis, | ||
facebook::jni::alias_ref<JRuntimeExecutor::javaobject> runtimeExecutor, | ||
facebook::jni::alias_ref<jobject> uiConstantsProviderManager); | ||
|
||
static void registerNatives(); | ||
|
||
private: | ||
friend HybridBase; | ||
facebook::jni::global_ref<UIConstantsProviderManager::javaobject> javaPart_; | ||
RuntimeExecutor runtimeExecutor_; | ||
|
||
facebook::jni::global_ref<jobject> uiConstantsProvider_; | ||
|
||
void installJSIBindings(); | ||
|
||
explicit UIConstantsProviderManager( | ||
facebook::jni::alias_ref<UIConstantsProviderManager::jhybridobject> jThis, | ||
RuntimeExecutor runtimeExecutor, | ||
facebook::jni::alias_ref<jobject> uiConstantsProviderManager); | ||
}; | ||
|
||
} // namespace facebook::react |
19 changes: 19 additions & 0 deletions
19
packages/react-native/ReactCommon/react/bridgeless/nativeviewconfig/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
|
||
cmake_minimum_required(VERSION 3.13) | ||
set(CMAKE_VERBOSE_MAKEFILE on) | ||
|
||
add_compile_options(-std=c++17) | ||
|
||
file(GLOB_RECURSE bridgeless_nativeviewconfig_SRC CONFIGURE_DEPENDS *.cpp) | ||
add_library( | ||
bridgelessnativeviewconfig | ||
STATIC | ||
${bridgeless_nativeviewconfig_SRC} | ||
) | ||
target_include_directories(bridgelessnativeviewconfig PUBLIC .) | ||
|
||
target_link_libraries(bridgelessnativeviewconfig jsi) |