forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make UIConstantsProviderManager a static method (facebook#43615)
Summary: Pull Request resolved: facebook#43615 This class is used for a one-time setup of bindings into the jsi::Runtime. The lambda will retain ownership of any java components required, and we can rely on the teardown of the JS runtime to clean up any dependencies. Changelog: [Internal] Reviewed By: dmytrorykun Differential Revision: D55241233 fbshipit-source-id: f7541f28277307be9b3a5f4f780c7eca1a467c57
- Loading branch information
1 parent
1000093
commit 6f956af
Showing
12 changed files
with
249 additions
and
339 deletions.
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
47 changes: 47 additions & 0 deletions
47
...ive/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIConstantsProviderBinding.kt
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. | ||
*/ | ||
|
||
package com.facebook.react.uimanager | ||
|
||
import com.facebook.proguard.annotations.DoNotStripAny | ||
import com.facebook.react.bridge.NativeMap | ||
import com.facebook.react.bridge.RuntimeExecutor | ||
import com.facebook.soloader.SoLoader | ||
import kotlin.jvm.JvmStatic | ||
|
||
@DoNotStripAny | ||
public object UIConstantsProviderBinding { | ||
init { | ||
SoLoader.loadLibrary("uimanagerjni") | ||
} | ||
|
||
@JvmStatic | ||
public external fun install( | ||
runtimeExecutor: RuntimeExecutor, | ||
defaultEventTypesProvider: DefaultEventTypesProvider, | ||
viewManagerConstantsProvider: ConstantsForViewManagerProvider, | ||
constantsProvider: ConstantsProvider | ||
) | ||
|
||
@DoNotStripAny | ||
public interface DefaultEventTypesProvider { | ||
/* Returns UIManager's constants. */ | ||
fun getDefaultEventTypes(): NativeMap | ||
} | ||
|
||
@DoNotStripAny | ||
public interface ConstantsForViewManagerProvider { | ||
/* Returns UIManager's constants. */ | ||
fun getConstantsForViewManager(viewManagerName: String): NativeMap? | ||
} | ||
|
||
@DoNotStripAny | ||
public interface ConstantsProvider { | ||
/* Returns UIManager's constants. */ | ||
fun getConstants(): NativeMap | ||
} | ||
} |
75 changes: 0 additions & 75 deletions
75
...e/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIConstantsProviderManager.java
This file was deleted.
Oops, something went wrong.
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
66 changes: 66 additions & 0 deletions
66
...ges/react-native/ReactAndroid/src/main/jni/react/uimanager/UIConstantsProviderBinding.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,66 @@ | ||
/* | ||
* 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 "UIConstantsProviderBinding.h" | ||
|
||
#include <jsi/JSIDynamic.h> | ||
#include <jsi/jsi.h> | ||
#include <react/runtime/nativeviewconfig/LegacyUIManagerConstantsProviderBinding.h> | ||
|
||
namespace facebook::react { | ||
|
||
using namespace facebook::jni; | ||
|
||
void UIConstantsProviderBinding::registerNatives() { | ||
javaClassStatic()->registerNatives({ | ||
makeNativeMethod("install", UIConstantsProviderBinding::install), | ||
}); | ||
} | ||
|
||
void UIConstantsProviderBinding::install( | ||
jni::alias_ref<jclass> /* unused */, | ||
jni::alias_ref<JRuntimeExecutor::javaobject> runtimeExecutor, | ||
jni::alias_ref<DefaultEventTypesProvider::javaobject> | ||
defaultExportableEventTypesProvider, | ||
jni::alias_ref<ConstantsForViewManagerProvider::javaobject> | ||
constantsForViewManagerProvider, | ||
jni::alias_ref<ConstantsProvider::javaobject> constantsProvider) { | ||
auto executor = runtimeExecutor->cthis()->get(); | ||
executor([defaultExportableEventTypesProvider = | ||
make_global(defaultExportableEventTypesProvider), | ||
constantsForViewManagerProvider = | ||
make_global(constantsForViewManagerProvider), | ||
constantsProvider = | ||
make_global(constantsProvider)](jsi::Runtime& runtime) mutable { | ||
LegacyUIManagerConstantsProviderBinding::install( | ||
runtime, | ||
"getDefaultEventTypes", | ||
[provider = std::move(defaultExportableEventTypesProvider)]( | ||
jsi::Runtime& runtime) { | ||
return jsi::valueFromDynamic( | ||
runtime, provider->getDefaultEventTypes()); | ||
}); | ||
|
||
LegacyUIManagerConstantsProviderBinding::install( | ||
runtime, | ||
"getConstantsForViewManager", | ||
[provider = std::move(constantsForViewManagerProvider)]( | ||
jsi::Runtime& runtime, const std::string& viewManagerName) { | ||
return jsi::valueFromDynamic( | ||
runtime, provider->getConstantsForViewManager(viewManagerName)); | ||
}); | ||
|
||
LegacyUIManagerConstantsProviderBinding::install( | ||
runtime, | ||
"getConstants", | ||
[provider = std::move(constantsProvider)](jsi::Runtime& runtime) { | ||
return jsi::valueFromDynamic(runtime, provider->getConstants()); | ||
}); | ||
}); | ||
} | ||
|
||
} // namespace facebook::react |
Oops, something went wrong.