143e2c802d
* Add common gutter styles as hook * Add computed scrollbar gutter CSS vars * Add new layout components * Replace layout components in settings screens * Remove old back button * Invert web border logic for easier migration * Clean up Slot API * Port over FF handling of scrollbar offset * Trade boilerplate for ease of use * Limit to one line * Allow two lines, fix wrapping * Fix alignment * sticky headers * set max with on header and center * [Layout] Notifications Header (#6910) * Replace notifications screen header * fix cropped indicator --------- Co-authored-by: Samuel Newman <mozzius@protonmail.com> * Replace Hashtag header (#6928) * [Layout] ChatList header (#6929) * Replace ChatList header * update chat settings as well --------- Co-authored-by: Samuel Newman <mozzius@protonmail.com> * Add web borders to Chat settings * Remove unused var * Move ChatList header outside center * Replace empty chat layout * fix breakpoints * [Layout] Scrollbar gutters (#6908) * Fix sidebar alignment * Make sure scrollbars don't hide * Gift left nav more space * Use stable one-edge, update logic in RightNav * Ope * Increase width * Reset * Add transform to sidebars * Remove bg in sidebars * Handle shifts in layout components * Replace scroll-removal handling * Make react-remove-scroll an explicit dep * Remove unused script * use correct scroll insets (#6950) * [Layout] Feeds headers (#6913) * Replace ViewHeader internals, duplicate old ViewHeader * Replace Feeds header * Replace SavedFeeds header * Visual alignment * Uglier but clear * Use old ViewHeader for SavedFeeds * use Layout.Center instead of Layout.Content * use left-aligned header for feed edit * delete unused old view header --------- Co-authored-by: Samuel Newman <mozzius@protonmail.com> * [Layout] Every other screen (#6953) * attempt to fix double borders on every other screen * delete ListHeaderDesktop * delete `SimpleViewHeader` and fix screens (#6956) * Make Layout.Center not full height * Refactor List to use Layout.Center, remove built-in borders * Fix Home screen * Refactor PagerWithHeader to use Layout components * Replace components in ProfileFeed and ProfileList * Borders on Profile * Search screen replacements * use new header for profile subpage header (#6958) * Search AutocompleteResults * use new header for starter pack wizard (#6957) * Fix post thread * Enable borders by default * Moderation muted and blocked accounts * Fix scrollbar offset on Labeler * Remove ScrollView from Moderation * Remove ScrollView from Deactivated * Remove ScrollView from onboarding * Remove ScrollView from SignupQueued * Mark deprecations * fix lint * Fix double borders on profile load * Remove unneeded CenteredView from noty Feed * Remove double Center layout on Notifications screen * Remove double Center layout on ChatList screen * Handle scrollbar offset in chat * Use new atom for other scrollbar offsets * Remove borders from old views * Better doc * Remove temp migration prop * Fix new atom usage on native * Clean up Hashtag screen * Layout docs * Clarify usage in Pager * Handle nested offset contexts * Clean up Layout * fix feeds page * asymmetric header on native (#6969) * Reusable header const * Fix up home header * Add back button to convo * Add hitslop to header buttons * Comment * Better handling on native for new atom * Format * Fix nested flatlist on mod screens * Use react-remove-scroll-bar directly * Fix notification count overflow on web * Clarify doc --------- Co-authored-by: Samuel Newman <mozzius@protonmail.com>
284 lines
7.3 KiB
TypeScript
284 lines
7.3 KiB
TypeScript
import React, {useImperativeHandle} from 'react'
|
|
import {
|
|
FlatList,
|
|
FlatListProps,
|
|
StyleProp,
|
|
TouchableWithoutFeedback,
|
|
View,
|
|
ViewStyle,
|
|
} from 'react-native'
|
|
import {msg} from '@lingui/macro'
|
|
import {useLingui} from '@lingui/react'
|
|
import {DismissableLayer} from '@radix-ui/react-dismissable-layer'
|
|
import {useFocusGuards} from '@radix-ui/react-focus-guards'
|
|
import {FocusScope} from '@radix-ui/react-focus-scope'
|
|
import {RemoveScrollBar} from 'react-remove-scroll-bar'
|
|
|
|
import {logger} from '#/logger'
|
|
import {useDialogStateControlContext} from '#/state/dialogs'
|
|
import {atoms as a, flatten, useBreakpoints, useTheme, web} from '#/alf'
|
|
import {Button, ButtonIcon} from '#/components/Button'
|
|
import {Context} from '#/components/Dialog/context'
|
|
import {
|
|
DialogControlProps,
|
|
DialogInnerProps,
|
|
DialogOuterProps,
|
|
} from '#/components/Dialog/types'
|
|
import {TimesLarge_Stroke2_Corner0_Rounded as X} from '#/components/icons/Times'
|
|
import {Portal} from '#/components/Portal'
|
|
|
|
export {useDialogContext, useDialogControl} from '#/components/Dialog/context'
|
|
export * from '#/components/Dialog/shared'
|
|
export * from '#/components/Dialog/types'
|
|
export * from '#/components/Dialog/utils'
|
|
export {Input} from '#/components/forms/TextField'
|
|
|
|
const stopPropagation = (e: any) => e.stopPropagation()
|
|
const preventDefault = (e: any) => e.preventDefault()
|
|
|
|
export function Outer({
|
|
children,
|
|
control,
|
|
onClose,
|
|
}: React.PropsWithChildren<DialogOuterProps>) {
|
|
const {_} = useLingui()
|
|
const {gtMobile} = useBreakpoints()
|
|
const [isOpen, setIsOpen] = React.useState(false)
|
|
const {setDialogIsOpen} = useDialogStateControlContext()
|
|
|
|
const open = React.useCallback(() => {
|
|
setDialogIsOpen(control.id, true)
|
|
setIsOpen(true)
|
|
}, [setIsOpen, setDialogIsOpen, control.id])
|
|
|
|
const close = React.useCallback<DialogControlProps['close']>(
|
|
cb => {
|
|
setDialogIsOpen(control.id, false)
|
|
setIsOpen(false)
|
|
|
|
try {
|
|
if (cb && typeof cb === 'function') {
|
|
// This timeout ensures that the callback runs at the same time as it would on native. I.e.
|
|
// console.log('Step 1') -> close(() => console.log('Step 3')) -> console.log('Step 2')
|
|
// This should always output 'Step 1', 'Step 2', 'Step 3', but without the timeout it would output
|
|
// 'Step 1', 'Step 3', 'Step 2'.
|
|
setTimeout(cb)
|
|
}
|
|
} catch (e: any) {
|
|
logger.error(`Dialog closeCallback failed`, {
|
|
message: e.message,
|
|
})
|
|
}
|
|
|
|
onClose?.()
|
|
},
|
|
[control.id, onClose, setDialogIsOpen],
|
|
)
|
|
|
|
const handleBackgroundPress = React.useCallback(async () => {
|
|
close()
|
|
}, [close])
|
|
|
|
useImperativeHandle(
|
|
control.ref,
|
|
() => ({
|
|
open,
|
|
close,
|
|
}),
|
|
[close, open],
|
|
)
|
|
|
|
const context = React.useMemo(
|
|
() => ({
|
|
close,
|
|
isNativeDialog: false,
|
|
nativeSnapPoint: 0,
|
|
disableDrag: false,
|
|
setDisableDrag: () => {},
|
|
}),
|
|
[close],
|
|
)
|
|
|
|
return (
|
|
<>
|
|
{isOpen && (
|
|
<Portal>
|
|
<Context.Provider value={context}>
|
|
<RemoveScrollBar />
|
|
<TouchableWithoutFeedback
|
|
accessibilityHint={undefined}
|
|
accessibilityLabel={_(msg`Close active dialog`)}
|
|
onPress={handleBackgroundPress}>
|
|
<View
|
|
style={[
|
|
web(a.fixed),
|
|
a.inset_0,
|
|
a.z_10,
|
|
a.align_center,
|
|
gtMobile ? a.p_lg : a.p_md,
|
|
{overflowY: 'auto'},
|
|
]}>
|
|
<Backdrop />
|
|
<View
|
|
style={[
|
|
a.w_full,
|
|
a.z_20,
|
|
a.justify_center,
|
|
a.align_center,
|
|
{
|
|
minHeight: web('calc(90vh - 36px)') || undefined,
|
|
},
|
|
]}>
|
|
{children}
|
|
</View>
|
|
</View>
|
|
</TouchableWithoutFeedback>
|
|
</Context.Provider>
|
|
</Portal>
|
|
)}
|
|
</>
|
|
)
|
|
}
|
|
|
|
export function Inner({
|
|
children,
|
|
style,
|
|
label,
|
|
accessibilityLabelledBy,
|
|
accessibilityDescribedBy,
|
|
header,
|
|
contentContainerStyle,
|
|
}: DialogInnerProps) {
|
|
const t = useTheme()
|
|
const {close} = React.useContext(Context)
|
|
const {gtMobile} = useBreakpoints()
|
|
useFocusGuards()
|
|
return (
|
|
<FocusScope loop asChild trapped>
|
|
<View
|
|
role="dialog"
|
|
aria-role="dialog"
|
|
aria-label={label}
|
|
aria-labelledby={accessibilityLabelledBy}
|
|
aria-describedby={accessibilityDescribedBy}
|
|
// @ts-ignore web only -prf
|
|
onClick={stopPropagation}
|
|
onStartShouldSetResponder={_ => true}
|
|
onTouchEnd={stopPropagation}
|
|
style={flatten([
|
|
a.relative,
|
|
a.rounded_md,
|
|
a.w_full,
|
|
a.border,
|
|
t.atoms.bg,
|
|
{
|
|
maxWidth: 600,
|
|
borderColor: t.palette.contrast_200,
|
|
shadowColor: t.palette.black,
|
|
shadowOpacity: t.name === 'light' ? 0.1 : 0.4,
|
|
shadowRadius: 30,
|
|
// @ts-ignore web only
|
|
animation: 'fadeIn ease-out 0.1s',
|
|
},
|
|
flatten(style),
|
|
])}>
|
|
<DismissableLayer
|
|
onInteractOutside={preventDefault}
|
|
onFocusOutside={preventDefault}
|
|
onDismiss={close}
|
|
style={{display: 'flex', flexDirection: 'column'}}>
|
|
{header}
|
|
<View style={[gtMobile ? a.p_2xl : a.p_xl, contentContainerStyle]}>
|
|
{children}
|
|
</View>
|
|
</DismissableLayer>
|
|
</View>
|
|
</FocusScope>
|
|
)
|
|
}
|
|
|
|
export const ScrollableInner = Inner
|
|
|
|
export const InnerFlatList = React.forwardRef<
|
|
FlatList,
|
|
FlatListProps<any> & {label: string} & {
|
|
webInnerStyle?: StyleProp<ViewStyle>
|
|
webInnerContentContainerStyle?: StyleProp<ViewStyle>
|
|
}
|
|
>(function InnerFlatList(
|
|
{label, style, webInnerStyle, webInnerContentContainerStyle, ...props},
|
|
ref,
|
|
) {
|
|
const {gtMobile} = useBreakpoints()
|
|
return (
|
|
<Inner
|
|
label={label}
|
|
style={[
|
|
a.overflow_hidden,
|
|
a.px_0,
|
|
// @ts-ignore web only -sfn
|
|
{maxHeight: 'calc(-36px + 100vh)'},
|
|
webInnerStyle,
|
|
]}
|
|
contentContainerStyle={[a.px_0, webInnerContentContainerStyle]}>
|
|
<FlatList
|
|
ref={ref}
|
|
style={[gtMobile ? a.px_2xl : a.px_xl, flatten(style)]}
|
|
{...props}
|
|
/>
|
|
</Inner>
|
|
)
|
|
})
|
|
|
|
export function Close() {
|
|
const {_} = useLingui()
|
|
const {close} = React.useContext(Context)
|
|
return (
|
|
<View
|
|
style={[
|
|
a.absolute,
|
|
a.z_10,
|
|
{
|
|
top: a.pt_md.paddingTop,
|
|
right: a.pr_md.paddingRight,
|
|
},
|
|
]}>
|
|
<Button
|
|
size="small"
|
|
variant="ghost"
|
|
color="secondary"
|
|
shape="round"
|
|
onPress={() => close()}
|
|
label={_(msg`Close active dialog`)}>
|
|
<ButtonIcon icon={X} size="md" />
|
|
</Button>
|
|
</View>
|
|
)
|
|
}
|
|
|
|
export function Handle() {
|
|
return null
|
|
}
|
|
|
|
function Backdrop() {
|
|
const t = useTheme()
|
|
return (
|
|
<View
|
|
style={{
|
|
opacity: 0.8,
|
|
}}>
|
|
<View
|
|
style={[
|
|
a.fixed,
|
|
a.inset_0,
|
|
{
|
|
backgroundColor: t.palette.black,
|
|
// @ts-ignore web only
|
|
animation: 'fadeIn ease-out 0.15s',
|
|
},
|
|
]}
|
|
/>
|
|
</View>
|
|
)
|
|
}
|