Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dbe87ee99d |
No files matched your search
@@ -5,6 +5,7 @@ import { useLocation, useHistory } from 'react-router-dom';
|
||||
import type { LocationBase } from 'scroll-behavior';
|
||||
import ScrollBehavior from 'scroll-behavior';
|
||||
|
||||
import { useViewportSize } from '@/mastodon/hooks/useViewportSize';
|
||||
import type {
|
||||
LocationState,
|
||||
MastodonLocation,
|
||||
@@ -92,6 +93,8 @@ export const ScrollContext: React.FC<ScrollContextProps> = ({
|
||||
}),
|
||||
);
|
||||
|
||||
const size = useViewportSize();
|
||||
|
||||
/**
|
||||
* Handle scroll update when location changes
|
||||
*/
|
||||
@@ -135,6 +138,20 @@ export const ScrollContext: React.FC<ScrollContextProps> = ({
|
||||
return (
|
||||
<ScrollBehaviorContext.Provider value={contextValue}>
|
||||
{React.Children.only(children)}
|
||||
|
||||
<aside
|
||||
style={{
|
||||
position: 'fixed',
|
||||
top: 0,
|
||||
left: 0,
|
||||
padding: '10px',
|
||||
background: 'pink',
|
||||
color: 'black',
|
||||
zIndex: 'calc(Infinity)',
|
||||
}}
|
||||
>
|
||||
{size.width} / {size.height}
|
||||
</aside>
|
||||
</ScrollBehaviorContext.Provider>
|
||||
);
|
||||
};
|
||||
@@ -12,7 +12,11 @@
|
||||
padding-bottom: calc(max(env(safe-area-inset-bottom), var(--space-4)));
|
||||
position: relative;
|
||||
|
||||
@media (width >= #{variables.$mobile-menu-breakpoint}) {
|
||||
[data-narrow-height='true'] & {
|
||||
overflow-y: scroll;
|
||||
}
|
||||
|
||||
[data-fullscreen='false'] & {
|
||||
@include mixins.elevation-2;
|
||||
|
||||
border-bottom: none;
|
||||
@@ -128,6 +132,10 @@
|
||||
&[data-scroll-down='true']::after {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
[data-narrow-height='true'] & {
|
||||
overflow-y: visible;
|
||||
}
|
||||
}
|
||||
|
||||
.sensitiveWrapper {
|
||||
|
||||
@@ -33,11 +33,15 @@
|
||||
top: env(safe-area-inset-top);
|
||||
transition: bottom 200ms ease-in-out;
|
||||
|
||||
@media (width < #{variables.$mobile-menu-breakpoint}) {
|
||||
&[data-narrow-height='true'] {
|
||||
overflow-y: visible;
|
||||
}
|
||||
|
||||
&[data-fullscreen='true'] {
|
||||
// Add a backdrop for the mobile composer to cover up the page
|
||||
// behind the composer that can be visible on Safari iOS
|
||||
&::before {
|
||||
content: '';
|
||||
// content: '';
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: -1;
|
||||
@@ -45,7 +49,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
@media (width >= #{variables.$mobile-menu-breakpoint}) {
|
||||
&[data-fullscreen='false'] {
|
||||
top: auto;
|
||||
display: grid;
|
||||
grid-template-columns: var(--columns-area-grid-columns);
|
||||
@@ -56,7 +60,7 @@
|
||||
|
||||
.composer,
|
||||
.composerMinimized {
|
||||
@media (width >= #{variables.$mobile-menu-breakpoint}) {
|
||||
[data-fullscreen='false'] & {
|
||||
box-sizing: border-box;
|
||||
grid-column: 2;
|
||||
pointer-events: auto;
|
||||
@@ -64,13 +68,13 @@
|
||||
}
|
||||
|
||||
.composer {
|
||||
@media (width < #{variables.$mobile-menu-breakpoint}) {
|
||||
[data-fullscreen='true'] & {
|
||||
// Set from the visualViewport API.
|
||||
height: var(--viewport-height, 100vh);
|
||||
max-height: 100vh;
|
||||
}
|
||||
|
||||
@media (width >= #{variables.$mobile-menu-breakpoint}) {
|
||||
[data-fullscreen='false'] & {
|
||||
min-height: 270px;
|
||||
max-height: calc(100vh - (var(--space-4) * 2));
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useCallback, useEffect, useLayoutEffect, useState } from 'react';
|
||||
import { useCallback, useLayoutEffect, useState } from 'react';
|
||||
|
||||
import { FormattedMessage } from 'react-intl';
|
||||
|
||||
@@ -9,7 +9,9 @@ import { PenNibIcon, ReadCvLogoIcon } from '@phosphor-icons/react';
|
||||
|
||||
import type { IconButtonProps } from '@/mastodon/components/button/redesign';
|
||||
import { IconButton } from '@/mastodon/components/button/redesign';
|
||||
import { useBodyScrollLock } from '@/mastodon/hooks/useBodyScrollLock';
|
||||
import { useResizeObserver } from '@/mastodon/hooks/useObserver';
|
||||
import { useViewportSize } from '@/mastodon/hooks/useViewportSize';
|
||||
import { useIdentity } from '@/mastodon/identity_context';
|
||||
import {
|
||||
minimizeComposerToggle,
|
||||
@@ -18,13 +20,15 @@ import {
|
||||
import { useAppDispatch, useAppSelector } from '@/mastodon/store';
|
||||
import { includeMultiColumnPaths } from '@/mastodon/utils/react_router';
|
||||
|
||||
import { useBreakpoint } from '../ui/hooks/useBreakpoint';
|
||||
import { BREAKPOINTS, useBreakpoint } from '../ui/hooks/useBreakpoint';
|
||||
|
||||
import { ComposeFormHeader } from './components/header';
|
||||
import { ComposeForm } from './form';
|
||||
import composerClasses from './styles.module.scss';
|
||||
import classes from './trigger.module.scss';
|
||||
|
||||
const NARROW_HEIGHT = 500;
|
||||
|
||||
export const ComposeButton: React.FC<{
|
||||
/**
|
||||
* Render the button in regular document flow instead of fixed positioning for mobile layout
|
||||
@@ -38,19 +42,7 @@ export const ComposeButton: React.FC<{
|
||||
isMobile,
|
||||
});
|
||||
|
||||
// Update viewport based on visual size in order to account for the virtual keyboard.
|
||||
const [viewportHeight, setViewportHeight] = useState<null | number>(null);
|
||||
useEffect(() => {
|
||||
const updateHeight = () => {
|
||||
setViewportHeight(visualViewport?.height ?? null);
|
||||
};
|
||||
|
||||
visualViewport?.addEventListener('resize', updateHeight);
|
||||
|
||||
return () => {
|
||||
visualViewport?.removeEventListener('resize', updateHeight);
|
||||
};
|
||||
}, []);
|
||||
const viewport = useViewportSize();
|
||||
|
||||
const dispatch = useAppDispatch();
|
||||
const handleComposerOpen: React.MouseEventHandler<HTMLButtonElement> =
|
||||
@@ -79,6 +71,10 @@ export const ComposeButton: React.FC<{
|
||||
|
||||
const trackComposerHeight = useTrackComposerHeight();
|
||||
|
||||
const isFullscreen =
|
||||
viewport.height < NARROW_HEIGHT || viewport.width < BREAKPOINTS.openable;
|
||||
useBodyScrollLock(isFullscreen);
|
||||
|
||||
if (!signedIn) {
|
||||
return null;
|
||||
}
|
||||
@@ -90,7 +86,7 @@ export const ComposeButton: React.FC<{
|
||||
|
||||
// Pass the viewport height as a CSS variable so it's only used for mobile.
|
||||
const style = {
|
||||
'--viewport-height': viewportHeight ? `${viewportHeight}px` : undefined,
|
||||
'--viewport-height': `${viewport.height}px`,
|
||||
} as React.CSSProperties;
|
||||
|
||||
if (displayState === 'minimized') {
|
||||
@@ -124,7 +120,13 @@ export const ComposeButton: React.FC<{
|
||||
|
||||
if (displayState === 'showing') {
|
||||
return (
|
||||
<div className={classes.root} style={style} ref={trackComposerHeight}>
|
||||
<div
|
||||
className={classes.root}
|
||||
style={style}
|
||||
ref={trackComposerHeight}
|
||||
data-fullscreen={isFullscreen}
|
||||
data-narrow-height={viewport.height < NARROW_HEIGHT}
|
||||
>
|
||||
<ComposeForm autoFocus className={classes.composer} />
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import { useSyncExternalStore } from 'react';
|
||||
|
||||
const breakpoints = {
|
||||
export const BREAKPOINTS = {
|
||||
narrow: 479, // Device width under which horizontal space is constrained
|
||||
openable: 759, // Device width at which the sidebar becomes an openable hamburger menu
|
||||
full: 1174, // Device width at which all 3 columns can be displayed
|
||||
};
|
||||
|
||||
type Breakpoint = keyof typeof breakpoints;
|
||||
type Breakpoint = keyof typeof BREAKPOINTS;
|
||||
|
||||
export const useBreakpoint = (breakpoint: Breakpoint) => {
|
||||
const query = `(max-width: ${breakpoints[breakpoint]}px)`;
|
||||
const query = `(max-width: ${BREAKPOINTS[breakpoint]}px)`;
|
||||
|
||||
const isMatching = useSyncExternalStore(
|
||||
(callback) => {
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
|
||||
interface Size {
|
||||
width: number;
|
||||
height: number;
|
||||
}
|
||||
|
||||
export function getViewportSize(): Size {
|
||||
if (window.visualViewport) {
|
||||
return {
|
||||
width: window.visualViewport.width,
|
||||
height: window.visualViewport.height,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
width: window.innerWidth,
|
||||
height: window.innerHeight,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the viewport size. This can also be used as a dependency in a
|
||||
* useEffect to trigger an update when the browser resizes.
|
||||
*
|
||||
* Based on https://martijnhols.nl/blog/how-to-get-document-height-ios-safari-osk
|
||||
*/
|
||||
export function useViewportSize() {
|
||||
const [viewportSize, setViewportSize] = useState(getViewportSize);
|
||||
const updateViewportSize = useCallback(() => {
|
||||
const viewportSize = getViewportSize();
|
||||
|
||||
setViewportSize((oldViewportSize) => {
|
||||
if (
|
||||
oldViewportSize.width === viewportSize.width &&
|
||||
oldViewportSize.height === viewportSize.height
|
||||
) {
|
||||
return oldViewportSize;
|
||||
}
|
||||
|
||||
return viewportSize;
|
||||
});
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const effectTwice = () => {
|
||||
updateViewportSize();
|
||||
setTimeout(updateViewportSize, 1000);
|
||||
};
|
||||
|
||||
window.addEventListener('resize', effectTwice);
|
||||
window.addEventListener('orientationchange', effectTwice);
|
||||
window.visualViewport?.addEventListener('resize', effectTwice);
|
||||
|
||||
return () => {
|
||||
window.removeEventListener('resize', effectTwice);
|
||||
window.removeEventListener('orientationchange', effectTwice);
|
||||
window.visualViewport?.removeEventListener('resize', effectTwice);
|
||||
};
|
||||
}, [updateViewportSize]);
|
||||
|
||||
return viewportSize;
|
||||
}
|
||||
Reference in new issue
Block a user