Fix flickering footer when inlining causes 1-2px change in width.

This commit is contained in:
Alex Hart
2025-10-15 14:45:29 -03:00
committed by Cody Henthorne
parent cbe72307a0
commit c2d0d80b9f

View File

@@ -181,7 +181,8 @@ public final class ConversationItem extends RelativeLayout implements BindableCo
{
private static final String TAG = Log.tag(ConversationItem.class);
private static final int MAX_MEASURE_CALLS = 3;
private static final int MAX_MEASURE_CALLS = 3;
private static final int FOOTER_POSITION_THRESHOLD = ViewUtil.dpToPx(8);
private static final Rect SWIPE_RECT = new Rect();
@@ -246,6 +247,9 @@ public final class ConversationItem extends RelativeLayout implements BindableCo
private int measureCalls;
private boolean updatingFooter;
private int lastFooterDecisionLineWidth = -1;
private boolean lastFooterWasCollapsed = false;
private final PassthroughClickListener passthroughClickListener = new PassthroughClickListener();
private final AttachmentDownloadClickListener downloadClickListener = new AttachmentDownloadClickListener();
private final PlayVideoClickListener playVideoClickListener = new PlayVideoClickListener();
@@ -582,30 +586,70 @@ public final class ConversationItem extends RelativeLayout implements BindableCo
if (hasQuote(messageRecord) && sizeWithMargins < availableWidth) {
ViewUtil.setTopMargin(footer, collapsedTopMargin, false);
ViewUtil.setBottomMargin(footer, collapsedBottomMargin, false);
needsMeasure = true;
updatingFooter = true;
needsMeasure = true;
updatingFooter = true;
lastFooterWasCollapsed = true;
lastFooterDecisionLineWidth = bodyText.getLastLineWidth();
} else if (sizeWithMargins != bodyText.getMeasuredWidth() && sizeWithMargins <= minSize) {
bodyBubble.getLayoutParams().width = minSize;
ViewUtil.setTopMargin(footer, collapsedTopMargin, false);
ViewUtil.setBottomMargin(footer, collapsedBottomMargin, false);
needsMeasure = true;
updatingFooter = true;
needsMeasure = true;
updatingFooter = true;
lastFooterWasCollapsed = true;
lastFooterDecisionLineWidth = bodyText.getLastLineWidth();
}
}
if (!updatingFooter && !messageRecord.isFailed() && bodyText.getLastLineWidth() + ViewUtil.dpToPx(6) + footerWidth <= bodyText.getMeasuredWidth()) {
ViewUtil.setTopMargin(footer, collapsedTopMargin, false);
ViewUtil.setBottomMargin(footer, collapsedBottomMargin, false);
updatingFooter = true;
needsMeasure = true;
// prevent footer flickering from small measurement variations
if (!updatingFooter && !messageRecord.isFailed()) {
int currentLineWidth = bodyText.getLastLineWidth();
int requiredSpace = currentLineWidth + ViewUtil.dpToPx(6) + footerWidth;
int availableSpace = bodyText.getMeasuredWidth();
boolean lineWidthChangedSlightly = (lastFooterDecisionLineWidth > 0 &&
Math.abs(currentLineWidth - lastFooterDecisionLineWidth) <= FOOTER_POSITION_THRESHOLD);
if (lineWidthChangedSlightly) {
if (lastFooterWasCollapsed && ViewUtil.getTopMargin(footer) != collapsedTopMargin) {
ViewUtil.setTopMargin(footer, collapsedTopMargin, false);
ViewUtil.setBottomMargin(footer, collapsedBottomMargin, false);
updatingFooter = true;
needsMeasure = true;
}
} else {
if (requiredSpace + FOOTER_POSITION_THRESHOLD <= availableSpace) {
ViewUtil.setTopMargin(footer, collapsedTopMargin, false);
ViewUtil.setBottomMargin(footer, collapsedBottomMargin, false);
updatingFooter = true;
needsMeasure = true;
lastFooterWasCollapsed = true;
lastFooterDecisionLineWidth = currentLineWidth;
}
}
}
}
int defaultTopMarginForRecord = getDefaultTopMarginForRecord(messageRecord, defaultTopMargin, defaultBottomMargin);
if (!updatingFooter && ViewUtil.getTopMargin(footer) != defaultTopMarginForRecord) {
ViewUtil.setTopMargin(footer, defaultTopMarginForRecord, false);
ViewUtil.setBottomMargin(footer, defaultBottomMargin, false);
needsMeasure = true;
boolean shouldRevert = true;
if (lastFooterDecisionLineWidth > 0 && bodyText.getLastLineWidth() > 0) {
int currentLineWidth = bodyText.getLastLineWidth();
boolean lineWidthChangedSlightly = Math.abs(currentLineWidth - lastFooterDecisionLineWidth) <= FOOTER_POSITION_THRESHOLD;
if (lineWidthChangedSlightly && lastFooterWasCollapsed) {
shouldRevert = false;
}
}
if (shouldRevert) {
ViewUtil.setTopMargin(footer, defaultTopMarginForRecord, false);
ViewUtil.setBottomMargin(footer, defaultBottomMargin, false);
needsMeasure = true;
lastFooterWasCollapsed = false;
lastFooterDecisionLineWidth = -1;
}
}
if (hasSharedContact(messageRecord)) {