Skip to content

Commit 4076293

Browse files
mdvaccafacebook-github-bot
authored andcommitted
Fix changes of View visibilities
Summary: The purpose of this diff is to ensure that visibility changes are handled correctly when the value of "display" for a View changes from 'flex' to 'none'. RNTester is nesting several Views with different kind of visibilities. When the user tap on an item there's a state update that changes the visibility styles for some of these views. Fabric does not reflect the right changes of visibility on the screen. changelog: internal Reviewed By: shergin Differential Revision: D25841763 fbshipit-source-id: 769b97afb72939d346a4c6f2669ff938b35596bc
1 parent 50f2dd9 commit 4076293

File tree

4 files changed

+33
-8
lines changed

4 files changed

+33
-8
lines changed

ReactAndroid/src/main/java/com/facebook/react/fabric/jni/Binding.cpp

+7-4
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ static inline int getIntBufferSizeForType(CppMountItem::Type mountItemType) {
102102
} else if (mountItemType == CppMountItem::Type::UpdatePadding) {
103103
return 5; // tag, top, left, bottom, right
104104
} else if (mountItemType == CppMountItem::Type::UpdateLayout) {
105-
return 6; // tag, x, y, w, h, layoutDirection
105+
return 7; // tag, x, y, w, h, layoutDirection, DisplayType
106106
} else if (mountItemType == CppMountItem::Type::UpdateEventEmitter) {
107107
return 1; // tag
108108
} else {
@@ -714,7 +714,7 @@ void Binding::schedulerDidFinishTransaction(
714714
int intBufferPosition = 0;
715715
int objBufferPosition = 0;
716716
int prevMountItemType = -1;
717-
jint temp[6];
717+
jint temp[7];
718718
for (int i = 0; i < cppCommonMountItems.size(); i++) {
719719
const auto &mountItem = cppCommonMountItems[i];
720720
const auto &mountItemType = mountItem.type;
@@ -879,15 +879,18 @@ void Binding::schedulerDidFinishTransaction(
879879
int h = round(frame.size.height * pointScaleFactor);
880880
int layoutDirection =
881881
toInt(mountItem.newChildShadowView.layoutMetrics.layoutDirection);
882+
int displayType =
883+
toInt(mountItem.newChildShadowView.layoutMetrics.displayType);
882884

883885
temp[0] = mountItem.newChildShadowView.tag;
884886
temp[1] = x;
885887
temp[2] = y;
886888
temp[3] = w;
887889
temp[4] = h;
888890
temp[5] = layoutDirection;
889-
env->SetIntArrayRegion(intBufferArray, intBufferPosition, 6, temp);
890-
intBufferPosition += 6;
891+
temp[6] = displayType;
892+
env->SetIntArrayRegion(intBufferArray, intBufferPosition, 7, temp);
893+
intBufferPosition += 7;
891894
}
892895
}
893896
if (cppUpdateEventEmitterMountItems.size() > 0) {

ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountingManager.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ public void updateProps(int reactTag, @Nullable ReadableMap props) {
563563
}
564564

565565
@UiThread
566-
public void updateLayout(int reactTag, int x, int y, int width, int height) {
566+
public void updateLayout(int reactTag, int x, int y, int width, int height, int displayType) {
567567
UiThreadUtil.assertOnUiThread();
568568

569569
ViewState viewState = getViewState(reactTag);
@@ -589,6 +589,12 @@ public void updateLayout(int reactTag, int x, int y, int width, int height) {
589589
// TODO: T31905686 Check if the parent of the view has to layout the view, or the child has
590590
// to lay itself out. see NativeViewHierarchyManager.updateLayout
591591
viewToUpdate.layout(x, y, x + width, y + height);
592+
593+
// displayType: 0 represents display: 'none'
594+
int visibility = displayType == 0 ? View.INVISIBLE : View.VISIBLE;
595+
if (viewToUpdate.getVisibility() != visibility) {
596+
viewToUpdate.setVisibility(visibility);
597+
}
592598
}
593599

594600
@UiThread

ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/IntBufferBatchMountItem.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,16 @@ public void execute(@NonNull MountingManager mountingManager) {
157157
} else if (type == INSTRUCTION_UPDATE_STATE) {
158158
mountingManager.updateState(mIntBuffer[i++], castToState(mObjBuffer[j++]));
159159
} else if (type == INSTRUCTION_UPDATE_LAYOUT) {
160-
mountingManager.updateLayout(
161-
mIntBuffer[i++], mIntBuffer[i++], mIntBuffer[i++], mIntBuffer[i++], mIntBuffer[i++]);
162-
160+
int reactTag = mIntBuffer[i++];
161+
int x = mIntBuffer[i++];
162+
int y = mIntBuffer[i++];
163+
int width = mIntBuffer[i++];
164+
int height = mIntBuffer[i++];
163165
// The final buffer, layoutDirection, seems unused?
164166
i++;
167+
int displayType = mIntBuffer[i++];
168+
mountingManager.updateLayout(reactTag, x, y, width, height, displayType);
169+
165170
} else if (type == INSTRUCTION_UPDATE_PADDING) {
166171
mountingManager.updatePadding(
167172
mIntBuffer[i++], mIntBuffer[i++], mIntBuffer[i++], mIntBuffer[i++], mIntBuffer[i++]);

ReactCommon/react/renderer/core/conversions.h

+11
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ inline int toInt(const LayoutDirection &layoutDirection) {
3434
}
3535
}
3636

37+
inline int toInt(const DisplayType &displayType) {
38+
switch (displayType) {
39+
case DisplayType::None:
40+
return 0;
41+
case DisplayType::Flex:
42+
return 1;
43+
case DisplayType::Inline:
44+
return 2;
45+
}
46+
}
47+
3748
inline std::string toString(const DisplayType &displayType) {
3849
switch (displayType) {
3950
case DisplayType::None:

0 commit comments

Comments
 (0)