From c3d0cc55d98fb32b25cd2164cfa1c399985e7c84 Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Tue, 15 Oct 2024 21:57:28 +0300 Subject: Edit profile dialog ALF refresh (#5633) --- src/components/Dialog/index.tsx | 44 +++++++++++++++++--------- src/components/Dialog/index.web.tsx | 9 ++++-- src/components/Dialog/shared.tsx | 61 +++++++++++++++++++++++++++++++++++++ src/components/Dialog/types.ts | 6 ++++ 4 files changed, 103 insertions(+), 17 deletions(-) create mode 100644 src/components/Dialog/shared.tsx (limited to 'src/components/Dialog') diff --git a/src/components/Dialog/index.tsx b/src/components/Dialog/index.tsx index 93acad438..46c072ce4 100644 --- a/src/components/Dialog/index.tsx +++ b/src/components/Dialog/index.tsx @@ -40,6 +40,7 @@ import { import {BottomSheetNativeComponent} from '../../../modules/bottom-sheet/src/BottomSheetNativeComponent' export {useDialogContext, useDialogControl} from '#/components/Dialog/context' +export * from '#/components/Dialog/shared' export * from '#/components/Dialog/types' export * from '#/components/Dialog/utils' // @ts-ignore @@ -169,25 +170,31 @@ export function Outer({ ) } -export function Inner({children, style}: DialogInnerProps) { +export function Inner({children, style, header}: DialogInnerProps) { const insets = useSafeAreaInsets() return ( - - {children} - + <> + {header} + + {children} + + ) } export const ScrollableInner = React.forwardRef( - function ScrollableInner({children, style, ...props}, ref) { + function ScrollableInner( + {children, style, contentContainerStyle, header, ...props}, + ref, + ) { const {nativeSnapPoint, disableDrag, setDisableDrag} = useDialogContext() const insets = useSafeAreaInsets() const {setEnabled} = useKeyboardController() @@ -232,14 +239,21 @@ export const ScrollableInner = React.forwardRef( return ( + keyboardShouldPersistTaps="handled" + stickyHeaderIndices={header ? [0] : undefined}> + {header} {children} ) diff --git a/src/components/Dialog/index.web.tsx b/src/components/Dialog/index.web.tsx index 1a20311d3..43cb95b03 100644 --- a/src/components/Dialog/index.web.tsx +++ b/src/components/Dialog/index.web.tsx @@ -28,6 +28,7 @@ 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' @@ -154,6 +155,8 @@ export function Inner({ label, accessibilityLabelledBy, accessibilityDescribedBy, + header, + contentContainerStyle, }: DialogInnerProps) { const t = useTheme() const {close} = React.useContext(Context) @@ -178,7 +181,6 @@ export function Inner({ a.rounded_md, a.w_full, a.border, - gtMobile ? a.p_2xl : a.p_xl, t.atoms.bg, { maxWidth: 600, @@ -194,7 +196,10 @@ export function Inner({ onFocusOutside={preventDefault} onDismiss={close} style={{display: 'flex', flexDirection: 'column'}}> - {children} + {header} + + {children} + diff --git a/src/components/Dialog/shared.tsx b/src/components/Dialog/shared.tsx new file mode 100644 index 000000000..6f9bc2678 --- /dev/null +++ b/src/components/Dialog/shared.tsx @@ -0,0 +1,61 @@ +import React from 'react' +import {StyleProp, TextStyle, View, ViewStyle} from 'react-native' + +import {atoms as a, useTheme, web} from '#/alf' +import {Text} from '#/components/Typography' + +export function Header({ + renderLeft, + renderRight, + children, + style, +}: { + renderLeft?: () => React.ReactNode + renderRight?: () => React.ReactNode + children?: React.ReactNode + style?: StyleProp +}) { + const t = useTheme() + return ( + + {renderLeft && ( + {renderLeft()} + )} + {children} + {renderRight && ( + {renderRight()} + )} + + ) +} + +export function HeaderText({ + children, + style, +}: { + children?: React.ReactNode + style?: StyleProp +}) { + return ( + + {children} + + ) +} diff --git a/src/components/Dialog/types.ts b/src/components/Dialog/types.ts index b1388a817..526784baa 100644 --- a/src/components/Dialog/types.ts +++ b/src/components/Dialog/types.ts @@ -4,6 +4,8 @@ import type { GestureResponderEvent, ScrollViewProps, } from 'react-native' +import {ViewStyle} from 'react-native' +import {StyleProp} from 'react-native' import {ViewStyleProp} from '#/alf' import {BottomSheetViewProps} from '../../../modules/bottom-sheet' @@ -69,10 +71,14 @@ export type DialogInnerProps = accessibilityLabelledBy: A11yProps['aria-labelledby'] accessibilityDescribedBy: string keyboardDismissMode?: ScrollViewProps['keyboardDismissMode'] + contentContainerStyle?: StyleProp + header?: React.ReactNode }> | DialogInnerPropsBase<{ label: string accessibilityLabelledBy?: undefined accessibilityDescribedBy?: undefined keyboardDismissMode?: ScrollViewProps['keyboardDismissMode'] + contentContainerStyle?: StyleProp + header?: React.ReactNode }> -- cgit 1.4.1