Unverified Commit 3b3f6c7a authored by Chris Yang's avatar Chris Yang Committed by GitHub

Include platformViewId in semantics tree for iOS (#29304)

Include the platformViewId of PlatformViews in the semantics tree. The accessibility bridge in the engine can use this id to steal the semantics nodes from the actual platform view and stick them into Flutter's semantics tree.

It is the iOS PlatformView counter part of https://github.com/flutter/flutter/pull/28953. It reverts the change in https://github.com/flutter/flutter/pull/28953/commits/5b5d6e89ec50f8f51766fb778d0e244f183a5000 and https://github.com/flutter/flutter/pull/28953/commits/03fd797eb8955561c2654b51035175202a25da9d.

https://github.com/flutter/flutter/issues/29302
parent 7d678f2a
...@@ -311,8 +311,12 @@ class RenderUiKitView extends RenderBox { ...@@ -311,8 +311,12 @@ class RenderUiKitView extends RenderBox {
UiKitViewController _viewController; UiKitViewController _viewController;
set viewController(UiKitViewController viewController) { set viewController(UiKitViewController viewController) {
assert(viewController != null); assert(viewController != null);
final bool needsSemanticsUpdate = _viewController.id != viewController.id;
_viewController = viewController; _viewController = viewController;
markNeedsPaint(); markNeedsPaint();
if (needsSemanticsUpdate) {
markNeedsSemanticsUpdate();
}
} }
/// How to behave during hit testing. /// How to behave during hit testing.
...@@ -399,6 +403,13 @@ class RenderUiKitView extends RenderBox { ...@@ -399,6 +403,13 @@ class RenderUiKitView extends RenderBox {
_lastPointerDownEvent = null; _lastPointerDownEvent = null;
} }
@override
void describeSemanticsConfiguration (SemanticsConfiguration config) {
super.describeSemanticsConfiguration(config);
config.isSemanticBoundary = true;
config.platformViewId = _viewController.id;
}
@override @override
void attach(PipelineOwner owner) { void attach(PipelineOwner owner) {
super.attach(owner); super.attach(owner);
...@@ -715,4 +726,3 @@ class _MotionEventsDispatcher { ...@@ -715,4 +726,3 @@ class _MotionEventsDispatcher {
bool isSinglePointerAction(PointerEvent event) => bool isSinglePointerAction(PointerEvent event) =>
!(event is PointerDownEvent) && !(event is PointerUpEvent); !(event is PointerDownEvent) && !(event is PointerUpEvent);
} }
...@@ -1474,5 +1474,43 @@ void main() { ...@@ -1474,5 +1474,43 @@ void main() {
expect(factoryInvocationCount, 1); expect(factoryInvocationCount, 1);
}); });
testWidgets('UiKitView has correct semantics', (WidgetTester tester) async {
final SemanticsHandle handle = tester.ensureSemantics();
final int currentViewId = platformViewsRegistry.getNextPlatformViewId();
expect(currentViewId, greaterThanOrEqualTo(0));
final FakeIosPlatformViewsController viewsController = FakeIosPlatformViewsController();
viewsController.registerViewType('webview');
await tester.pumpWidget(
Semantics(
container: true,
child: const Align(
alignment: Alignment.bottomRight,
child: SizedBox(
width: 200.0,
height: 100.0,
child: UiKitView(
viewType: 'webview',
layoutDirection: TextDirection.ltr,
),
),
),
),
);
// First frame is before the platform view was created so the render object
// is not yet in the tree.
await tester.pump();
final SemanticsNode semantics = tester.getSemantics(find.byType(UiKitView));
expect(semantics.platformViewId, currentViewId + 1);
expect(semantics.rect, Rect.fromLTWH(0, 0, 200, 100));
// A 200x100 rect positioned at bottom right of a 800x600 box.
expect(semantics.transform, Matrix4.translationValues(600, 500, 0));
expect(semantics.childrenCount, 0);
handle.dispose();
});
}); });
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment