From c49182009a256ec8ef77bd2cc1830620534a21d5 Mon Sep 17 00:00:00 2001 From: Hailey Date: Wed, 2 Oct 2024 21:26:58 -0700 Subject: [PATCH] [Sheets] [Pt. 8] Allow nesting in other sheets or native modals (#5567) --- package.json | 2 +- src/components/Dialog/index.tsx | 61 +++++++++++++------ src/components/Dialog/index.web.tsx | 1 + src/components/Link.tsx | 5 +- src/components/Prompt.tsx | 23 +++++-- .../ReportDialog/SelectLabelerView.tsx | 7 +-- src/components/ReportDialog/index.tsx | 3 +- .../moderation/LabelsOnMeDialog.tsx | 15 +++-- .../moderation/ModerationDetailsDialog.tsx | 34 ++++++----- src/view/com/composer/Composer.tsx | 1 + yarn.lock | 8 +-- 11 files changed, 97 insertions(+), 63 deletions(-) diff --git a/package.json b/package.json index e32100ece8..273d8ddb35 100644 --- a/package.json +++ b/package.json @@ -68,7 +68,7 @@ "@fortawesome/free-regular-svg-icons": "^6.1.1", "@fortawesome/free-solid-svg-icons": "^6.1.1", "@fortawesome/react-native-fontawesome": "^0.3.2", - "@haileyok/bluesky-bottom-sheet": "^0.1.1-alpha.8", + "@haileyok/bluesky-bottom-sheet": "^0.1.1-alpha.9", "@haileyok/bluesky-video": "0.1.10", "@lingui/react": "^4.5.0", "@mattermost/react-native-paste-input": "^0.7.1", diff --git a/src/components/Dialog/index.tsx b/src/components/Dialog/index.tsx index 6fbc8d87a0..7493e7748b 100644 --- a/src/components/Dialog/index.tsx +++ b/src/components/Dialog/index.tsx @@ -1,12 +1,13 @@ import React, {useImperativeHandle} from 'react' import {StyleProp, TextInput, View, ViewStyle} from 'react-native' +import {GestureHandlerRootView, ScrollView} from 'react-native-gesture-handler' import {useSafeAreaInsets} from 'react-native-safe-area-context' import {BlueskyBottomSheetView} from '@haileyok/bluesky-bottom-sheet' import {logger} from '#/logger' +import {isIOS} from '#/platform/detection' import {useDialogStateControlContext} from '#/state/dialogs' import {List, ListMethods, ListProps} from '#/view/com/util/List' -import {ScrollView} from '#/view/com/util/Views' import {atoms as a, flatten, useTheme} from '#/alf' import {Context} from '#/components/Dialog/context' import { @@ -29,6 +30,26 @@ export function Outer({ onClose, nativeOptions, testID, +}: React.PropsWithChildren) { + return ( + + + {children} + + + ) +} + +export function OuterWithoutPortal({ + children, + control, + onClose, + nativeOptions, + testID, }: React.PropsWithChildren) { const t = useTheme() const ref = React.useRef(null) @@ -84,26 +105,26 @@ export function Outer({ const context = React.useMemo(() => ({close, insideDialog: true}), [close]) + const Wrapper = isIOS ? View : GestureHandlerRootView + return ( - - - { - if (e.nativeEvent.state === 'closed') { - onCloseAnimationComplete() - } - }} - cornerRadius={20} - {...nativeOptions}> - - {children} - - - - + + { + if (e.nativeEvent.state === 'closed') { + onCloseAnimationComplete() + } + }} + cornerRadius={20} + {...nativeOptions}> + + {children} + + + ) } diff --git a/src/components/Dialog/index.web.tsx b/src/components/Dialog/index.web.tsx index f8ecbd5d94..a50e960a8a 100644 --- a/src/components/Dialog/index.web.tsx +++ b/src/components/Dialog/index.web.tsx @@ -103,6 +103,7 @@ export function Outer({ const context = React.useMemo( () => ({ close, + insideDialog: true, }), [close], ) diff --git a/src/components/Link.tsx b/src/components/Link.tsx index 56d030b5df..5a66767243 100644 --- a/src/components/Link.tsx +++ b/src/components/Link.tsx @@ -23,7 +23,6 @@ import {shouldClickOpenNewTab} from '#/platform/urls' import {useModalControls} from '#/state/modals' import {useOpenLink} from '#/state/preferences/in-app-browser' import {atoms as a, flatten, TextStyleProp, useTheme, web} from '#/alf' -import {BottomSheetButton} from '#/components/BottomSheetButton' import {Button, ButtonProps} from '#/components/Button' import {useInteractionState} from '#/components/hooks/useInteractionState' import {Text, TextProps} from '#/components/Typography' @@ -258,7 +257,7 @@ export function BottomSheetLink({ }) return ( - {children} - + ) } diff --git a/src/components/Prompt.tsx b/src/components/Prompt.tsx index 8aa111bf3d..3e877a6630 100644 --- a/src/components/Prompt.tsx +++ b/src/components/Prompt.tsx @@ -3,8 +3,9 @@ import {GestureResponderEvent, View} from 'react-native' import {msg} from '@lingui/macro' import {useLingui} from '@lingui/react' +import {isNative} from '#/platform/detection' import {atoms as a, useBreakpoints, useTheme} from '#/alf' -import {Button, ButtonColor, ButtonProps, ButtonText} from '#/components/Button' +import {Button, ButtonColor, ButtonText} from '#/components/Button' import * as Dialog from '#/components/Dialog' import {Text} from '#/components/Typography' @@ -25,9 +26,11 @@ export function Outer({ children, control, testID, + withoutPortal, }: React.PropsWithChildren<{ control: Dialog.DialogControlProps testID?: string + withoutPortal?: boolean }>) { const {gtMobile} = useBreakpoints() const titleId = React.useId() @@ -38,8 +41,11 @@ export function Outer({ [titleId, descriptionId], ) + const Wrapper = + withoutPortal && isNative ? Dialog.OuterWithoutPortal : Dialog.Outer + return ( - + - + ) } @@ -139,7 +145,7 @@ export function Action({ * Note: The dialog will close automatically when the action is pressed, you * should NOT close the dialog as a side effect of this method. */ - onPress: ButtonProps['onPress'] + onPress: (e: GestureResponderEvent) => void color?: ButtonColor /** * Optional i18n string. If undefined, it will default to "Confirm". @@ -179,6 +185,7 @@ export function Basic({ onConfirm, confirmButtonColor, showCancel = true, + withoutPortal, }: React.PropsWithChildren<{ control: Dialog.DialogOuterProps['control'] title: string @@ -192,12 +199,16 @@ export function Basic({ * Note: The dialog will close automatically when the action is pressed, you * should NOT close the dialog as a side effect of this method. */ - onConfirm: ButtonProps['onPress'] + onConfirm: (e: GestureResponderEvent) => void confirmButtonColor?: ButtonColor showCancel?: boolean + withoutPortal?: boolean }>) { return ( - + {title} {description} diff --git a/src/components/ReportDialog/SelectLabelerView.tsx b/src/components/ReportDialog/SelectLabelerView.tsx index e62dc9910b..039bbf123f 100644 --- a/src/components/ReportDialog/SelectLabelerView.tsx +++ b/src/components/ReportDialog/SelectLabelerView.tsx @@ -6,8 +6,7 @@ import {useLingui} from '@lingui/react' import {getLabelingServiceTitle} from '#/lib/moderation' import {atoms as a, useBreakpoints, useTheme} from '#/alf' -import {BottomSheetButton} from '#/components/BottomSheetButton' -import {useButtonContext} from '#/components/Button' +import {Button, useButtonContext} from '#/components/Button' import {Divider} from '#/components/Divider' import * as LabelingServiceCard from '#/components/LabelingServiceCard' import {Text} from '#/components/Typography' @@ -39,12 +38,12 @@ export function SelectLabelerView({ {props.labelers.map(labeler => { return ( - props.onSelectLabeler(labeler.creator.did)}> - + ) })} diff --git a/src/components/ReportDialog/index.tsx b/src/components/ReportDialog/index.tsx index b942659380..b781d9f39e 100644 --- a/src/components/ReportDialog/index.tsx +++ b/src/components/ReportDialog/index.tsx @@ -1,5 +1,6 @@ import React from 'react' -import {Pressable, ScrollView, View} from 'react-native' +import {Pressable, View} from 'react-native' +import {ScrollView} from 'react-native-gesture-handler' import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' diff --git a/src/components/moderation/LabelsOnMeDialog.tsx b/src/components/moderation/LabelsOnMeDialog.tsx index 22eb406a00..fc30b004ad 100644 --- a/src/components/moderation/LabelsOnMeDialog.tsx +++ b/src/components/moderation/LabelsOnMeDialog.tsx @@ -13,9 +13,8 @@ import {logger} from '#/logger' import {useAgent, useSession} from '#/state/session' import * as Toast from '#/view/com/util/Toast' import {atoms as a, useBreakpoints, useTheme} from '#/alf' -import {BottomSheetButton} from '#/components/BottomSheetButton' import {BottomSheetInlineLinkText} from '#/components/BottomSheetLink' -import {ButtonIcon, ButtonText} from '#/components/Button' +import {Button, ButtonIcon, ButtonText} from '#/components/Button' import * as Dialog from '#/components/Dialog' import {InlineLinkText} from '#/components/Link' import {Text} from '#/components/Typography' @@ -141,7 +140,7 @@ function Label({ {!isSelfLabel && ( - Appeal - + )} @@ -279,7 +278,7 @@ function AppealForm({ ? [a.flex_row, a.justify_between] : [{flexDirection: 'column-reverse'}, a.gap_sm] }> - {_(msg`Back`)} - - + ) diff --git a/src/components/moderation/ModerationDetailsDialog.tsx b/src/components/moderation/ModerationDetailsDialog.tsx index 1198e8b921..2fb190efa5 100644 --- a/src/components/moderation/ModerationDetailsDialog.tsx +++ b/src/components/moderation/ModerationDetailsDialog.tsx @@ -10,6 +10,7 @@ import {listUriToHref} from '#/lib/strings/url-helpers' import {isNative} from '#/platform/detection' import {useSession} from '#/state/session' import {atoms as a, useTheme} from '#/alf' +import {BottomSheetInlineLinkText} from '#/components/BottomSheetLink' import * as Dialog from '#/components/Dialog' import {Divider} from '#/components/Divider' import {InlineLinkText} from '#/components/Link' @@ -140,23 +141,24 @@ function ModerationDetailsDialogInner({ {modcause?.type === 'label' && ( - - {modcause.source.type === 'user' ? ( + {modcause.source.type === 'user' ? ( + This label was applied by the author. - ) : ( - - This label was applied by{' '} - control.close()} - style={a.text_md}> - {desc.source || _(msg`an unknown labeler`)} - - . - - )} - + + ) : ( + <> + + This label was applied by + + control.close()} + style={a.text_md}> + {desc.source || _(msg`an unknown labeler`)} + + + )} )} diff --git a/src/view/com/composer/Composer.tsx b/src/view/com/composer/Composer.tsx index f354f0f0dc..eb15a78a4b 100644 --- a/src/view/com/composer/Composer.tsx +++ b/src/view/com/composer/Composer.tsx @@ -861,6 +861,7 @@ export const ComposePost = ({ onConfirm={onClose} confirmButtonCta={_(msg`Discard`)} confirmButtonColor="negative" + withoutPortal={true} /> ) diff --git a/yarn.lock b/yarn.lock index d20d4a4cdc..e9f02f5ec4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4120,10 +4120,10 @@ resolved "https://registry.yarnpkg.com/@graphql-typed-document-node/core/-/core-3.2.0.tgz#5f3d96ec6b2354ad6d8a28bf216a1d97b5426861" integrity sha512-mB9oAsNCm9aM3/SOv4YtBMqZbYj10R7dkq8byBqxGY/ncFwhf2oQzMV+LCRlWoDSEBJ3COiR1yeDvMtsoOsuFQ== -"@haileyok/bluesky-bottom-sheet@^0.1.1-alpha.8": - version "0.1.1-alpha.8" - resolved "https://registry.yarnpkg.com/@haileyok/bluesky-bottom-sheet/-/bluesky-bottom-sheet-0.1.1-alpha.8.tgz#c5fd503cdd5556a686a1f5c0974b1527fceda900" - integrity sha512-305MSNscniLZpxd80QO4OCuMXkm+U/v/YW/x0fVQtBilVTikOOPIkiYge+kCUdryFPD3LU/GdrsQZL+y8qAiMQ== +"@haileyok/bluesky-bottom-sheet@^0.1.1-alpha.9": + version "0.1.1-alpha.9" + resolved "https://registry.yarnpkg.com/@haileyok/bluesky-bottom-sheet/-/bluesky-bottom-sheet-0.1.1-alpha.9.tgz#f23a9245d4fed5e1825222249f2ad64ec99896e6" + integrity sha512-duGQ/l20Mr/lmjS7lUu0T0QgARA/V47PrmpL7LZJMoK4IhSBHT4HMSjjOaBcSJhQg2I5/uSX3pShFzCfdGttVQ== "@haileyok/bluesky-video@0.1.10": version "0.1.10"