Skip to content

♿️ Fix semantics #291

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

Merged
merged 3 commits into from
Feb 2, 2025
Merged
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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ See the [Migration Guide](guides/migration_guide.md) for breaking changes betwee

## Unreleased

*None.*
### Fixes

- Fix semantics with the capture button.

## 4.3.6

Expand Down
8 changes: 5 additions & 3 deletions example/lib/widgets/method_list_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ class _MethodListViewState extends State<MethodListView> {
width: 48,
height: 48,
child: Center(
child: Text(
model.icon,
style: const TextStyle(fontSize: 28.0),
child: ExcludeSemantics(
child: Text(
model.icon,
style: const TextStyle(fontSize: 28.0),
),
),
),
),
Expand Down
64 changes: 38 additions & 26 deletions lib/src/states/camera_picker_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,13 @@ class CameraPickerState extends State<CameraPicker>
return pickerConfig.minimumRecordingDuration;
}

/// Whether the controller is recording a video.
bool get isRecordingVideo => innerController?.value.isRecordingVideo ?? false;

/// Whether the capture button is displaying.
bool get shouldCaptureButtonDisplay =>
isCaptureButtonTapDown &&
(innerController?.value.isRecordingVideo ?? false) &&
isRecordingRestricted;
(isCaptureButtonTapDown || MediaQuery.accessibleNavigationOf(context)) &&
isRecordingVideo;

/// Whether the camera preview should be rotated.
bool get isCameraRotated => pickerConfig.cameraQuarterTurns % 4 != 0;
Expand Down Expand Up @@ -236,6 +238,25 @@ class CameraPickerState extends State<CameraPicker>
/// The calculated capture actions section height.
double? lastCaptureActionsEffectiveHeight;

/// Determine the label for the shooting button.
String get textShootingButtonLabel {
final String label;
if (pickerConfig.enableRecording) {
if (pickerConfig.onlyEnableRecording) {
if (pickerConfig.enableTapRecording) {
label = textDelegate.shootingTapRecordingTips;
} else {
label = textDelegate.shootingOnlyRecordingTips;
}
} else {
label = textDelegate.shootingWithRecordingTips;
}
} else {
label = textDelegate.shootingTips;
}
return label;
}

@override
void initState() {
super.initState();
Expand Down Expand Up @@ -878,7 +899,7 @@ class CameraPickerState extends State<CameraPicker>
BoxConstraints constraints,
) {
lastShootingButtonPressedPosition ??= event.position;
if (innerController?.value.isRecordingVideo == true) {
if (isRecordingVideo) {
// First calculate relative offset.
final Offset offset = event.position - lastShootingButtonPressedPosition!;
// Then turn negative,
Expand Down Expand Up @@ -987,7 +1008,7 @@ class CameraPickerState extends State<CameraPicker>
/// 将被取消,并且状态会重置。
void recordDetectionCancel(PointerUpEvent event) {
recordDetectTimer?.cancel();
if (innerController?.value.isRecordingVideo == true) {
if (isRecordingVideo) {
stopRecordingVideo();
}
}
Expand Down Expand Up @@ -1164,7 +1185,7 @@ class CameraPickerState extends State<CameraPicker>
return null;
}
if (enableTapRecording) {
if (innerController?.value.isRecordingVideo ?? false) {
if (isRecordingVideo) {
return textDelegate.sActionStopRecordingHint;
}
return textDelegate.sActionRecordHint;
Expand Down Expand Up @@ -1297,28 +1318,14 @@ class CameraPickerState extends State<CameraPicker>
/// Text widget for shooting tips.
/// 拍摄的提示文字
Widget buildCaptureTips(CameraController? controller) {
final String tips;
if (pickerConfig.enableRecording) {
if (pickerConfig.onlyEnableRecording) {
if (pickerConfig.enableTapRecording) {
tips = textDelegate.shootingTapRecordingTips;
} else {
tips = textDelegate.shootingOnlyRecordingTips;
}
} else {
tips = textDelegate.shootingWithRecordingTips;
}
} else {
tips = textDelegate.shootingTips;
}
return AnimatedOpacity(
duration: recordDetectDuration,
opacity: controller?.value.isRecordingVideo ?? false ? 0 : 1,
child: Container(
height: 48.0,
alignment: Alignment.center,
child: Text(
tips,
textShootingButtonLabel,
style: const TextStyle(fontSize: 15),
textAlign: TextAlign.center,
),
Expand Down Expand Up @@ -1419,14 +1426,19 @@ class CameraPickerState extends State<CameraPicker>
/// The shooting button.
/// 拍照按钮
Widget buildCaptureButton(BuildContext context, BoxConstraints constraints) {
if (!isCaptureButtonTapDown &&
(innerController?.value.isRecordingVideo ?? false)) {
final showProgressIndicator =
isCaptureButtonTapDown || MediaQuery.accessibleNavigationOf(context);

if (!showProgressIndicator && isRecordingVideo) {
return const SizedBox.shrink();
}
const size = Size.square(82.0);
return MergeSemantics(
child: Semantics(
label: textDelegate.sActionShootingButtonTooltip,
label: isRecordingVideo
? textDelegate.sActionStopRecordingHint
: textShootingButtonLabel,
button: true,
onTap: onTap,
onTapHint: onTapHint,
onLongPress: onLongPress,
Expand Down Expand Up @@ -1478,10 +1490,10 @@ class CameraPickerState extends State<CameraPicker>
if (shouldCaptureButtonDisplay)
RotatedBox(
quarterTurns:
!enableScaledPreview ? cameraQuarterTurns : 0,
enableScaledPreview ? 0 : cameraQuarterTurns,
child: CameraProgressButton(
isAnimating:
isCaptureButtonTapDown && isShootingButtonAnimate,
showProgressIndicator && isShootingButtonAnimate,
duration: pickerConfig.maximumRecordingDuration!,
size: size,
ringsColor: theme.indicatorColor,
Expand Down
Loading