Skip to content

Commit

Permalink
Extend Fabric measure function to support attachment positions parame…
Browse files Browse the repository at this point in the history
…ters

Summary:
This diff changes the Fabric measure API in order to support attachments parameters

changelog: [internal]

Reviewed By: JoshuaGross

Differential Revision: D20087252

fbshipit-source-id: 20e1526aaa3695d38d0805416df8a32adb8296ad
  • Loading branch information
mdvacca authored and facebook-github-bot committed Feb 25, 2020
1 parent af5ecb2 commit 8bc7ad6
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,32 @@ private long measure(
float maxWidth,
float minHeight,
float maxHeight) {
return measure(
rootTag,
componentName,
localData,
props,
state,
minWidth,
maxWidth,
minHeight,
maxHeight,
null);
}

@DoNotStrip
@SuppressWarnings("unused")
private long measure(
int rootTag,
String componentName,
ReadableMap localData,
ReadableMap props,
ReadableMap state,
float minWidth,
float maxWidth,
float minHeight,
float maxHeight,
@Nullable int[] attachmentsPositions) {
ReactContext context =
rootTag < 0 ? mReactApplicationContext : mReactContextForRootTag.get(rootTag);
return mMountingManager.measure(
Expand All @@ -440,7 +466,8 @@ private long measure(
getYogaSize(minWidth, maxWidth),
getYogaMeasureMode(minWidth, maxWidth),
getYogaSize(minHeight, maxHeight),
getYogaMeasureMode(minHeight, maxHeight));
getYogaMeasureMode(minHeight, maxHeight),
attachmentsPositions);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -518,11 +518,21 @@ public long measure(
float width,
@NonNull YogaMeasureMode widthMode,
float height,
@NonNull YogaMeasureMode heightMode) {
@NonNull YogaMeasureMode heightMode,
@Nullable int[] attachmentsPositions) {

return mViewManagerRegistry
.get(componentName)
.measure(context, localData, props, state, width, widthMode, height, heightMode);
.measure(
context,
localData,
props,
state,
width,
widthMode,
height,
heightMode,
attachmentsPositions);
}

@AnyThread
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,28 @@ public Map<String, String> getNativeProps() {
return null;
}

/**
* Subclasses can override this method to implement custom measure functions for the ViewManager
*
* @param context {@link com.facebook.react.bridge.ReactContext} used for the view.
* @param localData {@link ReadableMap} containing "local data" defined in C++
* @param props {@link ReadableMap} containing JS props
* @param state {@link ReadableMap} containing state defined in C++
* @param width width of the view (usually zero)
* @param widthMode widthMode used during calculation of layout
* @param height height of the view (usually zero)
* @param heightMode widthMode used during calculation of layout
* @param attachmentsPositions {@link int[]} array containing 2x times the amount of attachments
* of the view. An attachment represents the position of an inline view that needs to be
* rendered inside a component and it requires the content of the parent view in order to be
* positioned. This array is meant to be used by the platform to RETURN the position of each
* attachment, as a result of the calculation of layout. (e.g. this array is used to measure
* inlineViews that are rendered inside Text components). On most of the components this array
* will be contain a null value.
* <p>Even values will represent the TOP of each attachment, Odd values represent the LEFT of
* each attachment.
* @return result of calculation of layout for the arguments received as a parameter.
*/
public long measure(
Context context,
ReadableMap localData,
Expand All @@ -295,7 +317,8 @@ public long measure(
float width,
YogaMeasureMode widthMode,
float height,
YogaMeasureMode heightMode) {
YogaMeasureMode heightMode,
@Nullable int[] attachmentsPositions) {
return 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,8 @@ public long measure(
float width,
YogaMeasureMode widthMode,
float height,
YogaMeasureMode heightMode) {
YogaMeasureMode heightMode,
@Nullable int[] attachmentsPositions) {
SeekBar reactSlider = new ReactSlider(context, null, STYLE);
final int spec =
View.MeasureSpec.makeMeasureSpec(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ public long measure(
float width,
YogaMeasureMode widthMode,
float height,
YogaMeasureMode heightMode) {
YogaMeasureMode heightMode,
@Nullable int[] attachmentsPositions) {
ReactSwitch view = new ReactSwitch(context);
view.setShowText(false);
int measureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ public long measure(
float width,
YogaMeasureMode widthMode,
float height,
YogaMeasureMode heightMode) {
YogaMeasureMode heightMode,
@Nullable int[] attachmentsPositions) {

return TextLayoutManager.measureText(
context,
Expand Down

0 comments on commit 8bc7ad6

Please sign in to comment.