Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix alt text - allow keyboard dismiss to be handled by scrollviews #5534

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions src/components/Dialog/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import React, {useImperativeHandle} from 'react'
import {
Dimensions,
Keyboard,
Pressable,
StyleProp,
useWindowDimensions,
View,
ViewStyle,
} from 'react-native'
Expand Down Expand Up @@ -96,6 +95,7 @@ export function Outer({
const insets = useSafeAreaInsets()
const closeCallbacks = React.useRef<(() => void)[]>([])
const {setDialogIsOpen} = useDialogStateControlContext()
const {height: windowHeight} = useWindowDimensions()

/*
* Used to manage open/closed, but index is otherwise handled internally by `BottomSheet`
Expand Down Expand Up @@ -179,8 +179,7 @@ export function Outer({
// Android
importantForAccessibility="yes"
style={[a.absolute, a.inset_0]}
testID={testID}
onTouchMove={() => Keyboard.dismiss()}>
testID={testID}>
<BottomSheet
enableDynamicSizing={!hasSnapPoints}
enablePanDownToClose
Expand All @@ -206,7 +205,7 @@ export function Outer({
{
borderTopLeftRadius: 40,
borderTopRightRadius: 40,
height: Dimensions.get('window').height * 2,
height: windowHeight * 2,
},
]}
/>
Expand Down Expand Up @@ -243,11 +242,20 @@ export function Inner({children, style}: DialogInnerProps) {
export const ScrollableInner = React.forwardRef<
BottomSheetScrollViewMethods,
DialogInnerProps
>(function ScrollableInner({children, style}, ref) {
>(function ScrollableInner(
{
children,
style,
keyboardShouldPersistTaps = 'handled',
keyboardDismissMode = 'on-drag',
},
ref,
) {
const insets = useSafeAreaInsets()
return (
<BottomSheetScrollView
keyboardShouldPersistTaps="handled"
keyboardShouldPersistTaps={keyboardShouldPersistTaps}
keyboardDismissMode={keyboardDismissMode}
style={[
a.flex_1, // main diff is this
a.p_xl,
Expand Down Expand Up @@ -276,6 +284,7 @@ export const InnerFlatList = React.forwardRef<
return (
<BottomSheetFlatList
keyboardShouldPersistTaps="handled"
keyboardDismissMode="on-drag"
contentContainerStyle={[a.pb_4xl, flatten(contentContainerStyle)]}
ListFooterComponent={
<View style={{height: insets.bottom + a.pt_5xl.paddingTop}} />
Expand Down
2 changes: 2 additions & 0 deletions src/components/Dialog/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,12 @@ export type DialogInnerProps =
accessibilityLabelledBy: A11yProps['aria-labelledby']
accessibilityDescribedBy: string
keyboardDismissMode?: ScrollViewProps['keyboardDismissMode']
keyboardShouldPersistTaps?: ScrollViewProps['keyboardShouldPersistTaps']
}>
| DialogInnerPropsBase<{
label: string
accessibilityLabelledBy?: undefined
accessibilityDescribedBy?: undefined
keyboardDismissMode?: ScrollViewProps['keyboardDismissMode']
keyboardShouldPersistTaps?: ScrollViewProps['keyboardShouldPersistTaps']
}>
4 changes: 2 additions & 2 deletions src/components/dialogs/GifSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ import {GifPreview} from './GifSelect.shared'

export function GifSelectDialog({
controlRef,
onClose,
onSelectGif: onSelectGifProp,
onClose,
}: {
controlRef: React.RefObject<{open: () => void}>
onClose: () => void
onSelectGif: (gif: Gif) => void
onClose?: () => void
}) {
const control = Dialog.useDialogControl()

Expand Down
12 changes: 2 additions & 10 deletions src/view/com/composer/Composer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ import {ComposerOpts} from '#/state/shell/composer'
import {CharProgress} from '#/view/com/composer/char-progress/CharProgress'
import {ComposerReplyTo} from '#/view/com/composer/ComposerReplyTo'
import {ExternalEmbed} from '#/view/com/composer/ExternalEmbed'
import {GifAltText} from '#/view/com/composer/GifAltText'
import {LabelsBtn} from '#/view/com/composer/labels/LabelsBtn'
import {Gallery} from '#/view/com/composer/photos/Gallery'
import {GifAltText} from '#/view/com/composer/photos/GifAltTextDialog'
import {OpenCameraBtn} from '#/view/com/composer/photos/OpenCameraBtn'
import {SelectGifBtn} from '#/view/com/composer/photos/SelectGifBtn'
import {SelectPhotoBtn} from '#/view/com/composer/photos/SelectPhotoBtn'
Expand Down Expand Up @@ -528,10 +528,6 @@ export const ComposePost = ({
openEmojiPicker?.(textInput.current?.getCursorPosition())
}, [openEmojiPicker])

const focusTextInput = useCallback(() => {
textInput.current?.focus()
}, [])

const onSelectGif = useCallback(
(gif: Gif) => {
setExtLink({
Expand Down Expand Up @@ -813,11 +809,7 @@ export const ComposePost = ({
setError={setError}
/>
<OpenCameraBtn disabled={!canSelectImages} onAdd={onImageAdd} />
<SelectGifBtn
onClose={focusTextInput}
onSelectGif={onSelectGif}
disabled={hasMedia}
/>
<SelectGifBtn onSelectGif={onSelectGif} disabled={hasMedia} />
{!isMobile ? (
<Button
onPress={onEmojiButtonPress}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@ import {
parseEmbedPlayerFromUrl,
} from '#/lib/strings/embed-player'
import {enforceLen} from '#/lib/strings/helpers'
import {isAndroid} from '#/platform/detection'
import {Gif} from '#/state/queries/tenor'
import {GifEmbed} from '#/view/com/util/post-embeds/GifEmbed'
import {atoms as a, native, useTheme} from '#/alf'
import {Button, ButtonText} from '#/components/Button'
import * as Dialog from '#/components/Dialog'
import * as TextField from '#/components/forms/TextField'
import {Check_Stroke2_Corner0_Rounded as Check} from '#/components/icons/Check'
import {PlusSmall_Stroke2_Corner0_Rounded as Plus} from '#/components/icons/Plus'
import {Text} from '#/components/Typography'
import {GifEmbed} from '../util/post-embeds/GifEmbed'
import {AltTextReminder} from './photos/Gallery'
import {AltTextReminder} from './Gallery'

export function GifAltText({
link: linkProp,
Expand Down Expand Up @@ -98,7 +97,7 @@ export function GifAltText({

<Dialog.Outer
control={control}
nativeOptions={isAndroid ? {sheet: {snapPoints: ['100%']}} : {}}>
nativeOptions={{sheet: {snapPoints: ['100%']}}}>
<Dialog.Handle />
<AltTextInner
onSubmit={onPressSubmit}
Expand Down Expand Up @@ -132,7 +131,9 @@ function AltTextInner({
}, [onSubmit, altText])

return (
<Dialog.ScrollableInner label={_(msg`Add alt text`)}>
<Dialog.ScrollableInner
label={_(msg`Add alt text`)}
keyboardDismissMode="none">
<View style={a.flex_col_reverse}>
<View style={[a.mt_md, a.gap_md]}>
<View>
Expand Down
14 changes: 9 additions & 5 deletions src/view/com/composer/photos/ImageAltTextDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ type Props = {

export const ImageAltTextDialog = (props: Props): React.ReactNode => {
return (
<Dialog.Outer control={props.control}>
<Dialog.Outer
control={props.control}
nativeOptions={{sheet: {snapPoints: ['100%']}}}>
<Dialog.Handle />

<ImageAltTextInner {...props} />
Expand Down Expand Up @@ -66,15 +68,15 @@ const ImageAltTextInner = ({
}, [image, windim])

return (
<Dialog.ScrollableInner label={_(msg`Add alt text`)}>
<Dialog.Close />

<Dialog.ScrollableInner
label={_(msg`Add alt text`)}
keyboardDismissMode="none">
<View>
<Text style={[a.text_2xl, a.font_bold, a.leading_tight, a.pb_sm]}>
<Trans>Add alt text</Trans>
</Text>

<View style={[t.atoms.bg_contrast_50, a.rounded_sm, a.overflow_hidden]}>
<View style={[t.atoms.bg_contrast_50, a.rounded_md, a.overflow_hidden]}>
<Image
style={imageStyle}
source={{
Expand Down Expand Up @@ -116,6 +118,8 @@ const ImageAltTextInner = ({
</ButtonText>
</Button>
</View>

<Dialog.Close />
</Dialog.ScrollableInner>
)
}
2 changes: 1 addition & 1 deletion src/view/com/composer/photos/SelectGifBtn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import {GifSelectDialog} from '#/components/dialogs/GifSelect'
import {GifSquare_Stroke2_Corner0_Rounded as GifIcon} from '#/components/icons/Gif'

type Props = {
onClose: () => void
onSelectGif: (gif: Gif) => void
onClose?: () => void
disabled?: boolean
}

Expand Down
Loading