Skip to content

Commit

Permalink
Mobile: Accessibility: Improve dialog accessibility (#11395)
Browse files Browse the repository at this point in the history
  • Loading branch information
personalizedrefrigerator authored Nov 16, 2024
1 parent 6eac8d9 commit 84eab77
Show file tree
Hide file tree
Showing 26 changed files with 478 additions and 417 deletions.
7 changes: 5 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,6 @@ packages/app-mobile/commands/openNote.js
packages/app-mobile/commands/scrollToHash.js
packages/app-mobile/commands/util/goToNote.js
packages/app-mobile/commands/util/showResource.js
packages/app-mobile/components/BackButtonDialogBox.js
packages/app-mobile/components/BetaChip.js
packages/app-mobile/components/CameraView/ActionButtons.js
packages/app-mobile/components/CameraView/Camera/index.jest.js
Expand All @@ -588,7 +587,10 @@ packages/app-mobile/components/CameraView/types.js
packages/app-mobile/components/CameraView/utils/fitRectIntoBounds.js
packages/app-mobile/components/CameraView/utils/useBarcodeScanner.js
packages/app-mobile/components/Checkbox.js
packages/app-mobile/components/DialogManager.js
packages/app-mobile/components/DialogManager/PromptDialog.js
packages/app-mobile/components/DialogManager/hooks/useDialogControl.js
packages/app-mobile/components/DialogManager/index.js
packages/app-mobile/components/DialogManager/types.js
packages/app-mobile/components/DismissibleDialog.js
packages/app-mobile/components/Dropdown.test.js
packages/app-mobile/components/Dropdown.js
Expand Down Expand Up @@ -760,6 +762,7 @@ packages/app-mobile/components/screens/ShareManager/IncomingShareItem.js
packages/app-mobile/components/screens/ShareManager/index.test.js
packages/app-mobile/components/screens/ShareManager/index.js
packages/app-mobile/components/screens/UpgradeSyncTargetScreen.js
packages/app-mobile/components/screens/dropbox-login.js
packages/app-mobile/components/screens/encryption-config.js
packages/app-mobile/components/screens/status.js
packages/app-mobile/components/side-menu-content.js
Expand Down
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,6 @@ packages/app-mobile/commands/openNote.js
packages/app-mobile/commands/scrollToHash.js
packages/app-mobile/commands/util/goToNote.js
packages/app-mobile/commands/util/showResource.js
packages/app-mobile/components/BackButtonDialogBox.js
packages/app-mobile/components/BetaChip.js
packages/app-mobile/components/CameraView/ActionButtons.js
packages/app-mobile/components/CameraView/Camera/index.jest.js
Expand All @@ -565,7 +564,10 @@ packages/app-mobile/components/CameraView/types.js
packages/app-mobile/components/CameraView/utils/fitRectIntoBounds.js
packages/app-mobile/components/CameraView/utils/useBarcodeScanner.js
packages/app-mobile/components/Checkbox.js
packages/app-mobile/components/DialogManager.js
packages/app-mobile/components/DialogManager/PromptDialog.js
packages/app-mobile/components/DialogManager/hooks/useDialogControl.js
packages/app-mobile/components/DialogManager/index.js
packages/app-mobile/components/DialogManager/types.js
packages/app-mobile/components/DismissibleDialog.js
packages/app-mobile/components/Dropdown.test.js
packages/app-mobile/components/Dropdown.js
Expand Down Expand Up @@ -737,6 +739,7 @@ packages/app-mobile/components/screens/ShareManager/IncomingShareItem.js
packages/app-mobile/components/screens/ShareManager/index.test.js
packages/app-mobile/components/screens/ShareManager/index.js
packages/app-mobile/components/screens/UpgradeSyncTargetScreen.js
packages/app-mobile/components/screens/dropbox-login.js
packages/app-mobile/components/screens/encryption-config.js
packages/app-mobile/components/screens/status.js
packages/app-mobile/components/side-menu-content.js
Expand Down
2 changes: 1 addition & 1 deletion packages/app-mobile/commands/openItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const runtime = (): CommandRuntime => {
} else {
const errorMessage = _('Unsupported link or message: %s', link);
logger.error(errorMessage);
await shim.showMessageBox(errorMessage);
await shim.showErrorDialog(errorMessage);
}
},
};
Expand Down
25 changes: 0 additions & 25 deletions packages/app-mobile/components/BackButtonDialogBox.ts

This file was deleted.

150 changes: 0 additions & 150 deletions packages/app-mobile/components/DialogManager.tsx

This file was deleted.

93 changes: 93 additions & 0 deletions packages/app-mobile/components/DialogManager/PromptDialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import * as React from 'react';
import { Button, Dialog, Divider, Surface, Text } from 'react-native-paper';
import { DialogType, PromptDialogData } from './types';
import { StyleSheet } from 'react-native';
import { useMemo } from 'react';
import { themeStyle } from '../global-style';

interface Props {
dialog: PromptDialogData;
themeId: number;
}

const useStyles = (themeId: number, isMenu: boolean) => {
return useMemo(() => {
const theme = themeStyle(themeId);

return StyleSheet.create({
dialogContainer: {
backgroundColor: theme.backgroundColor,
borderRadius: 24,
paddingTop: 24,
marginLeft: 4,
marginRight: 4,
},

buttonScrollerContent: {
flexDirection: 'row',
justifyContent: 'flex-end',
flexWrap: 'wrap',
},

dialogContent: {
paddingBottom: 14,
},
dialogActions: {
paddingBottom: 14,
paddingTop: 4,

...(isMenu ? {
flexDirection: 'column',
alignItems: 'stretch',
} : {}),
},
dialogLabel: {
textAlign: isMenu ? 'center' : undefined,
},
});
}, [themeId, isMenu]);
};

const PromptDialog: React.FC<Props> = ({ dialog, themeId }) => {
const isMenu = dialog.type === DialogType.Menu;
const styles = useStyles(themeId, isMenu);

const buttons = dialog.buttons.map((button, index) => {
return (
<Button
key={`${index}-${button.text}`}
onPress={button.onPress}
>{button.text}</Button>
);
});
const titleComponent = <Text
variant='titleMedium'
accessibilityRole='header'
style={styles.dialogLabel}
>{dialog.title}</Text>;

return (
<Surface
testID={'prompt-dialog'}
style={styles.dialogContainer}
key={dialog.key}
elevation={1}
>
<Dialog.Content style={styles.dialogContent}>
{dialog.title ? titleComponent : null}
<Text
variant='bodyMedium'
style={styles.dialogLabel}
>{dialog.message}</Text>
</Dialog.Content>
{isMenu ? <Divider/> : null}
<Dialog.Actions
style={styles.dialogActions}
>
{buttons}
</Dialog.Actions>
</Surface>
);
};

export default PromptDialog;
Loading

0 comments on commit 84eab77

Please sign in to comment.