diff --git a/packages/flutter/lib/src/rendering/platform_view.dart b/packages/flutter/lib/src/rendering/platform_view.dart index f596db5ff4..cf4568e646 100644 --- a/packages/flutter/lib/src/rendering/platform_view.dart +++ b/packages/flutter/lib/src/rendering/platform_view.dart @@ -311,8 +311,12 @@ class RenderUiKitView extends RenderBox { UiKitViewController _viewController; set viewController(UiKitViewController viewController) { assert(viewController != null); + final bool needsSemanticsUpdate = _viewController.id != viewController.id; _viewController = viewController; markNeedsPaint(); + if (needsSemanticsUpdate) { + markNeedsSemanticsUpdate(); + } } /// How to behave during hit testing. @@ -399,6 +403,13 @@ class RenderUiKitView extends RenderBox { _lastPointerDownEvent = null; } + @override + void describeSemanticsConfiguration (SemanticsConfiguration config) { + super.describeSemanticsConfiguration(config); + config.isSemanticBoundary = true; + config.platformViewId = _viewController.id; + } + @override void attach(PipelineOwner owner) { super.attach(owner); @@ -715,4 +726,3 @@ class _MotionEventsDispatcher { bool isSinglePointerAction(PointerEvent event) => !(event is PointerDownEvent) && !(event is PointerUpEvent); } - diff --git a/packages/flutter/test/widgets/platform_view_test.dart b/packages/flutter/test/widgets/platform_view_test.dart index 7c6fce6748..912bfa659a 100644 --- a/packages/flutter/test/widgets/platform_view_test.dart +++ b/packages/flutter/test/widgets/platform_view_test.dart @@ -1474,5 +1474,43 @@ void main() { 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(); + }); }); }