Layout: Improvements for tablet UI (#1218)
This commit is contained in:
parent
48f6f43372
commit
bb75af6dcd
@ -19,7 +19,12 @@ import {
|
|||||||
DARK_THEME_BG_COLOR,
|
DARK_THEME_BG_COLOR,
|
||||||
LIGHT_THEME_BG_COLOR,
|
LIGHT_THEME_BG_COLOR,
|
||||||
} from '../../config';
|
} from '../../config';
|
||||||
import { IS_SINGLE_COLUMN_LAYOUT, IS_TOUCH_ENV, MASK_IMAGE_DISABLED } from '../../util/environment';
|
import {
|
||||||
|
IS_SINGLE_COLUMN_LAYOUT,
|
||||||
|
IS_TABLET_COLUMN_LAYOUT,
|
||||||
|
IS_TOUCH_ENV,
|
||||||
|
MASK_IMAGE_DISABLED,
|
||||||
|
} from '../../util/environment';
|
||||||
import { DropAreaState } from './composer/DropArea';
|
import { DropAreaState } from './composer/DropArea';
|
||||||
import {
|
import {
|
||||||
selectChat,
|
selectChat,
|
||||||
@ -67,6 +72,7 @@ type StateProps = {
|
|||||||
customBackground?: string;
|
customBackground?: string;
|
||||||
backgroundColor?: string;
|
backgroundColor?: string;
|
||||||
patternColor?: string;
|
patternColor?: string;
|
||||||
|
isLeftColumnShown?: boolean;
|
||||||
isRightColumnShown?: boolean;
|
isRightColumnShown?: boolean;
|
||||||
isBackgroundBlurred?: boolean;
|
isBackgroundBlurred?: boolean;
|
||||||
isMobileSearchActive?: boolean;
|
isMobileSearchActive?: boolean;
|
||||||
@ -96,6 +102,7 @@ const MiddleColumn: FC<StateProps & DispatchProps> = ({
|
|||||||
theme,
|
theme,
|
||||||
backgroundColor,
|
backgroundColor,
|
||||||
patternColor,
|
patternColor,
|
||||||
|
isLeftColumnShown,
|
||||||
isRightColumnShown,
|
isRightColumnShown,
|
||||||
isBackgroundBlurred,
|
isBackgroundBlurred,
|
||||||
isMobileSearchActive,
|
isMobileSearchActive,
|
||||||
@ -179,6 +186,10 @@ const MiddleColumn: FC<StateProps & DispatchProps> = ({
|
|||||||
openChat({ id: chatId });
|
openChat({ id: chatId });
|
||||||
}, [unpinAllMessages, openChat, closeUnpinModal, chatId]);
|
}, [unpinAllMessages, openChat, closeUnpinModal, chatId]);
|
||||||
|
|
||||||
|
const handleTabletFocus = useCallback(() => {
|
||||||
|
openChat({ id: chatId });
|
||||||
|
}, [openChat, chatId]);
|
||||||
|
|
||||||
const customBackgroundValue = useCustomBackground(theme, customBackground);
|
const customBackgroundValue = useCustomBackground(theme, customBackground);
|
||||||
|
|
||||||
const className = buildClassName(
|
const className = buildClassName(
|
||||||
@ -228,6 +239,7 @@ const MiddleColumn: FC<StateProps & DispatchProps> = ({
|
|||||||
--theme-background-color:
|
--theme-background-color:
|
||||||
${backgroundColor || (theme === 'dark' ? DARK_THEME_BG_COLOR : LIGHT_THEME_BG_COLOR)};
|
${backgroundColor || (theme === 'dark' ? DARK_THEME_BG_COLOR : LIGHT_THEME_BG_COLOR)};
|
||||||
`}
|
`}
|
||||||
|
onClick={(IS_TABLET_COLUMN_LAYOUT && isLeftColumnShown) ? handleTabletFocus : undefined}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
id="middle-column-bg"
|
id="middle-column-bg"
|
||||||
@ -332,13 +344,14 @@ export default memo(withGlobal(
|
|||||||
} = global.settings.themes[theme] || {};
|
} = global.settings.themes[theme] || {};
|
||||||
|
|
||||||
const currentMessageList = selectCurrentMessageList(global);
|
const currentMessageList = selectCurrentMessageList(global);
|
||||||
const { chats: { listIds } } = global;
|
const { isLeftColumnShown, chats: { listIds } } = global;
|
||||||
|
|
||||||
const state: StateProps = {
|
const state: StateProps = {
|
||||||
theme,
|
theme,
|
||||||
customBackground,
|
customBackground,
|
||||||
backgroundColor,
|
backgroundColor,
|
||||||
patternColor,
|
patternColor,
|
||||||
|
isLeftColumnShown,
|
||||||
isRightColumnShown: selectIsRightColumnShown(global),
|
isRightColumnShown: selectIsRightColumnShown(global),
|
||||||
isBackgroundBlurred,
|
isBackgroundBlurred,
|
||||||
isMobileSearchActive: Boolean(IS_SINGLE_COLUMN_LAYOUT && selectCurrentTextSearch(global)),
|
isMobileSearchActive: Boolean(IS_SINGLE_COLUMN_LAYOUT && selectCurrentTextSearch(global)),
|
||||||
|
|||||||
@ -21,7 +21,7 @@ import {
|
|||||||
SAFE_SCREEN_WIDTH_FOR_STATIC_RIGHT_COLUMN,
|
SAFE_SCREEN_WIDTH_FOR_STATIC_RIGHT_COLUMN,
|
||||||
SAFE_SCREEN_WIDTH_FOR_CHAT_INFO,
|
SAFE_SCREEN_WIDTH_FOR_CHAT_INFO,
|
||||||
} from '../../config';
|
} from '../../config';
|
||||||
import { IS_SINGLE_COLUMN_LAYOUT } from '../../util/environment';
|
import { IS_SINGLE_COLUMN_LAYOUT, IS_TABLET_COLUMN_LAYOUT } from '../../util/environment';
|
||||||
import {
|
import {
|
||||||
isChatPrivate,
|
isChatPrivate,
|
||||||
isChatArchived,
|
isChatArchived,
|
||||||
@ -156,7 +156,7 @@ const MiddleHeader: FC<OwnProps & StateProps & DispatchProps> = ({
|
|||||||
const { width: windowWidth } = useWindowSize();
|
const { width: windowWidth } = useWindowSize();
|
||||||
|
|
||||||
const isLeftColumnHideable = windowWidth <= MIN_SCREEN_WIDTH_FOR_STATIC_LEFT_COLUMN;
|
const isLeftColumnHideable = windowWidth <= MIN_SCREEN_WIDTH_FOR_STATIC_LEFT_COLUMN;
|
||||||
const shouldShowCloseButton = windowWidth >= MOBILE_SCREEN_MAX_WIDTH && isLeftColumnShown;
|
const shouldShowCloseButton = IS_TABLET_COLUMN_LAYOUT && isLeftColumnShown;
|
||||||
|
|
||||||
// eslint-disable-next-line no-null/no-null
|
// eslint-disable-next-line no-null/no-null
|
||||||
const componentRef = useRef<HTMLDivElement>(null);
|
const componentRef = useRef<HTMLDivElement>(null);
|
||||||
@ -183,7 +183,7 @@ const MiddleHeader: FC<OwnProps & StateProps & DispatchProps> = ({
|
|||||||
openChat({ id: chatId, threadId: MAIN_THREAD_ID, type: 'pinned' });
|
openChat({ id: chatId, threadId: MAIN_THREAD_ID, type: 'pinned' });
|
||||||
}, [openChat, chatId]);
|
}, [openChat, chatId]);
|
||||||
|
|
||||||
const handleBackClick = useCallback(() => {
|
const handleBackClick = useCallback((e: React.MouseEvent<HTMLElement, MouseEvent>) => {
|
||||||
if (IS_SINGLE_COLUMN_LAYOUT) {
|
if (IS_SINGLE_COLUMN_LAYOUT) {
|
||||||
const messageInput = document.getElementById(EDITABLE_INPUT_ID);
|
const messageInput = document.getElementById(EDITABLE_INPUT_ID);
|
||||||
if (messageInput) {
|
if (messageInput) {
|
||||||
@ -191,7 +191,8 @@ const MiddleHeader: FC<OwnProps & StateProps & DispatchProps> = ({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (threadId === MAIN_THREAD_ID && messageListType === 'thread') {
|
if (threadId === MAIN_THREAD_ID && messageListType === 'thread') {
|
||||||
if (IS_SINGLE_COLUMN_LAYOUT) {
|
if (IS_SINGLE_COLUMN_LAYOUT || shouldShowCloseButton) {
|
||||||
|
e.stopPropagation(); // Stop propagation to prevent chat re-opening on tablets
|
||||||
openChat({ id: undefined });
|
openChat({ id: undefined });
|
||||||
} else {
|
} else {
|
||||||
toggleLeftColumn();
|
toggleLeftColumn();
|
||||||
@ -203,8 +204,12 @@ const MiddleHeader: FC<OwnProps & StateProps & DispatchProps> = ({
|
|||||||
if (messageListType === 'scheduled' && isSelectModeActive) {
|
if (messageListType === 'scheduled' && isSelectModeActive) {
|
||||||
exitMessageSelectMode();
|
exitMessageSelectMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
openChat({ id: originChatId, threadId: MAIN_THREAD_ID });
|
openChat({ id: originChatId, threadId: MAIN_THREAD_ID });
|
||||||
}, [openChat, originChatId, threadId, messageListType, toggleLeftColumn, isSelectModeActive, exitMessageSelectMode]);
|
}, [
|
||||||
|
openChat, originChatId, threadId, messageListType, toggleLeftColumn, isSelectModeActive, exitMessageSelectMode,
|
||||||
|
shouldShowCloseButton,
|
||||||
|
]);
|
||||||
|
|
||||||
const unreadCount = useMemo(() => {
|
const unreadCount = useMemo(() => {
|
||||||
if (!isLeftColumnHideable || !chatsById) {
|
if (!isLeftColumnHideable || !chatsById) {
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import { addReducer } from '../../../lib/teact/teactn';
|
|||||||
|
|
||||||
import { GlobalState } from '../../../global/types';
|
import { GlobalState } from '../../../global/types';
|
||||||
|
|
||||||
import { IS_SINGLE_COLUMN_LAYOUT } from '../../../util/environment';
|
import { IS_SINGLE_COLUMN_LAYOUT, IS_TABLET_COLUMN_LAYOUT } from '../../../util/environment';
|
||||||
import getReadableErrorText from '../../../util/getReadableErrorText';
|
import getReadableErrorText from '../../../util/getReadableErrorText';
|
||||||
import { selectCurrentMessageList } from '../../selectors';
|
import { selectCurrentMessageList } from '../../selectors';
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ addReducer('closeManagement', (global): GlobalState | undefined => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
addReducer('openChat', (global, actions, payload) => {
|
addReducer('openChat', (global, actions, payload) => {
|
||||||
if (!IS_SINGLE_COLUMN_LAYOUT) {
|
if (!IS_SINGLE_COLUMN_LAYOUT && !IS_TABLET_COLUMN_LAYOUT) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
|
MIN_SCREEN_WIDTH_FOR_STATIC_LEFT_COLUMN,
|
||||||
MOBILE_SCREEN_MAX_WIDTH,
|
MOBILE_SCREEN_MAX_WIDTH,
|
||||||
MOBILE_SCREEN_LANDSCAPE_MAX_HEIGHT,
|
MOBILE_SCREEN_LANDSCAPE_MAX_HEIGHT,
|
||||||
MOBILE_SCREEN_LANDSCAPE_MAX_WIDTH,
|
MOBILE_SCREEN_LANDSCAPE_MAX_WIDTH,
|
||||||
@ -42,6 +43,10 @@ export const IS_TOUCH_ENV = window.matchMedia('(pointer: coarse)').matches;
|
|||||||
export const IS_SINGLE_COLUMN_LAYOUT = window.innerWidth <= MOBILE_SCREEN_MAX_WIDTH || (
|
export const IS_SINGLE_COLUMN_LAYOUT = window.innerWidth <= MOBILE_SCREEN_MAX_WIDTH || (
|
||||||
window.innerWidth <= MOBILE_SCREEN_LANDSCAPE_MAX_WIDTH && window.innerHeight <= MOBILE_SCREEN_LANDSCAPE_MAX_HEIGHT
|
window.innerWidth <= MOBILE_SCREEN_LANDSCAPE_MAX_WIDTH && window.innerHeight <= MOBILE_SCREEN_LANDSCAPE_MAX_HEIGHT
|
||||||
);
|
);
|
||||||
|
// Special layout, 1 column while chat opened, 2 columns while collapsed
|
||||||
|
export const IS_TABLET_COLUMN_LAYOUT = !IS_SINGLE_COLUMN_LAYOUT && (
|
||||||
|
window.innerWidth <= MIN_SCREEN_WIDTH_FOR_STATIC_LEFT_COLUMN
|
||||||
|
);
|
||||||
export const IS_VOICE_RECORDING_SUPPORTED = (navigator.mediaDevices && 'getUserMedia' in navigator.mediaDevices && (
|
export const IS_VOICE_RECORDING_SUPPORTED = (navigator.mediaDevices && 'getUserMedia' in navigator.mediaDevices && (
|
||||||
window.AudioContext || (window as any).webkitAudioContext
|
window.AudioContext || (window as any).webkitAudioContext
|
||||||
));
|
));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user