Tweaks to left pane snapping logic
This commit is contained in:
parent
29e6ba8f10
commit
0faeda28f0
3 changed files with 51 additions and 8 deletions
|
@ -40,6 +40,8 @@ import * as OS from '../OS';
|
||||||
import { LocalizerType, ScrollBehavior } from '../types/Util';
|
import { LocalizerType, ScrollBehavior } from '../types/Util';
|
||||||
import { usePrevious } from '../hooks/usePrevious';
|
import { usePrevious } from '../hooks/usePrevious';
|
||||||
import { missingCaseError } from '../util/missingCaseError';
|
import { missingCaseError } from '../util/missingCaseError';
|
||||||
|
import { strictAssert } from '../util/assert';
|
||||||
|
import { isSorted } from '../util/isSorted';
|
||||||
import { getConversationListWidthBreakpoint, WidthBreakpoint } from './_util';
|
import { getConversationListWidthBreakpoint, WidthBreakpoint } from './_util';
|
||||||
|
|
||||||
import { ConversationList } from './ConversationList';
|
import { ConversationList } from './ConversationList';
|
||||||
|
@ -52,9 +54,13 @@ import {
|
||||||
} from '../types/Avatar';
|
} from '../types/Avatar';
|
||||||
|
|
||||||
const MIN_WIDTH = 109;
|
const MIN_WIDTH = 109;
|
||||||
const MIN_SNAP_WIDTH = 280;
|
const SNAP_WIDTH = 200;
|
||||||
const MIN_FULL_WIDTH = 320;
|
const MIN_FULL_WIDTH = 280;
|
||||||
const MAX_WIDTH = 380;
|
const MAX_WIDTH = 380;
|
||||||
|
strictAssert(
|
||||||
|
isSorted([MIN_WIDTH, SNAP_WIDTH, MIN_FULL_WIDTH, MAX_WIDTH]),
|
||||||
|
'Expected widths to be in the right order'
|
||||||
|
);
|
||||||
|
|
||||||
export enum LeftPaneMode {
|
export enum LeftPaneMode {
|
||||||
Inbox,
|
Inbox,
|
||||||
|
@ -387,10 +393,10 @@ export const LeftPane: React.FC<PropsType> = ({
|
||||||
let width: number;
|
let width: number;
|
||||||
if (requiresFullWidth) {
|
if (requiresFullWidth) {
|
||||||
width = Math.max(event.clientX, MIN_FULL_WIDTH);
|
width = Math.max(event.clientX, MIN_FULL_WIDTH);
|
||||||
} else if (event.clientX < MIN_SNAP_WIDTH) {
|
} else if (event.clientX < SNAP_WIDTH) {
|
||||||
width = MIN_WIDTH;
|
width = MIN_WIDTH;
|
||||||
} else {
|
} else {
|
||||||
width = Math.max(event.clientX, MIN_WIDTH);
|
width = clamp(event.clientX, MIN_FULL_WIDTH, MAX_WIDTH);
|
||||||
}
|
}
|
||||||
setPreferredWidth(Math.min(width, MAX_WIDTH));
|
setPreferredWidth(Math.min(width, MAX_WIDTH));
|
||||||
|
|
||||||
|
@ -484,12 +490,10 @@ export const LeftPane: React.FC<PropsType> = ({
|
||||||
);
|
);
|
||||||
|
|
||||||
let width: number;
|
let width: number;
|
||||||
if (requiresFullWidth) {
|
if (requiresFullWidth || preferredWidth >= SNAP_WIDTH) {
|
||||||
width = Math.max(preferredWidth, MIN_FULL_WIDTH);
|
width = Math.max(preferredWidth, MIN_FULL_WIDTH);
|
||||||
} else if (preferredWidth < MIN_SNAP_WIDTH) {
|
|
||||||
width = MIN_WIDTH;
|
|
||||||
} else {
|
} else {
|
||||||
width = preferredWidth;
|
width = MIN_WIDTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
const isScrollable = helper.isScrollable();
|
const isScrollable = helper.isScrollable();
|
||||||
|
|
26
ts/test-both/util/isSorted_test.ts
Normal file
26
ts/test-both/util/isSorted_test.ts
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
// Copyright 2021 Signal Messenger, LLC
|
||||||
|
// SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
import { assert } from 'chai';
|
||||||
|
|
||||||
|
import { isSorted } from '../../util/isSorted';
|
||||||
|
|
||||||
|
describe('isSorted', () => {
|
||||||
|
it('returns true for empty lists', () => {
|
||||||
|
assert.isTrue(isSorted([]));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns true for one-element lists', () => {
|
||||||
|
assert.isTrue(isSorted([5]));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns true for sorted lists', () => {
|
||||||
|
assert.isTrue(isSorted([1, 2]));
|
||||||
|
assert.isTrue(isSorted([1, 2, 2, 3]));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns false for out-of-order lists', () => {
|
||||||
|
assert.isFalse(isSorted([2, 1]));
|
||||||
|
assert.isFalse(isSorted([1, 2, 2, 3, 0]));
|
||||||
|
});
|
||||||
|
});
|
13
ts/util/isSorted.ts
Normal file
13
ts/util/isSorted.ts
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
// Copyright 2021 Signal Messenger, LLC
|
||||||
|
// SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
export function isSorted(list: Iterable<number>): boolean {
|
||||||
|
let previousItem: undefined | number;
|
||||||
|
for (const item of list) {
|
||||||
|
if (previousItem !== undefined && item < previousItem) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
previousItem = item;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
Loading…
Reference in a new issue