Viper Messenger

Posts · December 27, 2025

Chat UI in Viper: keyboard and messages

Chat looks simple.

A message list, an input field, a send button — it feels like a solved problem.

In practice, chat UI quickly hits the limits of standard components. Especially when you need to support at the same time:

In Viper, chat is implemented as a custom ScrollView built on SwiftUI + UIKit. During development, several typical but non-obvious problems appeared. These are rarely described end to end, but show up immediately in real apps.

Architecture in short

At the core there is UIScrollView wrapped in UIViewRepresentable.

Key components:

This approach allows:

Part 1. Keyboard show and hide

Keyboard Closed (older version of Viper)

The chat interface with the keyboard hidden, showing messages 7, 8, and 9 in the viewport.

Keyboard Open (older version of Viper)

When the keyboard appears, the same messages remain visible. The content shifts up smoothly without losing scroll position.

The most common scenario is reading messages and starting to type.

Expected behavior is simple:

What usually breaks

With a standard SwiftUI + ScrollView setup:

Formally everything works. Visually scrolling becomes unstable.

How it is handled in code

In ChatScrollView the keyboard is treated as a layout event. Not as a UI state change.

Several techniques are used:

As a result:

Part 2. Outgoing message

Typing Message (older version of Viper)

User types "10" in the input field while viewing messages 7, 8, 9.

Message Sent (older version of Viper)

After sending, message "10" appears at the bottom. The scroll position adjusts smoothly to show the new message without jarring jumps.

Sending a message is another scenario where jumps appear easily.

At the moment of sending:

Calling auto scroll directly almost always causes a jump.

How it works

There is no direct scrollToBottom in ChatScrollView.

Instead:

Outgoing messages do not interfere with reading history.

Part 3. Keyboard hide

Keyboard Closed Again (older version of Viper)

After sending message "10", the keyboard stays open. User manually taps outside the input field to dismiss it. When the keyboard hides, message "10" moves down smoothly as the content expands. Messages 3-10 are now visible, with "Load older (+10)" button at the top. The transition is stable with no content jumps.

Keyboard hide looks like a reverse operation. In practice, it is where many micro issues appear.

In SwiftUI, keyboard dismissal often causes layout jumps.

Typical symptoms:

The reason is UIKit automatic adjustments.

What is done in Viper

As a result, keyboard hide looks as stable as keyboard show.

Part 4. Incoming message

Incoming Message (older version of Viper)

A new incoming message "11" appears at the bottom with a darker bubble (left-aligned), showing it's from another user. The scroll position automatically adjusts to show the new message.

Incoming messages are also non-trivial because they can arrive:

Base rule

An incoming message must not change the current position if the user:

Implementation

Incoming messages do not break the current context.

Summary

Chat implementation is not just a message list. It is constant coordination between:

Keyboard, prepend, append, restore — all of them intersect inside one ScrollView and require explicit control.

That is why Viper uses a custom implementation instead of the standard ScrollView.

First published December 27, 2025 on the old Viper Foundation blog; moved here November 19, 2026. All posts