Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix[ios channels]: scroll message list when input focused" (#2452)

Peter Chinman26f3a5c39746
diff --git a/js/app/packages/channel/Channel/Channel.tsx b/js/app/packages/channel/Channel/Channel.tsx
index 35929eadfc..10bf093aed 100644
--- a/js/app/packages/channel/Channel/Channel.tsx
+++ b/js/app/packages/channel/Channel/Channel.tsx
@@ -60,6 +60,7 @@ import { createMessageEditor } from './create-message-editor';
import { createMessageSelection } from './create-message-selection';
import { createChannelHotkeys } from './create-channel-hotkeys';
import { createInlineInputKeyboardHandler } from './create-inline-input-keyboard-handler';
+import { createMainInputKeyboardHandler } from './create-main-input-keyboard-handler';
import type { ChannelInputProps } from '@channel/Input/ChannelInput';
import {
clearStaleRestoredChannelData,
@@ -164,6 +165,7 @@ export function Channel(props: ChannelProps) {
const threadManager = createThreadManager();
const [isChannelInputHidden, setIsChannelInputHidden] = createSignal(false);
+ const [channelInputEl, setChannelInputEl] = createSignal<HTMLDivElement>();
const threadPaginator = createThreadPaginator(messagesQuery);
const messageEditor = createMessageEditor({
channelId: () => props.channelId,
@@ -256,6 +258,12 @@ export function Channel(props: ChannelProps) {
// On Mobile when a thread reply input is focused, we want to hide the main Channel input
createInlineInputKeyboardHandler(messageListElement, setIsChannelInputHidden);
+ // On Native iOS app, when the main channel input is focused, scroll to bottom if already near bottom
+ createMainInputKeyboardHandler(
+ channelInputEl,
+ threadListNavigation,
+ messageListElement
+ );
const onSend: ChannelInputProps['onSend'] = (snapshot) => {
const senderId = userId();
@@ -383,7 +391,10 @@ export function Channel(props: ChannelProps) {
</Show>
<DebugSuspense name="Channel.input">
<ChannelInputContainer
- ref={attachInputRef}
+ ref={(el) => {
+ attachInputRef(el);
+ setChannelInputEl(el);
+ }}
isHidden={isChannelInputHidden()}
>
<ChannelInput
diff --git a/js/app/packages/channel/Channel/ThreadList.tsx b/js/app/packages/channel/Channel/ThreadList.tsx
index 09f073b3d3..60fabb3fc0 100644
--- a/js/app/packages/channel/Channel/ThreadList.tsx
+++ b/js/app/packages/channel/Channel/ThreadList.tsx
@@ -5,6 +5,7 @@ import {
createScrollIntentTracker,
type ScrollDirection,
} from '@core/util/scroll-intent';
+import { NEAR_BOTTOM_THRESHOLD } from './constants';
const BASE_ITEM_SIZE: number = 64;
const BASE_BUFFER_SIZE: number = BASE_ITEM_SIZE;
@@ -70,7 +71,6 @@ type ThreadListProps = {
};
const NEAR_TOP_THRESHOLD = 800;
-const NEAR_BOTTOM_THRESHOLD = 50;
const EXPLICIT_SCROLL_DOWN_TRIGGER_DISTANCE = 64;
export const DEFAULT_INITIAL_SCROLL_TARGET: ThreadListScrollTarget = {
diff --git a/js/app/packages/channel/Channel/constants.ts b/js/app/packages/channel/Channel/constants.ts
new file mode 100644
index 0000000000..5b20af0a8b
--- /dev/null
+++ b/js/app/packages/channel/Channel/constants.ts
@@ -0,0 +1 @@
+export const NEAR_BOTTOM_THRESHOLD = 50;
diff --git a/js/app/packages/channel/Channel/create-main-input-keyboard-handler.ts b/js/app/packages/channel/Channel/create-main-input-keyboard-handler.ts
new file mode 100644
index 0000000000..721e02fa4c
--- /dev/null
+++ b/js/app/packages/channel/Channel/create-main-input-keyboard-handler.ts
@@ -0,0 +1,57 @@
+import { createEffect, onCleanup, type Accessor } from 'solid-js';
+import type { ThreadListNavigation } from './ThreadList';
+import { isPlatform } from '@core/util/platform';
+import { NEAR_BOTTOM_THRESHOLD } from './constants';
+
+/**
+ * On native ios app, when the main channel input is focused and the user was near the
+ * bottom of the message list, scrolls to the bottom after the virtual keyboard
+ * appears (so messages aren't hidden behind the keyboard).
+ */
+export function createMainInputKeyboardHandler(
+ inputContainerEl: Accessor<HTMLElement | undefined>,
+ navigation: Accessor<ThreadListNavigation | undefined>,
+ channelRoot: Accessor<HTMLElement | undefined>
+): void {
+ if (!isPlatform('ios')) return;
+
+ // Read from the DOM directly: the scrollState signal is only updated on scroll
+ // events, which can fire after the keyboard has already shrunk the viewport,
+ // leaving a stale isNearBottom=false that persists until the next user scroll.
+ let wasNearBottom = false;
+
+ const captureNearBottom = () => {
+ const root = channelRoot();
+ const scrollEl = root?.querySelector<HTMLElement>('[data-channel-scroll]');
+ if (!scrollEl) {
+ wasNearBottom = false;
+ return;
+ }
+ const distanceFromBottom =
+ scrollEl.scrollHeight - scrollEl.scrollTop - scrollEl.clientHeight;
+ wasNearBottom = distanceFromBottom <= NEAR_BOTTOM_THRESHOLD;
+ };
+
+ createEffect(() => {
+ const el = inputContainerEl();
+ if (!el) return;
+
+ const handleTouchStart = () => captureNearBottom();
+ el.addEventListener('touchstart', handleTouchStart, {
+ capture: true,
+ passive: true,
+ });
+
+ const handleKeyboardWillShow = () => {
+ if (!el.contains(document.activeElement)) return;
+ if (wasNearBottom) navigation()?.scrollToBottom();
+ };
+ window.addEventListener('keyboardWillShow', handleKeyboardWillShow);
+ onCleanup(() => {
+ el.removeEventListener('touchstart', handleTouchStart, {
+ capture: true,
+ });
+ window.removeEventListener('keyboardWillShow', handleKeyboardWillShow);
+ });
+ });
+}