mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Pass layout constraints in to startSurface()
Summary: Scheduler.startSurface accepts LayoutConstraints and LayoutContext, but for some reason we don't use these on Android. This diff adds new methods to Binding and FabricUIManager to start a surface with the provided measurespecs. I created new methods to avoid affecting the functionality of any surfaces already using Fabric, but if we want this behavior everywhere then I can just add it to the existing `addRootView` and `startSurface`. Reviewed By: JoshuaGross, shergin Differential Revision: D15810990 fbshipit-source-id: 6cd9a58b125461f91253458905405298cfb723ce
This commit is contained in:
committed by
Facebook Github Bot
parent
d789bb80c3
commit
1de206f36f
@@ -41,6 +41,8 @@ public class Binding {
|
||||
|
||||
public native void startSurface(int surfaceId, String moduleName, NativeMap initialProps);
|
||||
|
||||
public native void startSurfaceWithConstraints(int surfaceId, String moduleName, NativeMap initialProps, float minWidth, float maxWidth, float minHeight, float maxHeight);
|
||||
|
||||
public native void renderTemplateToSurface(int surfaceId, String uiTemplate);
|
||||
|
||||
public native void stopSurface(int surfaceId);
|
||||
|
||||
@@ -130,23 +130,33 @@ public class FabricUIManager implements UIManager, LifecycleEventListener {
|
||||
@Override
|
||||
public <T extends View> int addRootView(
|
||||
final T rootView, final WritableMap initialProps, final @Nullable String initialUITemplate) {
|
||||
return addRootView(rootView, ((ReactRoot) rootView).getJSModuleName(), initialProps, initialUITemplate);
|
||||
}
|
||||
|
||||
public <T extends View> int addRootView(
|
||||
final T rootView, final String moduleName, final WritableMap initialProps, final @Nullable String initialUITemplate) {
|
||||
final int rootTag = ReactRootViewTagGenerator.getNextRootViewTag();
|
||||
ThemedReactContext reactContext =
|
||||
new ThemedReactContext(mReactApplicationContext, rootView.getContext());
|
||||
mMountingManager.addRootView(rootTag, rootView);
|
||||
mReactContextForRootTag.put(rootTag, reactContext);
|
||||
mBinding.startSurface(rootTag, moduleName, (NativeMap) initialProps);
|
||||
mBinding.startSurface(rootTag, ((ReactRoot) rootView).getJSModuleName(), (NativeMap) initialProps);
|
||||
if (initialUITemplate != null) {
|
||||
mBinding.renderTemplateToSurface(rootTag, initialUITemplate);
|
||||
}
|
||||
return rootTag;
|
||||
}
|
||||
|
||||
public <T extends View> int addRootView(
|
||||
final T rootView, final String moduleName, final WritableMap initialProps, int widthMeasureSpec, int heightMeasureSpec) {
|
||||
final int rootTag = ReactRootViewTagGenerator.getNextRootViewTag();
|
||||
ThemedReactContext reactContext =
|
||||
new ThemedReactContext(mReactApplicationContext, rootView.getContext());
|
||||
mMountingManager.addRootView(rootTag, rootView);
|
||||
mReactContextForRootTag.put(rootTag, reactContext);
|
||||
mBinding.startSurfaceWithConstraints(rootTag, moduleName, (NativeMap) initialProps,
|
||||
getMinSize(widthMeasureSpec),
|
||||
getMaxSize(widthMeasureSpec),
|
||||
getMinSize(heightMeasureSpec),
|
||||
getMaxSize(heightMeasureSpec));
|
||||
return rootTag;
|
||||
}
|
||||
|
||||
/** Method called when an event has been dispatched on the C++ side. */
|
||||
@DoNotStrip
|
||||
@SuppressWarnings("unused")
|
||||
|
||||
@@ -57,6 +57,35 @@ void Binding::startSurface(
|
||||
}
|
||||
}
|
||||
|
||||
void Binding::startSurfaceWithConstraints(
|
||||
jint surfaceId,
|
||||
jni::alias_ref<jstring> moduleName,
|
||||
NativeMap *initialProps,
|
||||
jfloat minWidth,
|
||||
jfloat maxWidth,
|
||||
jfloat minHeight,
|
||||
jfloat maxHeight) {
|
||||
if (scheduler_) {
|
||||
auto minimumSize =
|
||||
Size{minWidth / pointScaleFactor_, minHeight / pointScaleFactor_};
|
||||
auto maximumSize =
|
||||
Size{maxWidth / pointScaleFactor_, maxHeight / pointScaleFactor_};
|
||||
|
||||
LayoutContext context;
|
||||
context.pointScaleFactor = {pointScaleFactor_};
|
||||
LayoutConstraints constraints = {};
|
||||
constraints.minimumSize = minimumSize;
|
||||
constraints.maximumSize = maximumSize;
|
||||
|
||||
scheduler_->startSurface(
|
||||
surfaceId,
|
||||
moduleName->toStdString(),
|
||||
initialProps->consume(),
|
||||
constraints,
|
||||
context);
|
||||
}
|
||||
}
|
||||
|
||||
void Binding::renderTemplateToSurface(jint surfaceId, jstring uiTemplate) {
|
||||
SystraceSection s("FabricUIManagerBinding::renderTemplateToSurface");
|
||||
if (scheduler_) {
|
||||
@@ -571,6 +600,8 @@ void Binding::registerNatives() {
|
||||
makeNativeMethod(
|
||||
"installFabricUIManager", Binding::installFabricUIManager),
|
||||
makeNativeMethod("startSurface", Binding::startSurface),
|
||||
makeNativeMethod(
|
||||
"startSurfaceWithConstraints", Binding::startSurfaceWithConstraints),
|
||||
makeNativeMethod(
|
||||
"renderTemplateToSurface", Binding::renderTemplateToSurface),
|
||||
makeNativeMethod("stopSurface", Binding::stopSurface),
|
||||
|
||||
@@ -21,7 +21,7 @@ class Instance;
|
||||
|
||||
class Binding : public jni::HybridClass<Binding>, public SchedulerDelegate {
|
||||
public:
|
||||
constexpr static const char* const kJavaDescriptor =
|
||||
constexpr static const char *const kJavaDescriptor =
|
||||
"Lcom/facebook/react/fabric/Binding;";
|
||||
|
||||
static void registerNatives();
|
||||
@@ -55,6 +55,15 @@ class Binding : public jni::HybridClass<Binding>, public SchedulerDelegate {
|
||||
jni::alias_ref<jstring> moduleName,
|
||||
NativeMap *initialProps);
|
||||
|
||||
void startSurfaceWithConstraints(
|
||||
jint surfaceId,
|
||||
jni::alias_ref<jstring> moduleName,
|
||||
NativeMap *initialProps,
|
||||
jfloat minWidth,
|
||||
jfloat maxWidth,
|
||||
jfloat minHeight,
|
||||
jfloat maxHeight);
|
||||
|
||||
void renderTemplateToSurface(jint surfaceId, jstring uiTemplate);
|
||||
|
||||
void stopSurface(jint surfaceId);
|
||||
|
||||
Reference in New Issue
Block a user