mirror of
https://github.com/react/react-native.git
synced 2026-10-06 03:42:45 +08:00
Summary: Updates `ReadableMapBuffer` to conform to `MapBuffer` interface, to allow interchangeable use of `Readable/WritableMapBuffer` in the code. Notable changes: - MapBuffer.Entry getters are now represented as Kotlin properties and appended `Value` suffix (e.g. `entry.getInt()` becomes `entry.getIntValue()` in Java, or `entry.intValue` in Kotlin) - `ByteBuffer` is imported in constructor instead of on demand. This method doesn't copy the data as the bytes are read directly from native heap, and benchmarking a 500-byte `MapBuffer` shows no difference in import speed. - Internal logic of `ReadableMapBuffer` uses `UShort` kotlin type for key retrieval, for more correct representation of values. - Explicit exception throws are replaced with `require` and `check` methods for `IllegalArgumentException` and `IllegalStateException` (default FB conversion). The change also updates `ReadableMapBuffer` usages to `MapBuffer` interface where possible (virtually everywhere except JNI methods). Changelog: [Android][Changed] - Adopt `MapBuffer` interface for `ReadableMapBuffer` Reviewed By: mdvacca Differential Revision: D35218633 fbshipit-source-id: 515dd974c27b2978ade325b2e1750ab8f068a20a
77 lines
2.8 KiB
Java
77 lines
2.8 KiB
Java
/*
|
|
* 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.fabric;
|
|
|
|
import androidx.annotation.NonNull;
|
|
import com.facebook.react.bridge.JSIModuleProvider;
|
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
import com.facebook.react.bridge.UIManager;
|
|
import com.facebook.react.common.mapbuffer.MapBufferSoLoader;
|
|
import com.facebook.react.config.ReactFeatureFlags;
|
|
import com.facebook.react.fabric.events.EventBeatManager;
|
|
import com.facebook.react.uimanager.ViewManagerRegistry;
|
|
import com.facebook.systrace.Systrace;
|
|
|
|
public class FabricJSIModuleProvider implements JSIModuleProvider<UIManager> {
|
|
|
|
@NonNull private final ReactApplicationContext mReactApplicationContext;
|
|
@NonNull private final ComponentFactory mComponentFactory;
|
|
@NonNull private final ReactNativeConfig mConfig;
|
|
@NonNull private final ViewManagerRegistry mViewManagerRegistry;
|
|
|
|
public FabricJSIModuleProvider(
|
|
@NonNull ReactApplicationContext reactApplicationContext,
|
|
@NonNull ComponentFactory componentFactory,
|
|
@NonNull ReactNativeConfig config,
|
|
@NonNull ViewManagerRegistry viewManagerRegistry) {
|
|
mReactApplicationContext = reactApplicationContext;
|
|
mComponentFactory = componentFactory;
|
|
mConfig = config;
|
|
mViewManagerRegistry = viewManagerRegistry;
|
|
}
|
|
|
|
@Override
|
|
public UIManager get() {
|
|
Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "FabricJSIModuleProvider.get");
|
|
final EventBeatManager eventBeatManager = new EventBeatManager(mReactApplicationContext);
|
|
final FabricUIManager uiManager = createUIManager(eventBeatManager);
|
|
|
|
Systrace.beginSection(
|
|
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "FabricJSIModuleProvider.registerBinding");
|
|
final Binding binding = new Binding();
|
|
|
|
if (ReactFeatureFlags.isMapBufferSerializationEnabled()) {
|
|
MapBufferSoLoader.staticInit();
|
|
}
|
|
|
|
binding.register(
|
|
mReactApplicationContext.getCatalystInstance().getRuntimeExecutor(),
|
|
mReactApplicationContext.getCatalystInstance().getRuntimeScheduler(),
|
|
uiManager,
|
|
eventBeatManager,
|
|
mComponentFactory,
|
|
mConfig);
|
|
|
|
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
|
|
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
|
|
|
|
return uiManager;
|
|
}
|
|
|
|
private FabricUIManager createUIManager(@NonNull EventBeatManager eventBeatManager) {
|
|
Systrace.beginSection(
|
|
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "FabricJSIModuleProvider.createUIManager");
|
|
|
|
FabricUIManager fabricUIManager;
|
|
fabricUIManager =
|
|
new FabricUIManager(mReactApplicationContext, mViewManagerRegistry, eventBeatManager);
|
|
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
|
|
return fabricUIManager;
|
|
}
|
|
}
|