Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
509ddfda
Unverified
Commit
509ddfda
authored
Mar 16, 2022
by
Emmanuel Garcia
Committed by
GitHub
Mar 16, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Always use texture layer when displaying an Android view (#100091)
parent
13bf7515
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
166 additions
and
255 deletions
+166
-255
platform_view.dart
packages/flutter/lib/src/rendering/platform_view.dart
+41
-43
platform_views.dart
packages/flutter/lib/src/services/platform_views.dart
+35
-97
platform_view.dart
packages/flutter/lib/src/widgets/platform_view.dart
+25
-26
platform_view_test.dart
packages/flutter/test/rendering/platform_view_test.dart
+32
-0
fake_platform_views.dart
packages/flutter/test/services/fake_platform_views.dart
+11
-20
platform_views_test.dart
packages/flutter/test/services/platform_views_test.dart
+22
-32
platform_view_test.dart
packages/flutter/test/widgets/platform_view_test.dart
+0
-37
No files found.
packages/flutter/lib/src/rendering/platform_view.dart
View file @
509ddfda
...
@@ -52,7 +52,7 @@ Set<Type> _factoriesTypeSet<T>(Set<Factory<T>> factories) {
...
@@ -52,7 +52,7 @@ Set<Type> _factoriesTypeSet<T>(Set<Factory<T>> factories) {
/// A render object for an Android view.
/// A render object for an Android view.
///
///
/// Requires Android API level 2
0
or greater.
/// Requires Android API level 2
3
or greater.
///
///
/// [RenderAndroidView] is responsible for sizing, displaying and passing touch events to an
/// [RenderAndroidView] is responsible for sizing, displaying and passing touch events to an
/// Android [View](https://developer.android.com/reference/android/view/View).
/// Android [View](https://developer.android.com/reference/android/view/View).
...
@@ -74,7 +74,7 @@ Set<Type> _factoriesTypeSet<T>(Set<Factory<T>> factories) {
...
@@ -74,7 +74,7 @@ Set<Type> _factoriesTypeSet<T>(Set<Factory<T>> factories) {
///
///
/// * [AndroidView] which is a widget that is used to show an Android view.
/// * [AndroidView] which is a widget that is used to show an Android view.
/// * [PlatformViewsService] which is a service for controlling platform views.
/// * [PlatformViewsService] which is a service for controlling platform views.
class
RenderAndroidView
extends
RenderBox
with
_PlatformViewGestureMixin
{
class
RenderAndroidView
extends
PlatformViewRenderBox
{
/// Creates a render object for an Android view.
/// Creates a render object for an Android view.
RenderAndroidView
({
RenderAndroidView
({
required
AndroidViewController
viewController
,
required
AndroidViewController
viewController
,
...
@@ -86,7 +86,8 @@ class RenderAndroidView extends RenderBox with _PlatformViewGestureMixin {
...
@@ -86,7 +86,8 @@ class RenderAndroidView extends RenderBox with _PlatformViewGestureMixin {
assert
(
gestureRecognizers
!=
null
),
assert
(
gestureRecognizers
!=
null
),
assert
(
clipBehavior
!=
null
),
assert
(
clipBehavior
!=
null
),
_viewController
=
viewController
,
_viewController
=
viewController
,
_clipBehavior
=
clipBehavior
{
_clipBehavior
=
clipBehavior
,
super
(
controller:
viewController
,
hitTestBehavior:
hitTestBehavior
,
gestureRecognizers:
gestureRecognizers
)
{
_viewController
.
pointTransformer
=
(
Offset
offset
)
=>
globalToLocal
(
offset
);
_viewController
.
pointTransformer
=
(
Offset
offset
)
=>
globalToLocal
(
offset
);
updateGestureRecognizers
(
gestureRecognizers
);
updateGestureRecognizers
(
gestureRecognizers
);
_viewController
.
addOnPlatformViewCreatedListener
(
_onPlatformViewCreated
);
_viewController
.
addOnPlatformViewCreatedListener
(
_onPlatformViewCreated
);
...
@@ -101,18 +102,22 @@ class RenderAndroidView extends RenderBox with _PlatformViewGestureMixin {
...
@@ -101,18 +102,22 @@ class RenderAndroidView extends RenderBox with _PlatformViewGestureMixin {
bool
_isDisposed
=
false
;
bool
_isDisposed
=
false
;
/// The Android view controller for the Android view associated with this render object.
/// The Android view controller for the Android view associated with this render object.
AndroidViewController
get
viewController
=>
_viewController
;
@override
AndroidViewController
get
controller
=>
_viewController
;
AndroidViewController
_viewController
;
AndroidViewController
_viewController
;
/// Sets a new Android view controller.
/// Sets a new Android view controller.
///
@override
/// `viewController` must not be null.
set
controller
(
AndroidViewController
controller
)
{
set
viewController
(
AndroidViewController
viewController
)
{
assert
(
_viewController
!=
null
);
assert
(
_viewController
!=
null
);
assert
(
viewC
ontroller
!=
null
);
assert
(
c
ontroller
!=
null
);
if
(
_viewController
==
viewC
ontroller
)
if
(
_viewController
==
c
ontroller
)
return
;
return
;
_viewController
.
removeOnPlatformViewCreatedListener
(
_onPlatformViewCreated
);
_viewController
.
removeOnPlatformViewCreatedListener
(
_onPlatformViewCreated
);
_viewController
=
viewController
;
super
.
controller
=
controller
;
_viewController
=
controller
;
_viewController
.
pointTransformer
=
(
Offset
offset
)
=>
globalToLocal
(
offset
);
_sizePlatformView
();
_sizePlatformView
();
if
(
_viewController
.
isCreated
)
{
if
(
_viewController
.
isCreated
)
{
markNeedsSemanticsUpdate
();
markNeedsSemanticsUpdate
();
...
@@ -138,26 +143,6 @@ class RenderAndroidView extends RenderBox with _PlatformViewGestureMixin {
...
@@ -138,26 +143,6 @@ class RenderAndroidView extends RenderBox with _PlatformViewGestureMixin {
markNeedsSemanticsUpdate
();
markNeedsSemanticsUpdate
();
}
}
/// {@template flutter.rendering.RenderAndroidView.updateGestureRecognizers}
/// Updates which gestures should be forwarded to the platform view.
///
/// Gesture recognizers created by factories in this set participate in the gesture arena for each
/// pointer that was put down on the render box. If any of the recognizers on this list wins the
/// gesture arena, the entire pointer event sequence starting from the pointer down event
/// will be dispatched to the Android view.
///
/// The `gestureRecognizers` property must not contain more than one factory with the same [Factory.type].
///
/// Setting a new set of gesture recognizer factories with the same [Factory.type]s as the current
/// set has no effect, because the factories' constructors would have already been called with the previous set.
/// {@endtemplate}
///
/// Any active gesture arena the Android view participates in is rejected when the
/// set of gesture recognizers is changed.
void
updateGestureRecognizers
(
Set
<
Factory
<
OneSequenceGestureRecognizer
>>
gestureRecognizers
)
{
_updateGestureRecognizersWithCallBack
(
gestureRecognizers
,
_viewController
.
dispatchPointerEvent
);
}
@override
@override
bool
get
sizedByParent
=>
true
;
bool
get
sizedByParent
=>
true
;
...
@@ -182,9 +167,8 @@ class RenderAndroidView extends RenderBox with _PlatformViewGestureMixin {
...
@@ -182,9 +167,8 @@ class RenderAndroidView extends RenderBox with _PlatformViewGestureMixin {
// Android virtual displays cannot have a zero size.
// Android virtual displays cannot have a zero size.
// Trying to size it to 0 crashes the app, which was happening when starting the app
// Trying to size it to 0 crashes the app, which was happening when starting the app
// with a locked screen (see: https://github.com/flutter/flutter/issues/20456).
// with a locked screen (see: https://github.com/flutter/flutter/issues/20456).
if
(
_state
==
_PlatformViewState
.
resizing
||
size
.
isEmpty
)
{
if
(
_state
==
_PlatformViewState
.
resizing
||
size
.
isEmpty
)
return
;
return
;
}
_state
=
_PlatformViewState
.
resizing
;
_state
=
_PlatformViewState
.
resizing
;
markNeedsPaint
();
markNeedsPaint
();
...
@@ -212,7 +196,8 @@ class RenderAndroidView extends RenderBox with _PlatformViewGestureMixin {
...
@@ -212,7 +196,8 @@ class RenderAndroidView extends RenderBox with _PlatformViewGestureMixin {
void
_setOffset
()
{
void
_setOffset
()
{
SchedulerBinding
.
instance
.
addPostFrameCallback
((
_
)
async
{
SchedulerBinding
.
instance
.
addPostFrameCallback
((
_
)
async
{
if
(!
_isDisposed
)
{
if
(!
_isDisposed
)
{
await
_viewController
.
setOffset
(
localToGlobal
(
Offset
.
zero
));
if
(
attached
)
await
_viewController
.
setOffset
(
localToGlobal
(
Offset
.
zero
));
// Schedule a new post frame callback.
// Schedule a new post frame callback.
_setOffset
();
_setOffset
();
}
}
...
@@ -221,7 +206,7 @@ class RenderAndroidView extends RenderBox with _PlatformViewGestureMixin {
...
@@ -221,7 +206,7 @@ class RenderAndroidView extends RenderBox with _PlatformViewGestureMixin {
@override
@override
void
paint
(
PaintingContext
context
,
Offset
offset
)
{
void
paint
(
PaintingContext
context
,
Offset
offset
)
{
if
(
_viewController
.
textureId
==
null
)
if
(
_viewController
.
textureId
==
null
||
_currentTextureSize
==
null
)
return
;
return
;
// As resizing the Android view happens asynchronously we don't know exactly when is a
// As resizing the Android view happens asynchronously we don't know exactly when is a
...
@@ -264,14 +249,15 @@ class RenderAndroidView extends RenderBox with _PlatformViewGestureMixin {
...
@@ -264,14 +249,15 @@ class RenderAndroidView extends RenderBox with _PlatformViewGestureMixin {
context
.
addLayer
(
TextureLayer
(
context
.
addLayer
(
TextureLayer
(
rect:
offset
&
_currentTextureSize
!,
rect:
offset
&
_currentTextureSize
!,
textureId:
viewController
.
textureId
!,
textureId:
_
viewController
.
textureId
!,
));
));
}
}
@override
@override
void
describeSemanticsConfiguration
(
SemanticsConfiguration
config
)
{
void
describeSemanticsConfiguration
(
SemanticsConfiguration
config
)
{
super
.
describeSemanticsConfiguration
(
config
);
// Don't call the super implementation since `platformViewId` should
// be set only when the platform view is created, but the concept of
// a "created" platform view belongs to this subclass.
config
.
isSemanticBoundary
=
true
;
config
.
isSemanticBoundary
=
true
;
if
(
_viewController
.
isCreated
)
{
if
(
_viewController
.
isCreated
)
{
...
@@ -339,7 +325,7 @@ class RenderUiKitView extends RenderBox {
...
@@ -339,7 +325,7 @@ class RenderUiKitView extends RenderBox {
// any newly arriving events there's nothing we need to invalidate.
// any newly arriving events there's nothing we need to invalidate.
PlatformViewHitTestBehavior
hitTestBehavior
;
PlatformViewHitTestBehavior
hitTestBehavior
;
/// {@macro flutter.rendering.
RenderAndroidView
.updateGestureRecognizers}
/// {@macro flutter.rendering.
PlatformViewRenderBox
.updateGestureRecognizers}
void
updateGestureRecognizers
(
Set
<
Factory
<
OneSequenceGestureRecognizer
>>
gestureRecognizers
)
{
void
updateGestureRecognizers
(
Set
<
Factory
<
OneSequenceGestureRecognizer
>>
gestureRecognizers
)
{
assert
(
gestureRecognizers
!=
null
);
assert
(
gestureRecognizers
!=
null
);
assert
(
assert
(
...
@@ -653,11 +639,11 @@ class PlatformViewRenderBox extends RenderBox with _PlatformViewGestureMixin {
...
@@ -653,11 +639,11 @@ class PlatformViewRenderBox extends RenderBox with _PlatformViewGestureMixin {
PlatformViewController
get
controller
=>
_controller
;
PlatformViewController
get
controller
=>
_controller
;
PlatformViewController
_controller
;
PlatformViewController
_controller
;
/// This value must not be null, and setting it to a new value will result in a repaint.
/// This value must not be null, and setting it to a new value will result in a repaint.
set
controller
(
PlatformViewController
controller
)
{
set
controller
(
covariant
PlatformViewController
controller
)
{
assert
(
controller
!=
null
);
assert
(
controller
!=
null
);
assert
(
controller
.
viewId
!=
null
&&
controller
.
viewId
>
-
1
);
assert
(
controller
.
viewId
!=
null
&&
controller
.
viewId
>
-
1
);
if
(
_controller
==
controller
)
{
if
(
_controller
==
controller
)
{
return
;
return
;
}
}
final
bool
needsSemanticsUpdate
=
_controller
.
viewId
!=
controller
.
viewId
;
final
bool
needsSemanticsUpdate
=
_controller
.
viewId
!=
controller
.
viewId
;
...
@@ -668,7 +654,19 @@ class PlatformViewRenderBox extends RenderBox with _PlatformViewGestureMixin {
...
@@ -668,7 +654,19 @@ class PlatformViewRenderBox extends RenderBox with _PlatformViewGestureMixin {
}
}
}
}
/// {@macro flutter.rendering.RenderAndroidView.updateGestureRecognizers}
/// {@template flutter.rendering.PlatformViewRenderBox.updateGestureRecognizers}
/// Updates which gestures should be forwarded to the platform view.
///
/// Gesture recognizers created by factories in this set participate in the gesture arena for each
/// pointer that was put down on the render box. If any of the recognizers on this list wins the
/// gesture arena, the entire pointer event sequence starting from the pointer down event
/// will be dispatched to the Android view.
///
/// The `gestureRecognizers` property must not contain more than one factory with the same [Factory.type].
///
/// Setting a new set of gesture recognizer factories with the same [Factory.type]s as the current
/// set has no effect, because the factories' constructors would have already been called with the previous set.
/// {@endtemplate}
///
///
/// Any active gesture arena the `PlatformView` participates in is rejected when the
/// Any active gesture arena the `PlatformView` participates in is rejected when the
/// set of gesture recognizers is changed.
/// set of gesture recognizers is changed.
...
@@ -700,7 +698,7 @@ class PlatformViewRenderBox extends RenderBox with _PlatformViewGestureMixin {
...
@@ -700,7 +698,7 @@ class PlatformViewRenderBox extends RenderBox with _PlatformViewGestureMixin {
}
}
@override
@override
void
describeSemanticsConfiguration
(
SemanticsConfiguration
config
)
{
void
describeSemanticsConfiguration
(
SemanticsConfiguration
config
)
{
super
.
describeSemanticsConfiguration
(
config
);
super
.
describeSemanticsConfiguration
(
config
);
assert
(
_controller
.
viewId
!=
null
);
assert
(
_controller
.
viewId
!=
null
);
config
.
isSemanticBoundary
=
true
;
config
.
isSemanticBoundary
=
true
;
...
...
packages/flutter/lib/src/services/platform_views.dart
View file @
509ddfda
This diff is collapsed.
Click to expand it.
packages/flutter/lib/src/widgets/platform_view.dart
View file @
509ddfda
...
@@ -15,7 +15,7 @@ import 'framework.dart';
...
@@ -15,7 +15,7 @@ import 'framework.dart';
/// Embeds an Android view in the Widget hierarchy.
/// Embeds an Android view in the Widget hierarchy.
///
///
/// Requires Android API level 2
0
or greater.
/// Requires Android API level 2
3
or greater.
///
///
/// Embedding Android views is an expensive operation and should be avoided when a Flutter
/// Embedding Android views is an expensive operation and should be avoided when a Flutter
/// equivalent is possible.
/// equivalent is possible.
...
@@ -681,7 +681,7 @@ class _AndroidPlatformView extends LeafRenderObjectWidget {
...
@@ -681,7 +681,7 @@ class _AndroidPlatformView extends LeafRenderObjectWidget {
@override
@override
void
updateRenderObject
(
BuildContext
context
,
RenderAndroidView
renderObject
)
{
void
updateRenderObject
(
BuildContext
context
,
RenderAndroidView
renderObject
)
{
renderObject
.
viewC
ontroller
=
controller
;
renderObject
.
c
ontroller
=
controller
;
renderObject
.
hitTestBehavior
=
hitTestBehavior
;
renderObject
.
hitTestBehavior
=
hitTestBehavior
;
renderObject
.
updateGestureRecognizers
(
gestureRecognizers
);
renderObject
.
updateGestureRecognizers
(
gestureRecognizers
);
renderObject
.
clipBehavior
=
clipBehavior
;
renderObject
.
clipBehavior
=
clipBehavior
;
...
@@ -842,15 +842,11 @@ class PlatformViewLink extends StatefulWidget {
...
@@ -842,15 +842,11 @@ class PlatformViewLink extends StatefulWidget {
class
_PlatformViewLinkState
extends
State
<
PlatformViewLink
>
{
class
_PlatformViewLinkState
extends
State
<
PlatformViewLink
>
{
int
?
_id
;
int
?
_id
;
PlatformViewController
?
_controller
;
PlatformViewController
?
_controller
;
bool
_platformViewCreated
=
false
;
Widget
?
_surface
;
Widget
?
_surface
;
FocusNode
?
_focusNode
;
FocusNode
?
_focusNode
;
@override
@override
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
if
(!
_platformViewCreated
)
{
return
const
SizedBox
.
expand
();
}
_surface
??=
widget
.
_surfaceFactory
(
context
,
_controller
!);
_surface
??=
widget
.
_surfaceFactory
(
context
,
_controller
!);
return
Focus
(
return
Focus
(
focusNode:
_focusNode
,
focusNode:
_focusNode
,
...
@@ -875,9 +871,6 @@ class _PlatformViewLinkState extends State<PlatformViewLink> {
...
@@ -875,9 +871,6 @@ class _PlatformViewLinkState extends State<PlatformViewLink> {
// The _surface has to be recreated as its controller is disposed.
// The _surface has to be recreated as its controller is disposed.
// Setting _surface to null will trigger its creation in build().
// Setting _surface to null will trigger its creation in build().
_surface
=
null
;
_surface
=
null
;
// We are about to create a new platform view.
_platformViewCreated
=
false
;
_initialize
();
_initialize
();
}
}
}
}
...
@@ -888,16 +881,12 @@ class _PlatformViewLinkState extends State<PlatformViewLink> {
...
@@ -888,16 +881,12 @@ class _PlatformViewLinkState extends State<PlatformViewLink> {
PlatformViewCreationParams
.
_
(
PlatformViewCreationParams
.
_
(
id:
_id
!,
id:
_id
!,
viewType:
widget
.
viewType
,
viewType:
widget
.
viewType
,
onPlatformViewCreated:
_onPlatformViewCreated
,
onPlatformViewCreated:
(
_
)
{}
,
onFocusChanged:
_handlePlatformFocusChanged
,
onFocusChanged:
_handlePlatformFocusChanged
,
),
),
);
);
}
}
void
_onPlatformViewCreated
(
int
id
)
{
setState
(()
{
_platformViewCreated
=
true
;
});
}
void
_handleFrameworkFocusChanged
(
bool
isFocused
)
{
void
_handleFrameworkFocusChanged
(
bool
isFocused
)
{
if
(!
isFocused
)
{
if
(!
isFocused
)
{
_controller
?.
clearFocus
();
_controller
?.
clearFocus
();
...
@@ -1020,18 +1009,18 @@ class PlatformViewSurface extends LeafRenderObjectWidget {
...
@@ -1020,18 +1009,18 @@ class PlatformViewSurface extends LeafRenderObjectWidget {
/// Integrates an Android view with Flutter's compositor, touch, and semantics subsystems.
/// Integrates an Android view with Flutter's compositor, touch, and semantics subsystems.
///
///
/// The compositor integration is done by adding a [PlatformViewLayer] to the layer tree. [PlatformViewLayer]
/// The compositor integration is done by adding a [TextureLayer] to the layer tree.
/// isn't supported on all platforms. Custom Flutter embedders can support
/// [PlatformViewLayer]s by implementing a SystemCompositor.
///
///
/// The widget fills all available space, the parent of this object must provide bounded layout
/// The parent of this object must provide bounded layout constraints.
/// constraints.
///
///
/// If the associated platform view is not created, the [AndroidViewSurface] does not paint any contents.
/// If the associated platform view is not created, the [AndroidViewSurface] does not paint any contents.
///
///
/// When possible, you may want to use [AndroidView] directly, since it requires less boilerplate code
/// than [AndroidViewSurface], and there's no difference in performance, or other trade-off(s).
///
/// See also:
/// See also:
///
///
/// * [AndroidView] which embeds an Android platform view in the widget hierarchy
using a [TextureLayer]
.
/// * [AndroidView] which embeds an Android platform view in the widget hierarchy.
/// * [UiKitView] which embeds an iOS platform view in the widget hierarchy.
/// * [UiKitView] which embeds an iOS platform view in the widget hierarchy.
class
AndroidViewSurface
extends
PlatformViewSurface
{
class
AndroidViewSurface
extends
PlatformViewSurface
{
/// Construct an `AndroidPlatformViewSurface`.
/// Construct an `AndroidPlatformViewSurface`.
...
@@ -1052,12 +1041,22 @@ class AndroidViewSurface extends PlatformViewSurface {
...
@@ -1052,12 +1041,22 @@ class AndroidViewSurface extends PlatformViewSurface {
@override
@override
RenderObject
createRenderObject
(
BuildContext
context
)
{
RenderObject
createRenderObject
(
BuildContext
context
)
{
final
PlatformViewRenderBox
renderBox
=
final
AndroidViewController
viewController
=
controller
as
AndroidViewController
;
super
.
createRenderObject
(
context
)
as
PlatformViewRenderBox
;
final
RenderAndroidView
renderObject
=
RenderAndroidView
(
viewController:
viewController
,
(
controller
as
AndroidViewController
).
pointTransformer
=
gestureRecognizers:
gestureRecognizers
,
(
Offset
position
)
=>
renderBox
.
globalToLocal
(
position
);
hitTestBehavior:
hitTestBehavior
,
);
viewController
.
pointTransformer
=
(
Offset
position
)
=>
renderObject
.
globalToLocal
(
position
);
return
renderObject
;
}
return
renderBox
;
@override
void
updateRenderObject
(
BuildContext
context
,
RenderAndroidView
renderObject
)
{
renderObject
..
controller
=
controller
as
AndroidViewController
..
hitTestBehavior
=
hitTestBehavior
..
updateGestureRecognizers
(
gestureRecognizers
);
}
}
}
}
packages/flutter/test/rendering/platform_view_test.dart
View file @
509ddfda
...
@@ -151,6 +151,38 @@ void main() {
...
@@ -151,6 +151,38 @@ void main() {
// Passes if no crashes.
// Passes if no crashes.
});
});
test
(
'created callback is reset when controller is changed'
,
()
{
final
FakeAndroidPlatformViewsController
viewsController
=
FakeAndroidPlatformViewsController
();
viewsController
.
registerViewType
(
'webview'
);
final
AndroidViewController
firstController
=
PlatformViewsService
.
initAndroidView
(
id:
0
,
viewType:
'webview'
,
layoutDirection:
TextDirection
.
rtl
,
);
final
RenderAndroidView
renderBox
=
RenderAndroidView
(
viewController:
firstController
,
hitTestBehavior:
PlatformViewHitTestBehavior
.
opaque
,
gestureRecognizers:
<
Factory
<
OneSequenceGestureRecognizer
>>{},
);
layout
(
renderBox
);
pumpFrame
(
phase:
EnginePhase
.
flushSemantics
);
expect
(
firstController
.
createdCallbacks
,
isNotEmpty
);
expect
(
firstController
.
createdCallbacks
.
length
,
1
);
final
AndroidViewController
secondController
=
PlatformViewsService
.
initAndroidView
(
id:
0
,
viewType:
'webview'
,
layoutDirection:
TextDirection
.
rtl
,
);
// Reset controller.
renderBox
.
controller
=
secondController
;
expect
(
firstController
.
createdCallbacks
,
isEmpty
);
expect
(
secondController
.
createdCallbacks
,
isNotEmpty
);
expect
(
secondController
.
createdCallbacks
.
length
,
1
);
});
test
(
'render object changed its visual appearance after texture is created'
,
()
{
test
(
'render object changed its visual appearance after texture is created'
,
()
{
FakeAsync
().
run
((
FakeAsync
async
)
{
FakeAsync
().
run
((
FakeAsync
async
)
{
final
AndroidViewController
viewController
=
final
AndroidViewController
viewController
=
...
...
packages/flutter/test/services/fake_platform_views.dart
View file @
509ddfda
...
@@ -84,23 +84,22 @@ class FakeAndroidViewController implements AndroidViewController {
...
@@ -84,23 +84,22 @@ class FakeAndroidViewController implements AndroidViewController {
@override
@override
Future
<
Size
>
setSize
(
Size
size
)
{
Future
<
Size
>
setSize
(
Size
size
)
{
throw
UnimplementedError
(
);
return
Future
<
Size
>.
value
(
size
);
}
}
@override
@override
Future
<
void
>
setOffset
(
Offset
off
)
{
Future
<
void
>
setOffset
(
Offset
off
)
async
{}
throw
UnimplementedError
();
}
@override
@override
int
get
textureId
=>
throw
UnimplementedError
()
;
int
get
textureId
=>
0
;
@override
@override
bool
get
isCreated
=>
throw
UnimplementedError
()
;
bool
get
isCreated
=>
created
;
@override
@override
void
addOnPlatformViewCreatedListener
(
PlatformViewCreatedCallback
listener
)
=>
void
addOnPlatformViewCreatedListener
(
PlatformViewCreatedCallback
listener
)
{
throw
UnimplementedError
();
created
=
true
;
}
@override
@override
void
removeOnPlatformViewCreatedListener
(
PlatformViewCreatedCallback
listener
)
{
void
removeOnPlatformViewCreatedListener
(
PlatformViewCreatedCallback
listener
)
{
...
@@ -118,9 +117,10 @@ class FakeAndroidViewController implements AndroidViewController {
...
@@ -118,9 +117,10 @@ class FakeAndroidViewController implements AndroidViewController {
}
}
@override
@override
Future
<
void
>
create
()
async
{
Future
<
void
>
create
()
async
{}
created
=
true
;
}
@override
List
<
PlatformViewCreatedCallback
>
get
createdCallbacks
=>
<
PlatformViewCreatedCallback
>[];
}
}
class
FakeAndroidPlatformViewsController
{
class
FakeAndroidPlatformViewsController
{
...
@@ -143,8 +143,6 @@ class FakeAndroidPlatformViewsController {
...
@@ -143,8 +143,6 @@ class FakeAndroidPlatformViewsController {
int
?
lastClearedFocusViewId
;
int
?
lastClearedFocusViewId
;
bool
synchronizeToNativeViewHierarchy
=
true
;
Map
<
int
,
Offset
>
offsets
=
<
int
,
Offset
>{};
Map
<
int
,
Offset
>
offsets
=
<
int
,
Offset
>{};
void
registerViewType
(
String
viewType
)
{
void
registerViewType
(
String
viewType
)
{
...
@@ -174,8 +172,6 @@ class FakeAndroidPlatformViewsController {
...
@@ -174,8 +172,6 @@ class FakeAndroidPlatformViewsController {
return
_clearFocus
(
call
);
return
_clearFocus
(
call
);
case
'offset'
:
case
'offset'
:
return
_offset
(
call
);
return
_offset
(
call
);
case
'synchronizeToNativeViewHierarchy'
:
return
_synchronizeToNativeViewHierarchy
(
call
);
}
}
return
Future
<
dynamic
>.
sync
(()
=>
null
);
return
Future
<
dynamic
>.
sync
(()
=>
null
);
}
}
...
@@ -318,11 +314,6 @@ class FakeAndroidPlatformViewsController {
...
@@ -318,11 +314,6 @@ class FakeAndroidPlatformViewsController {
lastClearedFocusViewId
=
id
;
lastClearedFocusViewId
=
id
;
return
Future
<
dynamic
>.
sync
(()
=>
null
);
return
Future
<
dynamic
>.
sync
(()
=>
null
);
}
}
Future
<
dynamic
>
_synchronizeToNativeViewHierarchy
(
MethodCall
call
)
{
synchronizeToNativeViewHierarchy
=
call
.
arguments
as
bool
;
return
Future
<
dynamic
>.
sync
(()
=>
null
);
}
}
}
class
FakeIosPlatformViewsController
{
class
FakeIosPlatformViewsController
{
...
...
packages/flutter/test/services/platform_views_test.dart
View file @
509ddfda
...
@@ -18,7 +18,7 @@ void main() {
...
@@ -18,7 +18,7 @@ void main() {
});
});
test
(
'create Android view of unregistered type'
,
()
async
{
test
(
'create Android view of unregistered type'
,
()
async
{
expect
(
expect
Later
(
()
{
()
{
return
PlatformViewsService
.
initAndroidView
(
return
PlatformViewsService
.
initAndroidView
(
id:
0
,
id:
0
,
...
@@ -29,16 +29,25 @@ void main() {
...
@@ -29,16 +29,25 @@ void main() {
throwsA
(
isA
<
PlatformException
>()),
throwsA
(
isA
<
PlatformException
>()),
);
);
expect
(
try
{
()
{
await
PlatformViewsService
.
initSurfaceAndroidView
(
return
PlatformViewsService
.
initSurfaceAndroidView
(
id:
0
,
id:
0
,
viewType:
'web'
,
viewType:
'web'
,
layoutDirection:
TextDirection
.
ltr
,
layoutDirection:
TextDirection
.
ltr
,
).
create
();
).
create
();
}
catch
(
e
)
{
},
expect
(
false
,
isTrue
,
reason:
'did not expected any exception, but instead got `
$e
`'
);
throwsA
(
isA
<
PlatformException
>()),
}
);
try
{
await
PlatformViewsService
.
initAndroidView
(
id:
0
,
viewType:
'web'
,
layoutDirection:
TextDirection
.
ltr
,
).
create
();
}
catch
(
e
)
{
expect
(
false
,
isTrue
,
reason:
'did not expected any exception, but instead got `
$e
`'
);
}
});
});
test
(
'create Android views'
,
()
async
{
test
(
'create Android views'
,
()
async
{
...
@@ -47,13 +56,13 @@ void main() {
...
@@ -47,13 +56,13 @@ void main() {
.
setSize
(
const
Size
(
100.0
,
100.0
));
.
setSize
(
const
Size
(
100.0
,
100.0
));
await
PlatformViewsService
.
initAndroidView
(
id:
1
,
viewType:
'webview'
,
layoutDirection:
TextDirection
.
rtl
)
await
PlatformViewsService
.
initAndroidView
(
id:
1
,
viewType:
'webview'
,
layoutDirection:
TextDirection
.
rtl
)
.
setSize
(
const
Size
(
200.0
,
300.0
));
.
setSize
(
const
Size
(
200.0
,
300.0
));
// This platform view isn't created until the size is set.
await
PlatformViewsService
.
initSurfaceAndroidView
(
id:
2
,
viewType:
'webview'
,
layoutDirection:
TextDirection
.
rtl
).
create
();
await
PlatformViewsService
.
initSurfaceAndroidView
(
id:
2
,
viewType:
'webview'
,
layoutDirection:
TextDirection
.
rtl
).
create
();
expect
(
expect
(
viewsController
.
views
,
viewsController
.
views
,
unorderedEquals
(<
FakeAndroidPlatformView
>[
unorderedEquals
(<
FakeAndroidPlatformView
>[
const
FakeAndroidPlatformView
(
0
,
'webview'
,
Size
(
100.0
,
100.0
),
AndroidViewController
.
kAndroidLayoutDirectionLtr
,
null
),
const
FakeAndroidPlatformView
(
0
,
'webview'
,
Size
(
100.0
,
100.0
),
AndroidViewController
.
kAndroidLayoutDirectionLtr
,
null
),
const
FakeAndroidPlatformView
(
1
,
'webview'
,
Size
(
200.0
,
300.0
),
AndroidViewController
.
kAndroidLayoutDirectionRtl
,
null
),
const
FakeAndroidPlatformView
(
1
,
'webview'
,
Size
(
200.0
,
300.0
),
AndroidViewController
.
kAndroidLayoutDirectionRtl
,
null
),
const
FakeAndroidPlatformView
(
2
,
'webview'
,
null
,
AndroidViewController
.
kAndroidLayoutDirectionRtl
,
true
),
]),
]),
);
);
});
});
...
@@ -65,7 +74,7 @@ void main() {
...
@@ -65,7 +74,7 @@ void main() {
viewType:
'webview'
,
viewType:
'webview'
,
layoutDirection:
TextDirection
.
ltr
,
layoutDirection:
TextDirection
.
ltr
,
).
setSize
(
const
Size
(
100.0
,
100.0
));
).
setSize
(
const
Size
(
100.0
,
100.0
));
expect
(
expect
Later
(
()
=>
PlatformViewsService
.
initAndroidView
(
()
=>
PlatformViewsService
.
initAndroidView
(
id:
0
,
id:
0
,
viewType:
'web'
,
viewType:
'web'
,
...
@@ -73,20 +82,6 @@ void main() {
...
@@ -73,20 +82,6 @@ void main() {
).
setSize
(
const
Size
(
100.0
,
100.0
)),
).
setSize
(
const
Size
(
100.0
,
100.0
)),
throwsA
(
isA
<
PlatformException
>()),
throwsA
(
isA
<
PlatformException
>()),
);
);
await
PlatformViewsService
.
initSurfaceAndroidView
(
id:
1
,
viewType:
'webview'
,
layoutDirection:
TextDirection
.
ltr
,
).
create
();
expect
(
()
=>
PlatformViewsService
.
initSurfaceAndroidView
(
id:
1
,
viewType:
'web'
,
layoutDirection:
TextDirection
.
ltr
,
).
create
(),
throwsA
(
isA
<
PlatformException
>()),
);
});
});
test
(
'dispose Android view'
,
()
async
{
test
(
'dispose Android view'
,
()
async
{
...
@@ -240,11 +235,6 @@ void main() {
...
@@ -240,11 +235,6 @@ void main() {
await
viewController
.
setOffset
(
const
Offset
(
10
,
20
));
await
viewController
.
setOffset
(
const
Offset
(
10
,
20
));
expect
(
viewsController
.
offsets
,
equals
(<
int
,
Offset
>{}));
expect
(
viewsController
.
offsets
,
equals
(<
int
,
Offset
>{}));
});
});
test
(
'synchronizeToNativeViewHierarchy'
,
()
async
{
await
PlatformViewsService
.
synchronizeToNativeViewHierarchy
(
false
);
expect
(
viewsController
.
synchronizeToNativeViewHierarchy
,
false
);
});
});
});
group
(
'iOS'
,
()
{
group
(
'iOS'
,
()
{
...
...
packages/flutter/test/widgets/platform_view_test.dart
View file @
509ddfda
...
@@ -2312,43 +2312,6 @@ void main() {
...
@@ -2312,43 +2312,6 @@ void main() {
expect
(
factoryInvocationCount
,
1
);
expect
(
factoryInvocationCount
,
1
);
});
});
testWidgets
(
'PlatformViewLink Widget init, should create a SizedBox widget before onPlatformViewCreated and a PlatformViewSurface after'
,
(
WidgetTester
tester
)
async
{
final
int
currentViewId
=
platformViewsRegistry
.
getNextPlatformViewId
();
late
int
createdPlatformViewId
;
late
PlatformViewCreatedCallback
onPlatformViewCreatedCallBack
;
final
PlatformViewLink
platformViewLink
=
PlatformViewLink
(
viewType:
'webview'
,
onCreatePlatformView:
(
PlatformViewCreationParams
params
)
{
onPlatformViewCreatedCallBack
=
params
.
onPlatformViewCreated
;
createdPlatformViewId
=
params
.
id
;
return
FakePlatformViewController
(
params
.
id
);
},
surfaceFactory:
(
BuildContext
context
,
PlatformViewController
controller
)
{
return
PlatformViewSurface
(
gestureRecognizers:
const
<
Factory
<
OneSequenceGestureRecognizer
>>{},
controller:
controller
,
hitTestBehavior:
PlatformViewHitTestBehavior
.
opaque
,
);
},
);
await
tester
.
pumpWidget
(
platformViewLink
);
expect
(()
=>
tester
.
allWidgets
.
whereType
<
SizedBox
>().
first
,
returnsNormally
);
onPlatformViewCreatedCallBack
(
createdPlatformViewId
);
await
tester
.
pump
();
expect
(()
=>
tester
.
allWidgets
.
whereType
<
PlatformViewSurface
>().
first
,
returnsNormally
);
expect
(
createdPlatformViewId
,
currentViewId
+
1
);
},
);
testWidgets
(
'PlatformViewLink Widget dispose'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'PlatformViewLink Widget dispose'
,
(
WidgetTester
tester
)
async
{
late
FakePlatformViewController
disposedController
;
late
FakePlatformViewController
disposedController
;
final
PlatformViewLink
platformViewLink
=
PlatformViewLink
(
final
PlatformViewLink
platformViewLink
=
PlatformViewLink
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment