Files
bsky-social-app/src/view/com/modals/Modal.tsx
T
Samuel Newman ff23ebb58e Replace Add User to Lists modal with modern Dialog component
Migrate from deprecated modal system to modern Dialog system using the efficient getListsWithMembership() API instead of the inefficient useDangerousListMembershipsQuery(). Adds optimistic updates for faster UI feedback on add/remove operations.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-06-04 09:59:41 +03:00

92 lines
2.4 KiB
TypeScript

import {Fragment, useEffect, useRef} from 'react'
import {StyleSheet} from 'react-native'
import {SafeAreaView} from 'react-native-safe-area-context'
import BottomSheet from '@discord/bottom-sheet/src'
import {usePalette} from '#/lib/hooks/usePalette'
import {useModalControls, useModals} from '#/state/modals'
import {FullWindowOverlay} from '#/components/FullWindowOverlay'
import {createCustomBackdrop} from '../util/BottomSheetCustomBackdrop'
const DEFAULT_SNAPPOINTS = ['90%']
const HANDLE_HEIGHT = 24
export function ModalsContainer() {
const {isModalActive, activeModals} = useModals()
const {closeModal} = useModalControls()
const bottomSheetRef = useRef<BottomSheet>(null)
const pal = usePalette('default')
const activeModal = activeModals[activeModals.length - 1]
const onBottomSheetChange = async (snapPoint: number) => {
if (snapPoint === -1) {
closeModal()
}
}
const onClose = () => {
bottomSheetRef.current?.close()
closeModal()
}
useEffect(() => {
if (isModalActive) {
bottomSheetRef.current?.snapToIndex(0)
} else {
bottomSheetRef.current?.close()
}
}, [isModalActive, bottomSheetRef, activeModal?.name])
let snapPoints: (string | number)[] = DEFAULT_SNAPPOINTS
let element
{
return null
}
if (snapPoints[0] === 'fullscreen') {
return (
<SafeAreaView style={[styles.fullscreenContainer, pal.view]}>
{element}
</SafeAreaView>
)
}
const Container = activeModal ? FullWindowOverlay : Fragment
return (
<Container>
<BottomSheet
ref={bottomSheetRef}
snapPoints={snapPoints}
handleHeight={HANDLE_HEIGHT}
index={isModalActive ? 0 : -1}
enablePanDownToClose
android_keyboardInputMode="adjustResize"
keyboardBlurBehavior="restore"
backdropComponent={
isModalActive ? createCustomBackdrop(onClose) : undefined
}
handleIndicatorStyle={{backgroundColor: pal.text.color}}
handleStyle={[styles.handle, pal.view]}
backgroundStyle={pal.view}
onChange={onBottomSheetChange}>
{element}
</BottomSheet>
</Container>
)
}
const styles = StyleSheet.create({
handle: {
borderTopLeftRadius: 10,
borderTopRightRadius: 10,
},
fullscreenContainer: {
position: 'absolute',
top: 0,
left: 0,
bottom: 0,
right: 0,
},
})