[Sheets] [Pt. 9] Normalize RNGH pressable, use in remaining places (#5575)

Co-authored-by: Samuel Newman <mozzius@protonmail.com>
This commit is contained in:
Hailey
2024-10-02 21:34:12 -07:00
committed by GitHub
parent a458b4b26a
commit 9039e93ae2
7 changed files with 41 additions and 23 deletions
+7 -7
View File
@@ -89,7 +89,7 @@ export type ButtonProps = Pick<
style?: StyleProp<ViewStyle> style?: StyleProp<ViewStyle>
hoverStyle?: StyleProp<ViewStyle> hoverStyle?: StyleProp<ViewStyle>
children: NonTextElements | ((context: ButtonContext) => NonTextElements) children: NonTextElements | ((context: ButtonContext) => NonTextElements)
Component?: React.ComponentType<PressableProps> PressableComponent?: React.ComponentType<PressableProps>
} }
export type ButtonTextProps = TextProps & VariantProps & {disabled?: boolean} export type ButtonTextProps = TextProps & VariantProps & {disabled?: boolean}
@@ -117,7 +117,7 @@ export const Button = React.forwardRef<View, ButtonProps>(
disabled = false, disabled = false,
style, style,
hoverStyle: hoverStyleProp, hoverStyle: hoverStyleProp,
Component, PressableComponent,
...rest ...rest
}, },
ref, ref,
@@ -125,11 +125,11 @@ export const Button = React.forwardRef<View, ButtonProps>(
// This will pick the correct default pressable to use. If we are inside a dialog, we need to use the RNGH // This will pick the correct default pressable to use. If we are inside a dialog, we need to use the RNGH
// pressable so that it is usable inside the dialog. // pressable so that it is usable inside the dialog.
const {insideDialog} = useDialogContext() const {insideDialog} = useDialogContext()
if (!Component) { if (!PressableComponent) {
if (insideDialog) { if (insideDialog) {
Component = NormalizedRNGHPressable PressableComponent = NormalizedRNGHPressable
} else { } else {
Component = Pressable PressableComponent = Pressable
} }
} }
@@ -464,7 +464,7 @@ export const Button = React.forwardRef<View, ButtonProps>(
const flattenedBaseStyles = flatten([baseStyles, style]) const flattenedBaseStyles = flatten([baseStyles, style])
return ( return (
<Component <PressableComponent
role="button" role="button"
accessibilityHint={undefined} // optional accessibilityHint={undefined} // optional
{...rest} {...rest}
@@ -516,7 +516,7 @@ export const Button = React.forwardRef<View, ButtonProps>(
<Context.Provider value={context}> <Context.Provider value={context}>
{typeof children === 'function' ? children(context) : children} {typeof children === 'function' ? children(context) : children}
</Context.Provider> </Context.Provider>
</Component> </PressableComponent>
) )
}, },
) )
+3 -1
View File
@@ -16,6 +16,7 @@ import * as Toggle from '#/components/forms/Toggle'
import {Check_Stroke2_Corner0_Rounded as Check} from '#/components/icons/Check' import {Check_Stroke2_Corner0_Rounded as Check} from '#/components/icons/Check'
import {ChevronLeft_Stroke2_Corner0_Rounded as ChevronLeft} from '#/components/icons/Chevron' import {ChevronLeft_Stroke2_Corner0_Rounded as ChevronLeft} from '#/components/icons/Chevron'
import {Loader} from '#/components/Loader' import {Loader} from '#/components/Loader'
import {NormalizedRNGHPressable} from '#/components/NormalizedRNGHPressable'
import {Text} from '#/components/Typography' import {Text} from '#/components/Typography'
import {ReportDialogProps} from './types' import {ReportDialogProps} from './types'
@@ -153,7 +154,8 @@ export function SubmitView({
<Toggle.Item <Toggle.Item
key={labeler.creator.did} key={labeler.creator.did}
name={labeler.creator.did} name={labeler.creator.did}
label={title}> label={title}
PressableComponent={NormalizedRNGHPressable}>
<LabelerToggle title={title} /> <LabelerToggle title={title} />
</Toggle.Item> </Toggle.Item>
) )
+15 -7
View File
@@ -30,6 +30,7 @@ import {PageText_Stroke2_Corner0_Rounded as PageText} from '#/components/icons/P
import {PlusLarge_Stroke2_Corner0_Rounded as Plus} from '#/components/icons/Plus' import {PlusLarge_Stroke2_Corner0_Rounded as Plus} from '#/components/icons/Plus'
import {TimesLarge_Stroke2_Corner0_Rounded as X} from '#/components/icons/Times' import {TimesLarge_Stroke2_Corner0_Rounded as X} from '#/components/icons/Times'
import {Loader} from '#/components/Loader' import {Loader} from '#/components/Loader'
import {NormalizedRNGHPressable} from '#/components/NormalizedRNGHPressable'
import * as Prompt from '#/components/Prompt' import * as Prompt from '#/components/Prompt'
import {Text} from '#/components/Typography' import {Text} from '#/components/Typography'
@@ -168,7 +169,8 @@ function MutedWordsInner() {
<Toggle.Item <Toggle.Item
label={_(msg`Mute this word until you unmute it`)} label={_(msg`Mute this word until you unmute it`)}
name="forever" name="forever"
style={[a.flex_1]}> style={[a.flex_1]}
PressableComponent={NormalizedRNGHPressable}>
<TargetToggle> <TargetToggle>
<View <View
style={[a.flex_1, a.flex_row, a.align_center, a.gap_sm]}> style={[a.flex_1, a.flex_row, a.align_center, a.gap_sm]}>
@@ -183,7 +185,8 @@ function MutedWordsInner() {
<Toggle.Item <Toggle.Item
label={_(msg`Mute this word for 24 hours`)} label={_(msg`Mute this word for 24 hours`)}
name="24_hours" name="24_hours"
style={[a.flex_1]}> style={[a.flex_1]}
PressableComponent={NormalizedRNGHPressable}>
<TargetToggle> <TargetToggle>
<View <View
style={[a.flex_1, a.flex_row, a.align_center, a.gap_sm]}> style={[a.flex_1, a.flex_row, a.align_center, a.gap_sm]}>
@@ -207,7 +210,8 @@ function MutedWordsInner() {
<Toggle.Item <Toggle.Item
label={_(msg`Mute this word for 7 days`)} label={_(msg`Mute this word for 7 days`)}
name="7_days" name="7_days"
style={[a.flex_1]}> style={[a.flex_1]}
PressableComponent={NormalizedRNGHPressable}>
<TargetToggle> <TargetToggle>
<View <View
style={[a.flex_1, a.flex_row, a.align_center, a.gap_sm]}> style={[a.flex_1, a.flex_row, a.align_center, a.gap_sm]}>
@@ -222,7 +226,8 @@ function MutedWordsInner() {
<Toggle.Item <Toggle.Item
label={_(msg`Mute this word for 30 days`)} label={_(msg`Mute this word for 30 days`)}
name="30_days" name="30_days"
style={[a.flex_1]}> style={[a.flex_1]}
PressableComponent={NormalizedRNGHPressable}>
<TargetToggle> <TargetToggle>
<View <View
style={[a.flex_1, a.flex_row, a.align_center, a.gap_sm]}> style={[a.flex_1, a.flex_row, a.align_center, a.gap_sm]}>
@@ -256,7 +261,8 @@ function MutedWordsInner() {
<Toggle.Item <Toggle.Item
label={_(msg`Mute this word in post text and tags`)} label={_(msg`Mute this word in post text and tags`)}
name="content" name="content"
style={[a.flex_1]}> style={[a.flex_1]}
PressableComponent={NormalizedRNGHPressable}>
<TargetToggle> <TargetToggle>
<View <View
style={[a.flex_1, a.flex_row, a.align_center, a.gap_sm]}> style={[a.flex_1, a.flex_row, a.align_center, a.gap_sm]}>
@@ -272,7 +278,8 @@ function MutedWordsInner() {
<Toggle.Item <Toggle.Item
label={_(msg`Mute this word in tags only`)} label={_(msg`Mute this word in tags only`)}
name="tag" name="tag"
style={[a.flex_1]}> style={[a.flex_1]}
PressableComponent={NormalizedRNGHPressable}>
<TargetToggle> <TargetToggle>
<View <View
style={[a.flex_1, a.flex_row, a.align_center, a.gap_sm]}> style={[a.flex_1, a.flex_row, a.align_center, a.gap_sm]}>
@@ -302,7 +309,8 @@ function MutedWordsInner() {
name="exclude_following" name="exclude_following"
style={[a.flex_row, a.justify_between]} style={[a.flex_row, a.justify_between]}
value={excludeFollowing} value={excludeFollowing}
onChange={setExcludeFollowing}> onChange={setExcludeFollowing}
PressableComponent={NormalizedRNGHPressable}>
<TargetToggle> <TargetToggle>
<View style={[a.flex_1, a.flex_row, a.align_center, a.gap_sm]}> <View style={[a.flex_1, a.flex_row, a.align_center, a.gap_sm]}>
<Toggle.Checkbox /> <Toggle.Checkbox />
@@ -37,6 +37,7 @@ import * as Toggle from '#/components/forms/Toggle'
import {Check_Stroke2_Corner0_Rounded as Check} from '#/components/icons/Check' import {Check_Stroke2_Corner0_Rounded as Check} from '#/components/icons/Check'
import {CircleInfo_Stroke2_Corner0_Rounded as CircleInfo} from '#/components/icons/CircleInfo' import {CircleInfo_Stroke2_Corner0_Rounded as CircleInfo} from '#/components/icons/CircleInfo'
import {Loader} from '#/components/Loader' import {Loader} from '#/components/Loader'
import {NormalizedRNGHPressable} from '#/components/NormalizedRNGHPressable'
import {Text} from '#/components/Typography' import {Text} from '#/components/Typography'
export type PostInteractionSettingsFormProps = { export type PostInteractionSettingsFormProps = {
@@ -303,7 +304,8 @@ export function PostInteractionSettingsForm({
} }
value={quotesEnabled} value={quotesEnabled}
onChange={onChangeQuotesEnabled} onChange={onChangeQuotesEnabled}
style={[, a.justify_between, a.pt_xs]}> style={[a.justify_between, a.pt_xs]}
PressableComponent={NormalizedRNGHPressable}>
<Text style={[t.atoms.text_contrast_medium]}> <Text style={[t.atoms.text_contrast_medium]}>
{quotesEnabled ? ( {quotesEnabled ? (
<Trans>Quote posts enabled</Trans> <Trans>Quote posts enabled</Trans>
+6 -4
View File
@@ -1,9 +1,9 @@
import React from 'react' import React from 'react'
import {Pressable, View, ViewStyle} from 'react-native' import {Pressable, PressableProps, View, ViewStyle} from 'react-native'
import Animated, {LinearTransition} from 'react-native-reanimated' import Animated, {LinearTransition} from 'react-native-reanimated'
import {HITSLOP_10} from '#/lib/constants'
import {isNative} from '#/platform/detection' import {isNative} from '#/platform/detection'
import {HITSLOP_10} from 'lib/constants'
import { import {
atoms as a, atoms as a,
flatten, flatten,
@@ -68,6 +68,7 @@ export type ItemProps = ViewStyleProp & {
onChange?: (selected: boolean) => void onChange?: (selected: boolean) => void
isInvalid?: boolean isInvalid?: boolean
children: ((props: ItemState) => React.ReactNode) | React.ReactNode children: ((props: ItemState) => React.ReactNode) | React.ReactNode
PressableComponent?: React.ComponentType<PressableProps>
} }
export function useItemContext() { export function useItemContext() {
@@ -159,6 +160,7 @@ export function Item({
style, style,
type = 'checkbox', type = 'checkbox',
label, label,
PressableComponent = Pressable,
...rest ...rest
}: ItemProps) { }: ItemProps) {
const { const {
@@ -206,7 +208,7 @@ export function Item({
return ( return (
<ItemContext.Provider value={state}> <ItemContext.Provider value={state}>
<Pressable <PressableComponent
accessibilityHint={undefined} // optional accessibilityHint={undefined} // optional
hitSlop={HITSLOP_10} hitSlop={HITSLOP_10}
{...rest} {...rest}
@@ -231,7 +233,7 @@ export function Item({
onBlur={onBlur} onBlur={onBlur}
style={[a.flex_row, a.align_center, a.gap_sm, flatten(style)]}> style={[a.flex_row, a.align_center, a.gap_sm, flatten(style)]}>
{typeof children === 'function' ? children(state) : children} {typeof children === 'function' ? children(state) : children}
</Pressable> </PressableComponent>
</ItemContext.Provider> </ItemContext.Provider>
) )
} }
+7 -2
View File
@@ -12,6 +12,7 @@ import * as TextField from '#/components/forms/TextField'
import * as ToggleButton from '#/components/forms/ToggleButton' import * as ToggleButton from '#/components/forms/ToggleButton'
import {Globe_Stroke2_Corner0_Rounded as Globe} from '#/components/icons/Globe' import {Globe_Stroke2_Corner0_Rounded as Globe} from '#/components/icons/Globe'
import {InlineLinkText} from '#/components/Link' import {InlineLinkText} from '#/components/Link'
import {NormalizedRNGHPressable} from '#/components/NormalizedRNGHPressable'
import {P, Text} from '#/components/Typography' import {P, Text} from '#/components/Typography'
export function ServerInputDialog({ export function ServerInputDialog({
@@ -82,7 +83,10 @@ export function ServerInputDialog({
label="Preferences" label="Preferences"
values={fixedOption} values={fixedOption}
onChange={setFixedOption}> onChange={setFixedOption}>
<ToggleButton.Button name={BSKY_SERVICE} label={_(msg`Bluesky`)}> <ToggleButton.Button
name={BSKY_SERVICE}
label={_(msg`Bluesky`)}
PressableComponent={NormalizedRNGHPressable}>
<ToggleButton.ButtonText> <ToggleButton.ButtonText>
{_(msg`Bluesky`)} {_(msg`Bluesky`)}
</ToggleButton.ButtonText> </ToggleButton.ButtonText>
@@ -90,7 +94,8 @@ export function ServerInputDialog({
<ToggleButton.Button <ToggleButton.Button
testID="customSelectBtn" testID="customSelectBtn"
name="custom" name="custom"
label={_(msg`Custom`)}> label={_(msg`Custom`)}
PressableComponent={NormalizedRNGHPressable}>
<ToggleButton.ButtonText> <ToggleButton.ButtonText>
{_(msg`Custom`)} {_(msg`Custom`)}
</ToggleButton.ButtonText> </ToggleButton.ButtonText>
@@ -156,7 +156,6 @@ let RepostButton = ({
</View> </View>
<Button <Button
label={_(msg`Cancel quote post`)} label={_(msg`Cancel quote post`)}
onAccessibilityEscape={close}
onPress={close} onPress={close}
size="large" size="large"
variant="solid" variant="solid"