Fix stream action spacing branches

This commit is contained in:
Mohamed Boudra
2026-04-22 15:49:00 +07:00
parent e4badd95f4
commit 6601db2673
2 changed files with 46 additions and 28 deletions
@@ -89,20 +89,33 @@ const isSameAssistantBlockGroup = (params: {
params.item.blockGroupId !== undefined &&
params.item.blockGroupId === params.other.blockGroupId;
const isAssistantBlockFragment = (params: {
const getAssistantBlockSpacing = (params: {
item: StreamItem;
aboveItem: StreamItem | null | undefined;
belowItem: StreamItem | null | undefined;
}) =>
params.item.kind === "assistant_message" &&
(isSameAssistantBlockGroup({
}): "default" | "compactTop" | "compactBottom" | "compactBoth" => {
if (params.item.kind !== "assistant_message") {
return "default";
}
const compactTop = isSameAssistantBlockGroup({
item: params.item,
other: params.aboveItem,
}) ||
isSameAssistantBlockGroup({
item: params.item,
other: params.belowItem,
}));
});
const compactBottom = isSameAssistantBlockGroup({
item: params.item,
other: params.belowItem,
});
if (compactTop && compactBottom) {
return "compactBoth";
}
if (compactTop) {
return "compactTop";
}
if (compactBottom) {
return "compactBottom";
}
return "default";
};
export interface AgentStreamViewHandle {
scrollToBottom(reason?: BottomAnchorLocalRequest["reason"]): void;
prepareForViewportChange(): void;
@@ -373,13 +386,11 @@ const AgentStreamViewComponent = forwardRef<AgentStreamViewHandle, AgentStreamVi
index,
relation: "below",
});
const spacing = isAssistantBlockFragment({
const spacing = getAssistantBlockSpacing({
item,
aboveItem,
belowItem,
})
? "compact"
: "default";
});
return (
<AssistantMessage
message={item.text}
@@ -518,12 +529,7 @@ const AgentStreamViewComponent = forwardRef<AgentStreamViewHandle, AgentStreamVi
return (
<View style={[stylesheet.streamItemWrapper, { marginBottom: gapBelow }]}>
{content}
{isEndOfAssistantTurn ? (
<TurnCopyButton
getContent={getTurnContent}
containerStyle={stylesheet.assistantTurnCopyButton}
/>
) : null}
{isEndOfAssistantTurn ? <TurnCopyButton getContent={getTurnContent} /> : null}
</View>
);
},
@@ -636,7 +642,11 @@ const AgentStreamViewComponent = forwardRef<AgentStreamViewHandle, AgentStreamVi
<View
style={[
stylesheet.listHeaderContent,
boundary.hasLiveHead ? { paddingTop: looseGap } : null,
boundary.hasLiveHead
? streamRenderStrategy.getFlatListInverted()
? { paddingBottom: looseGap }
: { paddingTop: looseGap }
: null,
]}
>
{auxiliary.pendingPermissions}
@@ -644,7 +654,13 @@ const AgentStreamViewComponent = forwardRef<AgentStreamViewHandle, AgentStreamVi
</View>
</View>
);
}, [auxiliary.pendingPermissions, auxiliary.workingIndicator, boundary.hasLiveHead, looseGap]);
}, [
auxiliary.pendingPermissions,
auxiliary.workingIndicator,
boundary.hasLiveHead,
looseGap,
streamRenderStrategy,
]);
const renderers = useMemo<StreamSegmentRenderers>(
() => ({
@@ -1049,9 +1065,6 @@ const stylesheet = StyleSheet.create((theme) => ({
listHeaderContent: {
gap: theme.spacing[3],
},
assistantTurnCopyButton: {
marginTop: theme.spacing[3],
},
bottomBarWrapper: {
flexDirection: "row",
alignItems: "center",
+9 -4
View File
@@ -433,7 +433,7 @@ interface AssistantMessageProps {
serverId?: string;
client?: DaemonClient | null;
disableOuterSpacing?: boolean;
spacing?: "default" | "compact";
spacing?: "default" | "compactTop" | "compactBottom" | "compactBoth";
}
export const assistantMessageStylesheet = StyleSheet.create((theme) => ({
@@ -441,8 +441,10 @@ export const assistantMessageStylesheet = StyleSheet.create((theme) => ({
paddingHorizontal: theme.spacing[2],
paddingVertical: theme.spacing[3],
},
containerCompactVertical: {
containerCompactTop: {
paddingTop: 0,
},
containerCompactBottom: {
paddingBottom: 0,
},
containerSpacing: {
@@ -1107,7 +1109,7 @@ export const AssistantMessage = memo(function AssistantMessage({
}: AssistantMessageProps) {
const { theme } = useUnistyles();
const resolvedDisableOuterSpacing = useDisableOuterSpacing(
disableOuterSpacing ?? spacing === "compact",
disableOuterSpacing ?? spacing !== "default",
);
const markdownStyles = useMemo(() => createMarkdownStyles(theme), [theme]);
@@ -1309,7 +1311,10 @@ export const AssistantMessage = memo(function AssistantMessage({
testID="assistant-message"
style={[
assistantMessageStylesheet.container,
spacing === "compact" && assistantMessageStylesheet.containerCompactVertical,
(spacing === "compactTop" || spacing === "compactBoth") &&
assistantMessageStylesheet.containerCompactTop,
(spacing === "compactBottom" || spacing === "compactBoth") &&
assistantMessageStylesheet.containerCompactBottom,
!resolvedDisableOuterSpacing && assistantMessageStylesheet.containerSpacing,
]}
>