Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

ensu ios: trigger rive outro and collapse streaming bubble

Prateek Sunalb4080a05b33d
diff --git a/mobile/native/darwin/Apps/ensu/ensu/Chat/MessageList/MessageListComponents.swift b/mobile/native/darwin/Apps/ensu/ensu/Chat/MessageList/MessageListComponents.swift
index 58eab81141..7871db073d 100644
--- a/mobile/native/darwin/Apps/ensu/ensu/Chat/MessageList/MessageListComponents.swift
+++ b/mobile/native/darwin/Apps/ensu/ensu/Chat/MessageList/MessageListComponents.swift
@@ -219,6 +219,7 @@ private enum StreamingCursor {
struct StreamingBubbleView: View {
let text: String
+ let isGenerating: Bool
@State private var storageId = UUID().uuidString
@@ -227,7 +228,12 @@ struct StreamingBubbleView: View {
HStack(alignment: .bottom) {
VStack(alignment: .leading, spacing: EnsuSpacing.sm) {
- EnsuBrandIllustration(width: 115, height: 52.5)
+ EnsuBrandIllustration(
+ width: 115,
+ height: 52.5,
+ outroTrigger: !isGenerating,
+ outroInputName: "outro"
+ )
if hasText {
TimelineView(.periodic(from: .now, by: 0.55)) { context in
diff --git a/mobile/native/darwin/Apps/ensu/ensu/Chat/MessageListView.swift b/mobile/native/darwin/Apps/ensu/ensu/Chat/MessageListView.swift
index 5eb5d18d79..af9f4a8547 100644
--- a/mobile/native/darwin/Apps/ensu/ensu/Chat/MessageListView.swift
+++ b/mobile/native/darwin/Apps/ensu/ensu/Chat/MessageListView.swift
@@ -26,6 +26,9 @@ struct MessageListView: View {
@State private var lastScrollChange = ScrollChange()
@State private var didInitialScroll = false
@State private var suppressAutoScrollAfterGeneration = false
+ @State private var keepStreamingVisible = false
+ @State private var lastStreamingParentForOutro: UUID?
+ @State private var outroHideWorkItem: DispatchWorkItem?
var body: some View {
GeometryReader { proxy in
@@ -82,13 +85,38 @@ struct MessageListView: View {
scheduleInitialScroll(scrollProxy)
}
.onChange(of: isGenerating) { generating in
- if !generating {
+ if generating {
+ outroHideWorkItem?.cancel()
+ outroHideWorkItem = nil
+ keepStreamingVisible = true
+ lastStreamingParentForOutro = streamingParentId
+ suppressAutoScrollAfterGeneration = false
+ } else {
suppressAutoScrollAfterGeneration = true
- DispatchQueue.main.asyncAfter(deadline: .now() + 1.2) {
+ let workItem = DispatchWorkItem {
+ withAnimation(.easeOut(duration: 0.22)) {
+ keepStreamingVisible = false
+ lastStreamingParentForOutro = nil
+ }
suppressAutoScrollAfterGeneration = false
+ outroHideWorkItem = nil
}
+ outroHideWorkItem?.cancel()
+ outroHideWorkItem = workItem
+ DispatchQueue.main.asyncAfter(deadline: .now() + 1.2, execute: workItem)
}
}
+ .onChange(of: streamingParentId) { parentId in
+ if isGenerating {
+ lastStreamingParentForOutro = parentId
+ }
+ }
+ .onChange(of: sessionId) { _ in
+ outroHideWorkItem?.cancel()
+ outroHideWorkItem = nil
+ keepStreamingVisible = isGenerating
+ lastStreamingParentForOutro = streamingParentId
+ }
}
}
.sheet(item: $previewItem) { item in
@@ -207,21 +235,32 @@ struct MessageListView: View {
.transition(messageTransition)
}
- if isGenerating, streamingParentId == message.id {
- StreamingBubbleView(text: streamingResponse)
+ let showStreamingForMessage =
+ (isGenerating && streamingParentId == message.id) ||
+ (!isGenerating && keepStreamingVisible && lastStreamingParentForOutro == message.id)
+
+ if showStreamingForMessage {
+ StreamingBubbleView(text: streamingResponse, isGenerating: isGenerating)
.id("streaming-\(message.id.uuidString)")
+ .transition(streamingTransition)
}
}
- if isGenerating, streamingParentId == nil {
- StreamingBubbleView(text: streamingResponse)
+ let showRootStreaming =
+ (isGenerating && streamingParentId == nil) ||
+ (!isGenerating && keepStreamingVisible && lastStreamingParentForOutro == nil)
+
+ if showRootStreaming {
+ StreamingBubbleView(text: streamingResponse, isGenerating: isGenerating)
.id("streaming")
+ .transition(streamingTransition)
}
}
.padding(.horizontal, EnsuSpacing.pageHorizontal)
.padding(.top, EnsuSpacing.lg)
.padding(.bottom, EnsuSpacing.lg)
.animation(isGenerating ? .spring(response: 0.35, dampingFraction: 0.86) : nil, value: messages.count)
+ .animation(.easeOut(duration: 0.22), value: keepStreamingVisible)
Color.clear
.frame(height: contentBottomPadding)
@@ -245,6 +284,13 @@ struct MessageListView: View {
.move(edge: .bottom).combined(with: .opacity)
}
+ private var streamingTransition: AnyTransition {
+ .asymmetric(
+ insertion: .opacity.combined(with: .scale(scale: 0.96, anchor: .topLeading)),
+ removal: .opacity.combined(with: .scale(scale: 0.92, anchor: .topLeading))
+ )
+ }
+
private var contentBottomPadding: CGFloat {
let fallbackPadding = EnsuSpacing.xxxl + EnsuSpacing.xxl + 60
let measuredPadding = inputBarHeight > 0 ? inputBarHeight + EnsuSpacing.md : fallbackPadding
diff --git a/mobile/native/darwin/Apps/ensu/ensu/Components/EnsuBrandIllustration.swift b/mobile/native/darwin/Apps/ensu/ensu/Components/EnsuBrandIllustration.swift
index 441349e4b5..2ac158cd26 100644
--- a/mobile/native/darwin/Apps/ensu/ensu/Components/EnsuBrandIllustration.swift
+++ b/mobile/native/darwin/Apps/ensu/ensu/Components/EnsuBrandIllustration.swift
@@ -7,6 +7,8 @@ struct EnsuBrandIllustration: View {
var width: CGFloat = 92
var height: CGFloat = 42
var animated: Bool = true
+ var outroTrigger: Bool = false
+ var outroInputName: String = "outro"
@StateObject private var riveViewModel = RiveViewModel(
fileName: "ensu",
@@ -14,12 +16,12 @@ struct EnsuBrandIllustration: View {
alignment: .centerLeft,
autoPlay: true
)
+ @State private var lastOutroTrigger = false
var body: some View {
riveViewModel
.view()
.frame(width: width, height: height, alignment: .leading)
- .clipped()
.onAppear {
if animated {
riveViewModel.play()
@@ -34,6 +36,12 @@ struct EnsuBrandIllustration: View {
riveViewModel.pause()
}
}
+ .onChange(of: outroTrigger) { value in
+ if value && !lastOutroTrigger {
+ riveViewModel.triggerInput(outroInputName)
+ }
+ lastOutroTrigger = value
+ }
.accessibilityLabel("Ensu")
}
}
@@ -44,11 +52,15 @@ struct EnsuBrandIllustration: View {
var width: CGFloat = 92
var height: CGFloat = 42
var animated: Bool = true
+ var outroTrigger: Bool = false
+ var outroInputName: String = "outro"
@State private var isAnimating = false
var body: some View {
let activePhase = animated ? isAnimating : true
+ _ = outroTrigger
+ _ = outroInputName
Image("EnsuLogoForeground")
.resizable()