Simplify positioning of timeline warnings

This commit is contained in:
Evan Hahn 2022-03-09 12:47:13 -06:00 committed by GitHub
parent a72cf075ef
commit 0b5e2e6768
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 23 additions and 64 deletions

View file

@ -5452,6 +5452,7 @@ button.module-image__border-overlay:focus {
.module-timeline { .module-timeline {
display: flex; display: flex;
flex-direction: column;
height: 100%; height: 100%;
overflow: hidden; overflow: hidden;
} }
@ -5466,6 +5467,7 @@ button.module-image__border-overlay:focus {
overflow-y: overlay; overflow-y: overlay;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
position: relative;
} }
.module-timeline__messages { .module-timeline__messages {

View file

@ -7,7 +7,7 @@
flex-direction: column; flex-direction: column;
left: 0; left: 0;
pointer-events: none; pointer-events: none;
position: absolute; position: sticky;
top: 10px; top: 10px;
transition: opacity 0.25s ease-out; transition: opacity 0.25s ease-out;
width: 100%; width: 100%;

View file

@ -2,12 +2,7 @@
// SPDX-License-Identifier: AGPL-3.0-only // SPDX-License-Identifier: AGPL-3.0-only
.module-TimelineWarnings { .module-TimelineWarnings {
left: 0;
position: absolute;
top: 0;
width: 100%;
z-index: $z-index-above-above-base;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
width: 100%;
} }

View file

@ -171,7 +171,6 @@ export type PropsType = PropsDataType &
type StateType = { type StateType = {
hasDismissedDirectContactSpoofingWarning: boolean; hasDismissedDirectContactSpoofingWarning: boolean;
hasRecentlyScrolled: boolean; hasRecentlyScrolled: boolean;
lastMeasuredWarningHeight: number;
newestFullyVisibleMessageId?: string; newestFullyVisibleMessageId?: string;
oldestPartiallyVisibleMessageId?: string; oldestPartiallyVisibleMessageId?: string;
widthBreakpoint: WidthBreakpoint; widthBreakpoint: WidthBreakpoint;
@ -274,8 +273,7 @@ export class Timeline extends React.Component<
hasRecentlyScrolled: true, hasRecentlyScrolled: true,
hasDismissedDirectContactSpoofingWarning: false, hasDismissedDirectContactSpoofingWarning: false,
// These may be swiftly overridden. // This may be swiftly overridden.
lastMeasuredWarningHeight: 0,
widthBreakpoint: WidthBreakpoint.Wide, widthBreakpoint: WidthBreakpoint.Wide,
}; };
@ -766,7 +764,6 @@ export class Timeline extends React.Component<
} = this.props; } = this.props;
const { const {
hasRecentlyScrolled, hasRecentlyScrolled,
lastMeasuredWarningHeight,
newestFullyVisibleMessageId, newestFullyVisibleMessageId,
oldestPartiallyVisibleMessageId, oldestPartiallyVisibleMessageId,
widthBreakpoint, widthBreakpoint,
@ -820,11 +817,6 @@ export class Timeline extends React.Component<
<TimelineFloatingHeader <TimelineFloatingHeader
i18n={i18n} i18n={i18n}
isLoading={isLoadingMessages} isLoading={isLoadingMessages}
style={
lastMeasuredWarningHeight
? { marginTop: lastMeasuredWarningHeight }
: undefined
}
timestamp={oldestPartiallyVisibleMessageTimestamp} timestamp={oldestPartiallyVisibleMessageTimestamp}
visible={ visible={
(hasRecentlyScrolled || isLoadingMessages) && (hasRecentlyScrolled || isLoadingMessages) &&
@ -956,18 +948,7 @@ export class Timeline extends React.Component<
} }
timelineWarning = ( timelineWarning = (
<Measure <TimelineWarnings>
bounds
onResize={({ bounds }) => {
if (!bounds) {
assert(false, 'We should be measuring the bounds');
return;
}
this.setState({ lastMeasuredWarningHeight: bounds.height });
}}
>
{({ measureRef }) => (
<TimelineWarnings ref={measureRef}>
<TimelineWarning i18n={i18n} onClose={onClose}> <TimelineWarning i18n={i18n} onClose={onClose}>
<TimelineWarning.IconContainer> <TimelineWarning.IconContainer>
<TimelineWarning.GenericIcon /> <TimelineWarning.GenericIcon />
@ -975,8 +956,6 @@ export class Timeline extends React.Component<
<TimelineWarning.Text>{text}</TimelineWarning.Text> <TimelineWarning.Text>{text}</TimelineWarning.Text>
</TimelineWarning> </TimelineWarning>
</TimelineWarnings> </TimelineWarnings>
)}
</Measure>
); );
} }
@ -1059,13 +1038,13 @@ export class Timeline extends React.Component<
> >
{timelineWarning} {timelineWarning}
{floatingHeader}
<div <div
className="module-timeline__messages__container" className="module-timeline__messages__container"
onScroll={this.onScroll} onScroll={this.onScroll}
ref={this.containerRef} ref={this.containerRef}
> >
{floatingHeader}
<div <div
className={classNames( className={classNames(
'module-timeline__messages', 'module-timeline__messages',
@ -1073,14 +1052,8 @@ export class Timeline extends React.Component<
)} )}
ref={this.messagesRef} ref={this.messagesRef}
> >
{haveOldest && ( {haveOldest &&
<> renderHeroRow(id, unblurAvatar, updateSharedGroups)}
{Timeline.getWarning(this.props, this.state) && (
<div style={{ height: lastMeasuredWarningHeight }} />
)}
{renderHeroRow(id, unblurAvatar, updateSharedGroups)}
</>
)}
{messageNodes} {messageNodes}

View file

@ -2,7 +2,7 @@
// SPDX-License-Identifier: AGPL-3.0-only // SPDX-License-Identifier: AGPL-3.0-only
import classNames from 'classnames'; import classNames from 'classnames';
import type { CSSProperties, ReactElement } from 'react'; import type { ReactElement } from 'react';
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import type { LocalizerType } from '../../types/Util'; import type { LocalizerType } from '../../types/Util';
import { TimelineDateHeader } from './TimelineDateHeader'; import { TimelineDateHeader } from './TimelineDateHeader';
@ -11,13 +11,11 @@ import { Spinner } from '../Spinner';
export const TimelineFloatingHeader = ({ export const TimelineFloatingHeader = ({
i18n, i18n,
isLoading, isLoading,
style,
timestamp, timestamp,
visible, visible,
}: Readonly<{ }: Readonly<{
i18n: LocalizerType; i18n: LocalizerType;
isLoading: boolean; isLoading: boolean;
style?: CSSProperties;
timestamp: number; timestamp: number;
visible: boolean; visible: boolean;
}>): ReactElement => { }>): ReactElement => {
@ -35,7 +33,6 @@ export const TimelineFloatingHeader = ({
visible && hasRendered ? 'visible' : 'hidden' visible && hasRendered ? 'visible' : 'hidden'
}` }`
)} )}
style={style}
> >
<TimelineDateHeader floating i18n={i18n} timestamp={timestamp} /> <TimelineDateHeader floating i18n={i18n} timestamp={timestamp} />
<div <div

View file

@ -1,19 +1,11 @@
// Copyright 2021 Signal Messenger, LLC // Copyright 2021-2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only // SPDX-License-Identifier: AGPL-3.0-only
import type { ReactNode } from 'react'; import type { FunctionComponent } from 'react';
import React, { forwardRef } from 'react'; import React from 'react';
const CLASS_NAME = 'module-TimelineWarnings'; const CLASS_NAME = 'module-TimelineWarnings';
type PropsType = { export const TimelineWarnings: FunctionComponent = ({ children }) => (
children: ReactNode; <div className={CLASS_NAME}>{children}</div>
};
export const TimelineWarnings = forwardRef<HTMLDivElement, PropsType>(
({ children }, ref) => (
<div className={CLASS_NAME} ref={ref}>
{children}
</div>
)
); );