Add a layoutDirection parameter to AndroidView (#20838)
This commit is contained in:
parent
5d1f874075
commit
1fc7814bb1
@ -59,16 +59,21 @@ class PlatformViewsService {
|
|||||||
///
|
///
|
||||||
/// The Android view will only be created after [AndroidViewController.setSize] is called for the
|
/// The Android view will only be created after [AndroidViewController.setSize] is called for the
|
||||||
/// first time.
|
/// first time.
|
||||||
|
///
|
||||||
|
/// The `id, `viewType, and `layoutDirection` parameters must not be null.
|
||||||
static AndroidViewController initAndroidView({
|
static AndroidViewController initAndroidView({
|
||||||
@required int id,
|
@required int id,
|
||||||
@required String viewType,
|
@required String viewType,
|
||||||
|
@required TextDirection layoutDirection,
|
||||||
PlatformViewCreatedCallback onPlatformViewCreated,
|
PlatformViewCreatedCallback onPlatformViewCreated,
|
||||||
}) {
|
}) {
|
||||||
assert(id != null);
|
assert(id != null);
|
||||||
assert(viewType != null);
|
assert(viewType != null);
|
||||||
|
assert(layoutDirection != null);
|
||||||
return new AndroidViewController._(
|
return new AndroidViewController._(
|
||||||
id,
|
id,
|
||||||
viewType,
|
viewType,
|
||||||
|
layoutDirection,
|
||||||
onPlatformViewCreated
|
onPlatformViewCreated
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -343,10 +348,13 @@ class AndroidViewController {
|
|||||||
AndroidViewController._(
|
AndroidViewController._(
|
||||||
this.id,
|
this.id,
|
||||||
String viewType,
|
String viewType,
|
||||||
|
TextDirection layoutDirection,
|
||||||
PlatformViewCreatedCallback onPlatformViewCreated,
|
PlatformViewCreatedCallback onPlatformViewCreated,
|
||||||
) : assert(id != null),
|
) : assert(id != null),
|
||||||
assert(viewType != null),
|
assert(viewType != null),
|
||||||
|
assert(layoutDirection != null),
|
||||||
_viewType = viewType,
|
_viewType = viewType,
|
||||||
|
_layoutDirection = layoutDirection,
|
||||||
_onPlatformViewCreated = onPlatformViewCreated,
|
_onPlatformViewCreated = onPlatformViewCreated,
|
||||||
_state = _AndroidViewState.waitingForSize;
|
_state = _AndroidViewState.waitingForSize;
|
||||||
|
|
||||||
@ -380,6 +388,12 @@ class AndroidViewController {
|
|||||||
/// Android's [MotionEvent.ACTION_POINTER_UP](https://developer.android.com/reference/android/view/MotionEvent#ACTION_POINTER_UP)
|
/// Android's [MotionEvent.ACTION_POINTER_UP](https://developer.android.com/reference/android/view/MotionEvent#ACTION_POINTER_UP)
|
||||||
static const int kActionPointerUp = 6;
|
static const int kActionPointerUp = 6;
|
||||||
|
|
||||||
|
/// Android's [View.LAYOUT_DIRECTION_LTR](https://developer.android.com/reference/android/view/View.html#LAYOUT_DIRECTION_LTR) value.
|
||||||
|
static const int kAndroidLayoutDirectionLtr = 0;
|
||||||
|
|
||||||
|
/// Android's [View.LAYOUT_DIRECTION_RTL](https://developer.android.com/reference/android/view/View.html#LAYOUT_DIRECTION_RTL) value.
|
||||||
|
static const int kAndroidLayoutDirectionRtl = 1;
|
||||||
|
|
||||||
/// The unique identifier of the Android view controlled by this controller.
|
/// The unique identifier of the Android view controlled by this controller.
|
||||||
final int id;
|
final int id;
|
||||||
|
|
||||||
@ -396,6 +410,8 @@ class AndroidViewController {
|
|||||||
/// disposed.
|
/// disposed.
|
||||||
int get textureId => _textureId;
|
int get textureId => _textureId;
|
||||||
|
|
||||||
|
TextDirection _layoutDirection;
|
||||||
|
|
||||||
_AndroidViewState _state;
|
_AndroidViewState _state;
|
||||||
|
|
||||||
/// Disposes the Android view.
|
/// Disposes the Android view.
|
||||||
@ -430,6 +446,37 @@ class AndroidViewController {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets the layout direction for the Android view.
|
||||||
|
Future<void> setLayoutDirection(TextDirection layoutDirection) async {
|
||||||
|
if (_state == _AndroidViewState.disposed)
|
||||||
|
throw new FlutterError('trying to set a layout direction for a disposed Android View. View id: $id');
|
||||||
|
|
||||||
|
if (layoutDirection == _layoutDirection)
|
||||||
|
return;
|
||||||
|
|
||||||
|
assert(layoutDirection != null);
|
||||||
|
_layoutDirection = layoutDirection;
|
||||||
|
|
||||||
|
// If the view was not yet created we just update _layoutDirection and return, as the new
|
||||||
|
// direction will be used in _create.
|
||||||
|
if (_state == _AndroidViewState.waitingForSize)
|
||||||
|
return;
|
||||||
|
|
||||||
|
await SystemChannels.platform_views.invokeMethod('setDirection', <String, dynamic> {
|
||||||
|
'id': id,
|
||||||
|
'direction': _getAndroidDirection(layoutDirection),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
static int _getAndroidDirection(TextDirection direction) {
|
||||||
|
switch (direction) {
|
||||||
|
case TextDirection.ltr:
|
||||||
|
return kAndroidLayoutDirectionLtr;
|
||||||
|
case TextDirection.rtl:
|
||||||
|
return kAndroidLayoutDirectionRtl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Sends an Android [MotionEvent](https://developer.android.com/reference/android/view/MotionEvent)
|
/// Sends an Android [MotionEvent](https://developer.android.com/reference/android/view/MotionEvent)
|
||||||
/// to the view.
|
/// to the view.
|
||||||
///
|
///
|
||||||
@ -454,6 +501,7 @@ class AndroidViewController {
|
|||||||
'viewType': _viewType,
|
'viewType': _viewType,
|
||||||
'width': size.width,
|
'width': size.width,
|
||||||
'height': size.height,
|
'height': size.height,
|
||||||
|
'direction': _getAndroidDirection(_layoutDirection),
|
||||||
});
|
});
|
||||||
if (_onPlatformViewCreated != null)
|
if (_onPlatformViewCreated != null)
|
||||||
_onPlatformViewCreated(id);
|
_onPlatformViewCreated(id);
|
||||||
|
@ -6,6 +6,8 @@ import 'package:flutter/foundation.dart';
|
|||||||
import 'package:flutter/rendering.dart';
|
import 'package:flutter/rendering.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
|
import 'basic.dart';
|
||||||
|
import 'debug.dart';
|
||||||
import 'framework.dart';
|
import 'framework.dart';
|
||||||
|
|
||||||
/// Embeds an Android view in the Widget hierarchy.
|
/// Embeds an Android view in the Widget hierarchy.
|
||||||
@ -45,6 +47,7 @@ class AndroidView extends StatefulWidget {
|
|||||||
@required this.viewType,
|
@required this.viewType,
|
||||||
this.onPlatformViewCreated,
|
this.onPlatformViewCreated,
|
||||||
this.hitTestBehavior = PlatformViewHitTestBehavior.opaque,
|
this.hitTestBehavior = PlatformViewHitTestBehavior.opaque,
|
||||||
|
this.layoutDirection,
|
||||||
}) : assert(viewType != null),
|
}) : assert(viewType != null),
|
||||||
assert(hitTestBehavior != null),
|
assert(hitTestBehavior != null),
|
||||||
super(key: key);
|
super(key: key);
|
||||||
@ -66,6 +69,11 @@ class AndroidView extends StatefulWidget {
|
|||||||
/// This defaults to [PlatformViewHitTestBehavior.opaque].
|
/// This defaults to [PlatformViewHitTestBehavior.opaque].
|
||||||
final PlatformViewHitTestBehavior hitTestBehavior;
|
final PlatformViewHitTestBehavior hitTestBehavior;
|
||||||
|
|
||||||
|
/// The text direction to use for the embedded view.
|
||||||
|
///
|
||||||
|
/// If this is null, the ambient [Directionality] is used instead.
|
||||||
|
final TextDirection layoutDirection;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State createState() => new _AndroidViewState();
|
State createState() => new _AndroidViewState();
|
||||||
}
|
}
|
||||||
@ -73,6 +81,8 @@ class AndroidView extends StatefulWidget {
|
|||||||
class _AndroidViewState extends State<AndroidView> {
|
class _AndroidViewState extends State<AndroidView> {
|
||||||
int _id;
|
int _id;
|
||||||
AndroidViewController _controller;
|
AndroidViewController _controller;
|
||||||
|
TextDirection _layoutDirection;
|
||||||
|
bool _initialized = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -82,19 +92,53 @@ class _AndroidViewState extends State<AndroidView> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
void _initializeOnce() {
|
||||||
void initState() {
|
if (_initialized) {
|
||||||
super.initState();
|
return;
|
||||||
|
}
|
||||||
|
_initialized = true;
|
||||||
|
_layoutDirection = _findLayoutDirection();
|
||||||
_createNewAndroidView();
|
_createNewAndroidView();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didChangeDependencies() {
|
||||||
|
super.didChangeDependencies();
|
||||||
|
_initializeOnce();
|
||||||
|
|
||||||
|
final TextDirection newLayoutDirection = _findLayoutDirection();
|
||||||
|
final bool didChangeLayoutDirection = _layoutDirection != newLayoutDirection;
|
||||||
|
_layoutDirection = newLayoutDirection;
|
||||||
|
|
||||||
|
if (didChangeLayoutDirection) {
|
||||||
|
// The native view will update asynchronously, in the meantime we don't want
|
||||||
|
// to block the framework. (so this is intentionally not awaiting).
|
||||||
|
_controller.setLayoutDirection(_layoutDirection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void didUpdateWidget(AndroidView oldWidget) {
|
void didUpdateWidget(AndroidView oldWidget) {
|
||||||
super.didUpdateWidget(oldWidget);
|
super.didUpdateWidget(oldWidget);
|
||||||
if (widget.viewType == oldWidget.viewType)
|
|
||||||
return;
|
final TextDirection newLayoutDirection = _findLayoutDirection();
|
||||||
|
final bool didChangeLayoutDirection = _layoutDirection != newLayoutDirection;
|
||||||
|
_layoutDirection = newLayoutDirection;
|
||||||
|
|
||||||
|
if (widget.viewType != oldWidget.viewType) {
|
||||||
_controller.dispose();
|
_controller.dispose();
|
||||||
_createNewAndroidView();
|
_createNewAndroidView();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (didChangeLayoutDirection) {
|
||||||
|
_controller.setLayoutDirection(_layoutDirection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TextDirection _findLayoutDirection() {
|
||||||
|
assert(widget.layoutDirection != null || debugCheckHasDirectionality(context));
|
||||||
|
return widget.layoutDirection ?? Directionality.of(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -108,10 +152,10 @@ class _AndroidViewState extends State<AndroidView> {
|
|||||||
_controller = PlatformViewsService.initAndroidView(
|
_controller = PlatformViewsService.initAndroidView(
|
||||||
id: _id,
|
id: _id,
|
||||||
viewType: widget.viewType,
|
viewType: widget.viewType,
|
||||||
|
layoutDirection: _layoutDirection,
|
||||||
onPlatformViewCreated: widget.onPlatformViewCreated
|
onPlatformViewCreated: widget.onPlatformViewCreated
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class _AndroidPlatformView extends LeafRenderObjectWidget {
|
class _AndroidPlatformView extends LeafRenderObjectWidget {
|
||||||
|
@ -47,6 +47,8 @@ class FakePlatformViewsController {
|
|||||||
return _resize(call);
|
return _resize(call);
|
||||||
case 'touch':
|
case 'touch':
|
||||||
return _touch(call);
|
return _touch(call);
|
||||||
|
case 'setDirection':
|
||||||
|
return _setDirection(call);
|
||||||
}
|
}
|
||||||
return new Future<Null>.sync(() => null);
|
return new Future<Null>.sync(() => null);
|
||||||
}
|
}
|
||||||
@ -57,6 +59,7 @@ class FakePlatformViewsController {
|
|||||||
final String viewType = args['viewType'];
|
final String viewType = args['viewType'];
|
||||||
final double width = args['width'];
|
final double width = args['width'];
|
||||||
final double height = args['height'];
|
final double height = args['height'];
|
||||||
|
final int layoutDirection = args['direction'];
|
||||||
|
|
||||||
if (_views.containsKey(id))
|
if (_views.containsKey(id))
|
||||||
throw new PlatformException(
|
throw new PlatformException(
|
||||||
@ -70,7 +73,7 @@ class FakePlatformViewsController {
|
|||||||
message: 'Trying to create a platform view of unregistered type: $viewType',
|
message: 'Trying to create a platform view of unregistered type: $viewType',
|
||||||
);
|
);
|
||||||
|
|
||||||
_views[id] = new FakePlatformView(id, viewType, new Size(width, height));
|
_views[id] = new FakePlatformView(id, viewType, new Size(width, height), layoutDirection);
|
||||||
final int textureId = _textureCounter++;
|
final int textureId = _textureCounter++;
|
||||||
return new Future<int>.sync(() => textureId);
|
return new Future<int>.sync(() => textureId);
|
||||||
}
|
}
|
||||||
@ -130,15 +133,31 @@ class FakePlatformViewsController {
|
|||||||
return new Future<Null>.sync(() => null);
|
return new Future<Null>.sync(() => null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<dynamic> _setDirection(MethodCall call) async {
|
||||||
|
final Map<dynamic, dynamic> args = call.arguments;
|
||||||
|
final int id = args['id'];
|
||||||
|
final int layoutDirection = args['direction'];
|
||||||
|
|
||||||
|
if (!_views.containsKey(id))
|
||||||
|
throw new PlatformException(
|
||||||
|
code: 'error',
|
||||||
|
message: 'Trying to resize a platform view with unknown id: $id',
|
||||||
|
);
|
||||||
|
|
||||||
|
_views[id].layoutDirection = layoutDirection;
|
||||||
|
|
||||||
|
return new Future<Null>.sync(() => null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class FakePlatformView {
|
class FakePlatformView {
|
||||||
|
|
||||||
FakePlatformView(this.id, this.type, this.size);
|
FakePlatformView(this.id, this.type, this.size, this.layoutDirection);
|
||||||
|
|
||||||
final int id;
|
final int id;
|
||||||
final String type;
|
final String type;
|
||||||
Size size;
|
Size size;
|
||||||
|
int layoutDirection;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool operator ==(dynamic other) {
|
bool operator ==(dynamic other) {
|
||||||
@ -151,11 +170,11 @@ class FakePlatformView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
int get hashCode => hashValues(id, type, size);
|
int get hashCode => hashValues(id, type, size, layoutDirection);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'FakePlatformView(id: $id, type: $type, size: $size)';
|
return 'FakePlatformView(id: $id, type: $type, size: $size, layoutDirection: $layoutDirection)';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,57 +19,66 @@ void main() {
|
|||||||
|
|
||||||
test('create Android view of unregistered type', () async {
|
test('create Android view of unregistered type', () async {
|
||||||
expect(
|
expect(
|
||||||
() => PlatformViewsService.initAndroidView(
|
() {
|
||||||
id: 0, viewType: 'web').setSize(const Size(100.0, 100.0)),
|
return PlatformViewsService.initAndroidView(
|
||||||
throwsA(isInstanceOf<PlatformException>()));
|
id: 0,
|
||||||
|
viewType: 'web',
|
||||||
|
layoutDirection: TextDirection.ltr,
|
||||||
|
).setSize(const Size(100.0, 100.0));
|
||||||
|
},
|
||||||
|
throwsA(isInstanceOf<PlatformException>()),
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('create Android views', () async {
|
test('create Android views', () async {
|
||||||
viewsController.registerViewType('webview');
|
viewsController.registerViewType('webview');
|
||||||
await PlatformViewsService.initAndroidView(
|
await PlatformViewsService.initAndroidView(id: 0, viewType: 'webview', layoutDirection: TextDirection.ltr)
|
||||||
id: 0, viewType: 'webview').setSize(const Size(100.0, 100.0));
|
.setSize(const Size(100.0, 100.0));
|
||||||
await PlatformViewsService.initAndroidView(
|
await PlatformViewsService.initAndroidView( id: 1, viewType: 'webview', layoutDirection: TextDirection.rtl)
|
||||||
id: 1, viewType: 'webview').setSize(const Size(200.0, 300.0));
|
.setSize(const Size(200.0, 300.0));
|
||||||
expect(
|
expect(
|
||||||
viewsController.views,
|
viewsController.views,
|
||||||
unorderedEquals(<FakePlatformView>[
|
unorderedEquals(<FakePlatformView>[
|
||||||
new FakePlatformView(0, 'webview', const Size(100.0, 100.0)),
|
new FakePlatformView(0, 'webview', const Size(100.0, 100.0), AndroidViewController.kAndroidLayoutDirectionLtr),
|
||||||
new FakePlatformView(1, 'webview', const Size(200.0, 300.0)),
|
new FakePlatformView(1, 'webview', const Size(200.0, 300.0), AndroidViewController.kAndroidLayoutDirectionRtl),
|
||||||
]));
|
]));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('reuse Android view id', () async {
|
test('reuse Android view id', () async {
|
||||||
viewsController.registerViewType('webview');
|
viewsController.registerViewType('webview');
|
||||||
await PlatformViewsService.initAndroidView(
|
await PlatformViewsService.initAndroidView(
|
||||||
id: 0, viewType: 'webview').setSize(const Size(100.0, 100.0));
|
id: 0,
|
||||||
|
viewType: 'webview',
|
||||||
|
layoutDirection: TextDirection.ltr,
|
||||||
|
).setSize(const Size(100.0, 100.0));
|
||||||
expect(
|
expect(
|
||||||
() => PlatformViewsService.initAndroidView(
|
() => PlatformViewsService.initAndroidView(
|
||||||
id: 0, viewType: 'web').setSize(const Size(100.0, 100.0)),
|
id: 0, viewType: 'web', layoutDirection: TextDirection.ltr).setSize(const Size(100.0, 100.0)),
|
||||||
throwsA(isInstanceOf<PlatformException>()));
|
throwsA(isInstanceOf<PlatformException>()));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('dispose Android view', () async {
|
test('dispose Android view', () async {
|
||||||
viewsController.registerViewType('webview');
|
viewsController.registerViewType('webview');
|
||||||
await PlatformViewsService.initAndroidView(
|
await PlatformViewsService.initAndroidView(
|
||||||
id: 0, viewType: 'webview').setSize(const Size(100.0, 100.0));
|
id: 0, viewType: 'webview', layoutDirection: TextDirection.ltr).setSize(const Size(100.0, 100.0));
|
||||||
final AndroidViewController viewController =
|
final AndroidViewController viewController =
|
||||||
PlatformViewsService.initAndroidView(id: 1, viewType: 'webview');
|
PlatformViewsService.initAndroidView(id: 1, viewType: 'webview', layoutDirection: TextDirection.ltr);
|
||||||
await viewController.setSize(const Size(200.0, 300.0));
|
await viewController.setSize(const Size(200.0, 300.0));
|
||||||
|
|
||||||
viewController.dispose();
|
viewController.dispose();
|
||||||
expect(
|
expect(
|
||||||
viewsController.views,
|
viewsController.views,
|
||||||
unorderedEquals(<FakePlatformView>[
|
unorderedEquals(<FakePlatformView>[
|
||||||
new FakePlatformView(0, 'webview', const Size(100.0, 100.0)),
|
new FakePlatformView(0, 'webview', const Size(100.0, 100.0), AndroidViewController.kAndroidLayoutDirectionLtr),
|
||||||
]));
|
]));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('dispose inexisting Android view', () async {
|
test('dispose inexisting Android view', () async {
|
||||||
viewsController.registerViewType('webview');
|
viewsController.registerViewType('webview');
|
||||||
await PlatformViewsService.initAndroidView(
|
await PlatformViewsService.initAndroidView(
|
||||||
id: 0, viewType: 'webview').setSize(const Size(100.0, 100.0));
|
id: 0, viewType: 'webview', layoutDirection: TextDirection.ltr).setSize(const Size(100.0, 100.0));
|
||||||
final AndroidViewController viewController =
|
final AndroidViewController viewController =
|
||||||
PlatformViewsService.initAndroidView(id: 1, viewType: 'webview');
|
PlatformViewsService.initAndroidView(id: 1, viewType: 'webview', layoutDirection: TextDirection.ltr);
|
||||||
await viewController.setSize(const Size(200.0, 300.0));
|
await viewController.setSize(const Size(200.0, 300.0));
|
||||||
await viewController.dispose();
|
await viewController.dispose();
|
||||||
await viewController.dispose();
|
await viewController.dispose();
|
||||||
@ -78,16 +87,16 @@ void main() {
|
|||||||
test('resize Android view', () async {
|
test('resize Android view', () async {
|
||||||
viewsController.registerViewType('webview');
|
viewsController.registerViewType('webview');
|
||||||
await PlatformViewsService.initAndroidView(
|
await PlatformViewsService.initAndroidView(
|
||||||
id: 0, viewType: 'webview').setSize(const Size(100.0, 100.0));
|
id: 0, viewType: 'webview', layoutDirection: TextDirection.ltr).setSize(const Size(100.0, 100.0));
|
||||||
final AndroidViewController viewController =
|
final AndroidViewController viewController =
|
||||||
PlatformViewsService.initAndroidView(id: 1, viewType: 'webview');
|
PlatformViewsService.initAndroidView(id: 1, viewType: 'webview', layoutDirection: TextDirection.ltr);
|
||||||
await viewController.setSize(const Size(200.0, 300.0));
|
await viewController.setSize(const Size(200.0, 300.0));
|
||||||
await viewController.setSize(const Size(500.0, 500.0));
|
await viewController.setSize(const Size(500.0, 500.0));
|
||||||
expect(
|
expect(
|
||||||
viewsController.views,
|
viewsController.views,
|
||||||
unorderedEquals(<FakePlatformView>[
|
unorderedEquals(<FakePlatformView>[
|
||||||
new FakePlatformView(0, 'webview', const Size(100.0, 100.0)),
|
new FakePlatformView(0, 'webview', const Size(100.0, 100.0), AndroidViewController.kAndroidLayoutDirectionLtr),
|
||||||
new FakePlatformView(1, 'webview', const Size(500.0, 500.0)),
|
new FakePlatformView(1, 'webview', const Size(500.0, 500.0), AndroidViewController.kAndroidLayoutDirectionLtr),
|
||||||
]));
|
]));
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -97,19 +106,45 @@ void main() {
|
|||||||
final PlatformViewCreatedCallback callback = (int id) { createdViews.add(id); };
|
final PlatformViewCreatedCallback callback = (int id) { createdViews.add(id); };
|
||||||
|
|
||||||
final AndroidViewController controller1 = PlatformViewsService.initAndroidView(
|
final AndroidViewController controller1 = PlatformViewsService.initAndroidView(
|
||||||
id: 0, viewType: 'webview', onPlatformViewCreated: callback);
|
id: 0, viewType: 'webview', layoutDirection: TextDirection.ltr, onPlatformViewCreated: callback);
|
||||||
expect(createdViews, isEmpty);
|
expect(createdViews, isEmpty);
|
||||||
|
|
||||||
await controller1.setSize(const Size(100.0, 100.0));
|
await controller1.setSize(const Size(100.0, 100.0));
|
||||||
expect(createdViews, orderedEquals(<int>[0]));
|
expect(createdViews, orderedEquals(<int>[0]));
|
||||||
|
|
||||||
final AndroidViewController controller2 = PlatformViewsService.initAndroidView(
|
final AndroidViewController controller2 = PlatformViewsService.initAndroidView(
|
||||||
id: 5, viewType: 'webview', onPlatformViewCreated: callback);
|
id: 5, viewType: 'webview', layoutDirection: TextDirection.ltr, onPlatformViewCreated: callback);
|
||||||
expect(createdViews, orderedEquals(<int>[0]));
|
expect(createdViews, orderedEquals(<int>[0]));
|
||||||
|
|
||||||
await controller2.setSize(const Size(100.0, 200.0));
|
await controller2.setSize(const Size(100.0, 200.0));
|
||||||
expect(createdViews, orderedEquals(<int>[0, 5]));
|
expect(createdViews, orderedEquals(<int>[0, 5]));
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('change Android view\'s directionality before creation', () async {
|
||||||
|
viewsController.registerViewType('webview');
|
||||||
|
final AndroidViewController viewController =
|
||||||
|
PlatformViewsService.initAndroidView(id: 0, viewType: 'webview', layoutDirection: TextDirection.rtl);
|
||||||
|
await viewController.setLayoutDirection(TextDirection.ltr);
|
||||||
|
await viewController.setSize(const Size(100.0, 100.0));
|
||||||
|
expect(
|
||||||
|
viewsController.views,
|
||||||
|
unorderedEquals(<FakePlatformView>[
|
||||||
|
new FakePlatformView(0, 'webview', const Size(100.0, 100.0), AndroidViewController.kAndroidLayoutDirectionLtr),
|
||||||
|
]));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('change Android view\'s directionality after creation', () async {
|
||||||
|
viewsController.registerViewType('webview');
|
||||||
|
final AndroidViewController viewController =
|
||||||
|
PlatformViewsService.initAndroidView(id: 0, viewType: 'webview', layoutDirection: TextDirection.ltr);
|
||||||
|
await viewController.setSize(const Size(100.0, 100.0));
|
||||||
|
await viewController.setLayoutDirection(TextDirection.rtl);
|
||||||
|
expect(
|
||||||
|
viewsController.views,
|
||||||
|
unorderedEquals(<FakePlatformView>[
|
||||||
|
new FakePlatformView(0, 'webview', const Size(100.0, 100.0), AndroidViewController.kAndroidLayoutDirectionRtl),
|
||||||
|
]));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ void main() {
|
|||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
width: 200.0,
|
width: 200.0,
|
||||||
height: 100.0,
|
height: 100.0,
|
||||||
child: AndroidView(viewType: 'webview'),
|
child: AndroidView(viewType: 'webview', layoutDirection: TextDirection.ltr),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@ -32,7 +32,7 @@ void main() {
|
|||||||
expect(
|
expect(
|
||||||
viewsController.views,
|
viewsController.views,
|
||||||
unorderedEquals(<FakePlatformView>[
|
unorderedEquals(<FakePlatformView>[
|
||||||
new FakePlatformView(currentViewId + 1, 'webview', const Size(200.0, 100.0))
|
new FakePlatformView(currentViewId + 1, 'webview', const Size(200.0, 100.0), AndroidViewController.kAndroidLayoutDirectionLtr)
|
||||||
]),
|
]),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -46,7 +46,7 @@ void main() {
|
|||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
width: 200.0,
|
width: 200.0,
|
||||||
height: 100.0,
|
height: 100.0,
|
||||||
child: AndroidView(viewType: 'webview'),
|
child: AndroidView(viewType: 'webview', layoutDirection: TextDirection.ltr),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@ -58,7 +58,7 @@ void main() {
|
|||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
width: 100.0,
|
width: 100.0,
|
||||||
height: 50.0,
|
height: 50.0,
|
||||||
child: AndroidView(viewType: 'webview'),
|
child: AndroidView(viewType: 'webview', layoutDirection: TextDirection.ltr),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@ -70,7 +70,7 @@ void main() {
|
|||||||
expect(
|
expect(
|
||||||
viewsController.views,
|
viewsController.views,
|
||||||
unorderedEquals(<FakePlatformView>[
|
unorderedEquals(<FakePlatformView>[
|
||||||
new FakePlatformView(currentViewId + 1, 'webview', const Size(200.0, 100.0))
|
new FakePlatformView(currentViewId + 1, 'webview', const Size(200.0, 100.0), AndroidViewController.kAndroidLayoutDirectionLtr)
|
||||||
]),
|
]),
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -80,7 +80,7 @@ void main() {
|
|||||||
expect(
|
expect(
|
||||||
viewsController.views,
|
viewsController.views,
|
||||||
unorderedEquals(<FakePlatformView>[
|
unorderedEquals(<FakePlatformView>[
|
||||||
new FakePlatformView(currentViewId + 1, 'webview', const Size(100.0, 50.0))
|
new FakePlatformView(currentViewId + 1, 'webview', const Size(100.0, 50.0), AndroidViewController.kAndroidLayoutDirectionLtr)
|
||||||
]),
|
]),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -95,7 +95,7 @@ void main() {
|
|||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
width: 200.0,
|
width: 200.0,
|
||||||
height: 100.0,
|
height: 100.0,
|
||||||
child: AndroidView(viewType: 'webview'),
|
child: AndroidView(viewType: 'webview', layoutDirection: TextDirection.ltr),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@ -105,7 +105,7 @@ void main() {
|
|||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
width: 200.0,
|
width: 200.0,
|
||||||
height: 100.0,
|
height: 100.0,
|
||||||
child: AndroidView(viewType: 'maps'),
|
child: AndroidView(viewType: 'maps', layoutDirection: TextDirection.ltr),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@ -113,7 +113,7 @@ void main() {
|
|||||||
expect(
|
expect(
|
||||||
viewsController.views,
|
viewsController.views,
|
||||||
unorderedEquals(<FakePlatformView>[
|
unorderedEquals(<FakePlatformView>[
|
||||||
new FakePlatformView(currentViewId + 2, 'maps', const Size(200.0, 100.0))
|
new FakePlatformView(currentViewId + 2, 'maps', const Size(200.0, 100.0), AndroidViewController.kAndroidLayoutDirectionLtr)
|
||||||
]),
|
]),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -126,7 +126,7 @@ void main() {
|
|||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
width: 200.0,
|
width: 200.0,
|
||||||
height: 100.0,
|
height: 100.0,
|
||||||
child: AndroidView(viewType: 'webview'),
|
child: AndroidView(viewType: 'webview', layoutDirection: TextDirection.ltr),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@ -156,7 +156,7 @@ void main() {
|
|||||||
child: new SizedBox(
|
child: new SizedBox(
|
||||||
width: 200.0,
|
width: 200.0,
|
||||||
height: 100.0,
|
height: 100.0,
|
||||||
child: new AndroidView(viewType: 'webview', key: key),
|
child: new AndroidView(viewType: 'webview', layoutDirection: TextDirection.ltr, key: key),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@ -167,7 +167,7 @@ void main() {
|
|||||||
child: new SizedBox(
|
child: new SizedBox(
|
||||||
width: 200.0,
|
width: 200.0,
|
||||||
height: 100.0,
|
height: 100.0,
|
||||||
child: new AndroidView(viewType: 'webview', key: key),
|
child: new AndroidView(viewType: 'webview', layoutDirection: TextDirection.ltr, key: key),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -176,7 +176,7 @@ void main() {
|
|||||||
expect(
|
expect(
|
||||||
viewsController.views,
|
viewsController.views,
|
||||||
unorderedEquals(<FakePlatformView>[
|
unorderedEquals(<FakePlatformView>[
|
||||||
new FakePlatformView(currentViewId + 1, 'webview', const Size(200.0, 100.0))
|
new FakePlatformView(currentViewId + 1, 'webview', const Size(200.0, 100.0), AndroidViewController.kAndroidLayoutDirectionLtr)
|
||||||
]),
|
]),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -191,7 +191,7 @@ void main() {
|
|||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
width: 200.0,
|
width: 200.0,
|
||||||
height: 100.0,
|
height: 100.0,
|
||||||
child: AndroidView(viewType: 'webview'),
|
child: AndroidView(viewType: 'webview', layoutDirection: TextDirection.ltr,),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@ -230,6 +230,7 @@ void main() {
|
|||||||
child: AndroidView(
|
child: AndroidView(
|
||||||
viewType: 'webview',
|
viewType: 'webview',
|
||||||
hitTestBehavior: PlatformViewHitTestBehavior.transparent,
|
hitTestBehavior: PlatformViewHitTestBehavior.transparent,
|
||||||
|
layoutDirection: TextDirection.ltr,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -272,6 +273,7 @@ void main() {
|
|||||||
child: AndroidView(
|
child: AndroidView(
|
||||||
viewType: 'webview',
|
viewType: 'webview',
|
||||||
hitTestBehavior: PlatformViewHitTestBehavior.translucent,
|
hitTestBehavior: PlatformViewHitTestBehavior.translucent,
|
||||||
|
layoutDirection: TextDirection.ltr,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -316,6 +318,7 @@ void main() {
|
|||||||
child: AndroidView(
|
child: AndroidView(
|
||||||
viewType: 'webview',
|
viewType: 'webview',
|
||||||
hitTestBehavior: PlatformViewHitTestBehavior.opaque,
|
hitTestBehavior: PlatformViewHitTestBehavior.opaque,
|
||||||
|
layoutDirection: TextDirection.ltr,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -350,7 +353,7 @@ void main() {
|
|||||||
child: const SizedBox(
|
child: const SizedBox(
|
||||||
width: 200.0,
|
width: 200.0,
|
||||||
height: 100.0,
|
height: 100.0,
|
||||||
child: AndroidView(viewType: 'webview'),
|
child: AndroidView(viewType: 'webview', layoutDirection: TextDirection.ltr),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -367,4 +370,88 @@ void main() {
|
|||||||
]),
|
]),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWidgets('Android view directionality', (WidgetTester tester) async {
|
||||||
|
final int currentViewId = platformViewsRegistry.getNextPlatformViewId();
|
||||||
|
final FakePlatformViewsController viewsController = new FakePlatformViewsController(TargetPlatform.android);
|
||||||
|
viewsController.registerViewType('maps');
|
||||||
|
await tester.pumpWidget(
|
||||||
|
const Center(
|
||||||
|
child: SizedBox(
|
||||||
|
width: 200.0,
|
||||||
|
height: 100.0,
|
||||||
|
child: AndroidView(viewType: 'maps', layoutDirection: TextDirection.rtl),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
viewsController.views,
|
||||||
|
unorderedEquals(<FakePlatformView>[
|
||||||
|
new FakePlatformView(currentViewId + 1, 'maps', const Size(200.0, 100.0), AndroidViewController.kAndroidLayoutDirectionRtl)
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
|
||||||
|
await tester.pumpWidget(
|
||||||
|
const Center(
|
||||||
|
child: SizedBox(
|
||||||
|
width: 200.0,
|
||||||
|
height: 100.0,
|
||||||
|
child: AndroidView(viewType: 'maps', layoutDirection: TextDirection.ltr),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
viewsController.views,
|
||||||
|
unorderedEquals(<FakePlatformView>[
|
||||||
|
new FakePlatformView(currentViewId + 1, 'maps', const Size(200.0, 100.0), AndroidViewController.kAndroidLayoutDirectionLtr)
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('Android view ambient directionality', (WidgetTester tester) async {
|
||||||
|
final int currentViewId = platformViewsRegistry.getNextPlatformViewId();
|
||||||
|
final FakePlatformViewsController viewsController = new FakePlatformViewsController(TargetPlatform.android);
|
||||||
|
viewsController.registerViewType('maps');
|
||||||
|
await tester.pumpWidget(
|
||||||
|
const Directionality(
|
||||||
|
textDirection: TextDirection.rtl,
|
||||||
|
child: Center(
|
||||||
|
child: SizedBox(
|
||||||
|
width: 200.0,
|
||||||
|
height: 100.0,
|
||||||
|
child: AndroidView(viewType: 'maps'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
viewsController.views,
|
||||||
|
unorderedEquals(<FakePlatformView>[
|
||||||
|
new FakePlatformView(currentViewId + 1, 'maps', const Size(200.0, 100.0), AndroidViewController.kAndroidLayoutDirectionRtl)
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
|
||||||
|
await tester.pumpWidget(
|
||||||
|
const Directionality(
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
child: Center(
|
||||||
|
child: SizedBox(
|
||||||
|
width: 200.0,
|
||||||
|
height: 100.0,
|
||||||
|
child: AndroidView(viewType: 'maps'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
viewsController.views,
|
||||||
|
unorderedEquals(<FakePlatformView>[
|
||||||
|
new FakePlatformView(currentViewId + 1, 'maps', const Size(200.0, 100.0), AndroidViewController.kAndroidLayoutDirectionLtr)
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user