mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Fix setting component padding in Fabric
Summary: This diff fixes the issue with view paddings in Fabric introduced in D17081799. In Paper setting padding on a view was only supported for Text and TextInput components (see https://fburl.com/codesearch/6r6lu5vd). We want to keep Fabric backwards compatible, so we delegate setting the padding to the view manager instead of setting it directly on the view. In this way we can have a no-op implementation in the base view manager and implement this method only in view managers that support setting padding (ReactTextInputManager and ReactTextViewManager at the moment). Reviewed By: JoshuaGross Differential Revision: D17665011 fbshipit-source-id: 38bc56278e002bd34881cfcb9ed79df579f79e28
This commit is contained in:
committed by
Facebook Github Bot
parent
601981a67d
commit
769d51824e
@@ -307,7 +307,13 @@ public class MountingManager {
|
||||
throw new IllegalStateException("Unable to find View for tag: " + reactTag);
|
||||
}
|
||||
|
||||
viewToUpdate.setPadding(left, top, right, bottom);
|
||||
ViewManager viewManager = viewState.mViewManager;
|
||||
if (viewManager == null) {
|
||||
throw new IllegalStateException("Unable to find ViewManager for view: " + viewState);
|
||||
}
|
||||
|
||||
//noinspection unchecked
|
||||
viewManager.setPadding(viewToUpdate, left, top, right, bottom);
|
||||
}
|
||||
|
||||
@UiThread
|
||||
|
||||
@@ -297,4 +297,10 @@ public abstract class ViewManager<T extends View, C extends ReactShadowNode>
|
||||
YogaMeasureMode heightMode) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Subclasses can override this method to set padding for the given View in Fabric. Since not all
|
||||
* components support setting padding, the default implementation of this method does nothing.
|
||||
*/
|
||||
public void setPadding(T view, int left, int top, int right, int bottom) {}
|
||||
}
|
||||
|
||||
@@ -123,4 +123,9 @@ public class ReactTextViewManager
|
||||
return TextLayoutManager.measureText(
|
||||
context, localData, props, width, widthMode, height, heightMode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPadding(ReactTextView view, int left, int top, int right, int bottom) {
|
||||
view.setPadding(left, top, right, bottom);
|
||||
}
|
||||
}
|
||||
|
||||
+5
-2
@@ -8,7 +8,6 @@ package com.facebook.react.views.textinput;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.text.Editable;
|
||||
@@ -50,7 +49,6 @@ import com.facebook.react.views.imagehelper.ResourceDrawableIdHelper;
|
||||
import com.facebook.react.views.scroll.ScrollEvent;
|
||||
import com.facebook.react.views.scroll.ScrollEventType;
|
||||
import com.facebook.react.views.text.DefaultStyleValuesUtil;
|
||||
import com.facebook.react.views.text.ReactFontManager;
|
||||
import com.facebook.react.views.text.ReactTextUpdate;
|
||||
import com.facebook.react.views.text.TextInlineImageSpan;
|
||||
import com.facebook.react.views.text.TextLayoutManager;
|
||||
@@ -1042,4 +1040,9 @@ public class ReactTextInputManager extends BaseViewManager<ReactEditText, Layout
|
||||
return TextLayoutManager.measureText(
|
||||
context, localData, props, width, widthMode, height, heightMode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPadding(ReactEditText view, int left, int top, int right, int bottom) {
|
||||
view.setPadding(left, top, right, bottom);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user