Skip to content

Commit 9fa4e14

Browse files
authored
♿️ Fix semantics (#291)
1 parent 205c282 commit 9fa4e14

File tree

3 files changed

+46
-30
lines changed

3 files changed

+46
-30
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ See the [Migration Guide](guides/migration_guide.md) for breaking changes betwee
88

99
## Unreleased
1010

11-
*None.*
11+
### Fixes
12+
13+
- Fix semantics with the capture button.
1214

1315
## 4.3.6
1416

example/lib/widgets/method_list_view.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ class _MethodListViewState extends State<MethodListView> {
4040
width: 48,
4141
height: 48,
4242
child: Center(
43-
child: Text(
44-
model.icon,
45-
style: const TextStyle(fontSize: 28.0),
43+
child: ExcludeSemantics(
44+
child: Text(
45+
model.icon,
46+
style: const TextStyle(fontSize: 28.0),
47+
),
4648
),
4749
),
4850
),

lib/src/states/camera_picker_state.dart

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,13 @@ class CameraPickerState extends State<CameraPicker>
198198
return pickerConfig.minimumRecordingDuration;
199199
}
200200

201+
/// Whether the controller is recording a video.
202+
bool get isRecordingVideo => innerController?.value.isRecordingVideo ?? false;
203+
201204
/// Whether the capture button is displaying.
202205
bool get shouldCaptureButtonDisplay =>
203-
isCaptureButtonTapDown &&
204-
(innerController?.value.isRecordingVideo ?? false) &&
205-
isRecordingRestricted;
206+
(isCaptureButtonTapDown || MediaQuery.accessibleNavigationOf(context)) &&
207+
isRecordingVideo;
206208

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

241+
/// Determine the label for the shooting button.
242+
String get textShootingButtonLabel {
243+
final String label;
244+
if (pickerConfig.enableRecording) {
245+
if (pickerConfig.onlyEnableRecording) {
246+
if (pickerConfig.enableTapRecording) {
247+
label = textDelegate.shootingTapRecordingTips;
248+
} else {
249+
label = textDelegate.shootingOnlyRecordingTips;
250+
}
251+
} else {
252+
label = textDelegate.shootingWithRecordingTips;
253+
}
254+
} else {
255+
label = textDelegate.shootingTips;
256+
}
257+
return label;
258+
}
259+
239260
@override
240261
void initState() {
241262
super.initState();
@@ -878,7 +899,7 @@ class CameraPickerState extends State<CameraPicker>
878899
BoxConstraints constraints,
879900
) {
880901
lastShootingButtonPressedPosition ??= event.position;
881-
if (innerController?.value.isRecordingVideo == true) {
902+
if (isRecordingVideo) {
882903
// First calculate relative offset.
883904
final Offset offset = event.position - lastShootingButtonPressedPosition!;
884905
// Then turn negative,
@@ -987,7 +1008,7 @@ class CameraPickerState extends State<CameraPicker>
9871008
/// 将被取消,并且状态会重置。
9881009
void recordDetectionCancel(PointerUpEvent event) {
9891010
recordDetectTimer?.cancel();
990-
if (innerController?.value.isRecordingVideo == true) {
1011+
if (isRecordingVideo) {
9911012
stopRecordingVideo();
9921013
}
9931014
}
@@ -1164,7 +1185,7 @@ class CameraPickerState extends State<CameraPicker>
11641185
return null;
11651186
}
11661187
if (enableTapRecording) {
1167-
if (innerController?.value.isRecordingVideo ?? false) {
1188+
if (isRecordingVideo) {
11681189
return textDelegate.sActionStopRecordingHint;
11691190
}
11701191
return textDelegate.sActionRecordHint;
@@ -1297,28 +1318,14 @@ class CameraPickerState extends State<CameraPicker>
12971318
/// Text widget for shooting tips.
12981319
/// 拍摄的提示文字
12991320
Widget buildCaptureTips(CameraController? controller) {
1300-
final String tips;
1301-
if (pickerConfig.enableRecording) {
1302-
if (pickerConfig.onlyEnableRecording) {
1303-
if (pickerConfig.enableTapRecording) {
1304-
tips = textDelegate.shootingTapRecordingTips;
1305-
} else {
1306-
tips = textDelegate.shootingOnlyRecordingTips;
1307-
}
1308-
} else {
1309-
tips = textDelegate.shootingWithRecordingTips;
1310-
}
1311-
} else {
1312-
tips = textDelegate.shootingTips;
1313-
}
13141321
return AnimatedOpacity(
13151322
duration: recordDetectDuration,
13161323
opacity: controller?.value.isRecordingVideo ?? false ? 0 : 1,
13171324
child: Container(
13181325
height: 48.0,
13191326
alignment: Alignment.center,
13201327
child: Text(
1321-
tips,
1328+
textShootingButtonLabel,
13221329
style: const TextStyle(fontSize: 15),
13231330
textAlign: TextAlign.center,
13241331
),
@@ -1419,14 +1426,19 @@ class CameraPickerState extends State<CameraPicker>
14191426
/// The shooting button.
14201427
/// 拍照按钮
14211428
Widget buildCaptureButton(BuildContext context, BoxConstraints constraints) {
1422-
if (!isCaptureButtonTapDown &&
1423-
(innerController?.value.isRecordingVideo ?? false)) {
1429+
final showProgressIndicator =
1430+
isCaptureButtonTapDown || MediaQuery.accessibleNavigationOf(context);
1431+
1432+
if (!showProgressIndicator && isRecordingVideo) {
14241433
return const SizedBox.shrink();
14251434
}
14261435
const size = Size.square(82.0);
14271436
return MergeSemantics(
14281437
child: Semantics(
1429-
label: textDelegate.sActionShootingButtonTooltip,
1438+
label: isRecordingVideo
1439+
? textDelegate.sActionStopRecordingHint
1440+
: textShootingButtonLabel,
1441+
button: true,
14301442
onTap: onTap,
14311443
onTapHint: onTapHint,
14321444
onLongPress: onLongPress,
@@ -1478,10 +1490,10 @@ class CameraPickerState extends State<CameraPicker>
14781490
if (shouldCaptureButtonDisplay)
14791491
RotatedBox(
14801492
quarterTurns:
1481-
!enableScaledPreview ? cameraQuarterTurns : 0,
1493+
enableScaledPreview ? 0 : cameraQuarterTurns,
14821494
child: CameraProgressButton(
14831495
isAnimating:
1484-
isCaptureButtonTapDown && isShootingButtonAnimate,
1496+
showProgressIndicator && isShootingButtonAnimate,
14851497
duration: pickerConfig.maximumRecordingDuration!,
14861498
size: size,
14871499
ringsColor: theme.indicatorColor,

0 commit comments

Comments
 (0)