Skip to content

Commit

Permalink
nesting support
Browse files Browse the repository at this point in the history
  • Loading branch information
haileyok committed Oct 2, 2024
1 parent 87c83dd commit 5a60190
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 23 deletions.
58 changes: 38 additions & 20 deletions src/components/Dialog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,26 @@ export function Outer({
onClose,
nativeOptions,
testID,
}: React.PropsWithChildren<DialogOuterProps>) {
return (
<Portal>
<OuterWithoutPortal
control={control}
onClose={onClose}
nativeOptions={nativeOptions}
testID={testID}>
{children}
</OuterWithoutPortal>
</Portal>
)
}

export function OuterWithoutPortal({
children,
control,
onClose,
nativeOptions,
testID,
}: React.PropsWithChildren<DialogOuterProps>) {
const t = useTheme()
const ref = React.useRef<BlueskyBottomSheetView>(null)
Expand Down Expand Up @@ -93,26 +113,24 @@ export function Outer({
const context = React.useMemo(() => ({close}), [close])

return (
<Portal>
<Context.Provider value={context}>
<BlueskyBottomSheetView
// handleIndicatorStyle={{backgroundColor: t.palette.primary_500}} // @TODO DIALOG REFACTOR need to add this to lib!*/
ref={ref}
topInset={30}
bottomInset={insets.bottom}
onStateChange={e => {
if (e.nativeEvent.state === 'closed') {
onCloseAnimationComplete()
}
}}
cornerRadius={20}
{...nativeOptions}>
<View testID={testID} style={[t.atoms.bg]}>
{children}
</View>
</BlueskyBottomSheetView>
</Context.Provider>
</Portal>
<Context.Provider value={context}>
<BlueskyBottomSheetView
// handleIndicatorStyle={{backgroundColor: t.palette.primary_500}} // @TODO DIALOG REFACTOR need to add this to lib!*/
ref={ref}
topInset={30}
bottomInset={insets.bottom}
onStateChange={e => {
if (e.nativeEvent.state === 'closed') {
onCloseAnimationComplete()
}
}}
cornerRadius={20}
{...nativeOptions}>
<View testID={testID} style={[t.atoms.bg]}>
{children}
</View>
</BlueskyBottomSheetView>
</Context.Provider>
)
}

Expand Down
17 changes: 14 additions & 3 deletions src/components/Prompt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {PressableEvent} from 'react-native-gesture-handler/lib/typescript/compon
import {msg} from '@lingui/macro'
import {useLingui} from '@lingui/react'

import {isNative} from '#/platform/detection'
import {atoms as a, useBreakpoints, useTheme} from '#/alf'
import {BottomSheetButton} from '#/components/BottomSheetButton'
import {ButtonColor, ButtonText} from '#/components/Button'
Expand All @@ -27,9 +28,11 @@ export function Outer({
children,
control,
testID,
withoutPortal,
}: React.PropsWithChildren<{
control: Dialog.DialogControlProps
testID?: string
withoutPortal?: boolean
}>) {
const {gtMobile} = useBreakpoints()
const titleId = React.useId()
Expand All @@ -40,8 +43,11 @@ export function Outer({
[titleId, descriptionId],
)

const Wrapper =
withoutPortal && isNative ? Dialog.OuterWithoutPortal : Dialog.Outer

return (
<Dialog.Outer control={control} testID={testID}>
<Wrapper control={control} testID={testID}>
<Context.Provider value={context}>
<Dialog.ScrollableInner
accessibilityLabelledBy={titleId}
Expand All @@ -52,7 +58,7 @@ export function Outer({
{children}
</Dialog.ScrollableInner>
</Context.Provider>
</Dialog.Outer>
</Wrapper>
)
}

Expand Down Expand Up @@ -181,6 +187,7 @@ export function Basic({
onConfirm,
confirmButtonColor,
showCancel = true,
withoutPortal,
}: React.PropsWithChildren<{
control: Dialog.DialogOuterProps['control']
title: string
Expand All @@ -197,9 +204,13 @@ export function Basic({
onConfirm: (e: PressableEvent) => void
confirmButtonColor?: ButtonColor
showCancel?: boolean
withoutPortal?: boolean
}>) {
return (
<Outer control={control} testID="confirmModal">
<Outer
control={control}
testID="confirmModal"
withoutPortal={withoutPortal}>
<TitleText>{title}</TitleText>
<DescriptionText>{description}</DescriptionText>
<Actions>
Expand Down
1 change: 1 addition & 0 deletions src/view/com/composer/Composer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,7 @@ export const ComposePost = ({
onConfirm={onClose}
confirmButtonCta={_(msg`Discard`)}
confirmButtonColor="negative"
withoutPortal={true}
/>
</KeyboardAvoidingView>
)
Expand Down

0 comments on commit 5a60190

Please sign in to comment.