Skip to content

[webview_flutter] Update webview to be focused #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
</head>

<body>
<body style="background-color: blue">
<input id="ip1" type="text" ></input>
<button onclick="a()">Click</button>
<input id="ip2" type="text" ></input>
Expand Down
49 changes: 27 additions & 22 deletions packages/webview_flutter/lib/webview_flutter_tizen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,11 @@ import 'package:flutter/gestures.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter/semantics.dart';
import 'package:flutter/rendering.dart';

import 'package:webview_flutter/platform_interface.dart';
import 'package:webview_flutter/src/webview_method_channel.dart';

import 'package:flutter/src/rendering/binding.dart';
import 'package:flutter/src/rendering/box.dart';
import 'package:flutter/src/rendering/layer.dart';
import 'package:flutter/src/rendering/mouse_cursor.dart';
import 'package:flutter/src/rendering/mouse_tracking.dart';
import 'package:flutter/src/rendering/object.dart';

enum _TizenViewState {
waitingForSize,
creating,
Expand Down Expand Up @@ -110,7 +104,7 @@ class TizenViewController extends PlatformViewController {
'viewType': _viewType,
'width': _size.width,
'height': _size.height,
// 'direction': _layoutDirection,
'direction': _layoutDirection == TextDirection.ltr ? 0 : 1,
};
if (_creationParams != null) {
final ByteData paramsByteData =
Expand Down Expand Up @@ -151,6 +145,7 @@ class TizenViewController extends PlatformViewController {

set pointTransformer(PointTransformer transformer) {
assert(transformer != null);
// _motionEventConverter._pointTransformer = transformer;
}

bool get isCreated => _state == _TizenViewState.created;
Expand Down Expand Up @@ -182,7 +177,7 @@ class TizenViewController extends PlatformViewController {
await SystemChannels.platform_views
.invokeMethod<void>('setDirection', <String, dynamic>{
'id': viewId,
// 'direction': layoutDirection,
'direction': layoutDirection == TextDirection.ltr ? 0 : 1,
});
}

Expand Down Expand Up @@ -218,13 +213,14 @@ class TizenViewController extends PlatformViewController {
if (_state != _TizenViewState.created) {
return Future<void>.value();
}
// print('clearFocus : $viewId');
print('TizenViewController::clearFocus() : $viewId');
return SystemChannels.platform_views
.invokeMethod<void>('clearFocus', viewId);
}

@override
Future<void> dispose() async {
print('TizenViewController::dispose()');
if (_state == _TizenViewState.creating || _state == _TizenViewState.created)
await _sendDisposeMessage();
_platformViewCreatedCallbacks.clear();
Expand All @@ -233,8 +229,8 @@ class TizenViewController extends PlatformViewController {
}
}

class TizenWebView_ extends StatefulWidget {
const TizenWebView_({
class TizenView extends StatefulWidget {
const TizenView({
Key key,
@required this.viewType,
this.onPlatformViewCreated,
Expand All @@ -257,7 +253,7 @@ class TizenWebView_ extends StatefulWidget {
final MessageCodec<dynamic> creationParamsCodec;

@override
State<TizenWebView_> createState() => _TizenWebViewState();
State<TizenView> createState() => _TizenWebViewState();
}

class PlatformViewsServiceTizen {
Expand All @@ -268,9 +264,11 @@ class PlatformViewsServiceTizen {
PlatformViewsServiceTizen._();

Future<void> _onMethodCall(MethodCall call) {
print('TizenView::_onMethodCall() - ${call.method}');
switch (call.method) {
case 'viewFocused':
final int id = call.arguments as int;
print('viewFocused: id - $id');
if (_focusCallbacks.containsKey(id)) {
if (_focusCallbacks[id] != null) {
_focusCallbacks[id]();
Expand Down Expand Up @@ -301,6 +299,9 @@ class PlatformViewsServiceTizen {
assert(layoutDirection != null);
assert(creationParams == null || creationParamsCodec != null);

print(
'PlatformViewsServiceTizen::initTizenView [id:$id] [onFocus:$onFocus]');

final TizenViewController controller = TizenViewController._(
viewId: id,
viewType: viewType,
Expand Down Expand Up @@ -444,12 +445,12 @@ class RenderTizenView extends RenderBox with _PlatformViewGestureMixin {
_viewController.pointTransformer = (Offset offset) => globalToLocal(offset);
updateGestureRecognizers(gestureRecognizers);
_viewController.addOnPlatformViewCreatedListener(_onPlatformViewCreated);
// this.hitTestBehavior = hitTestBehavior;
this.hitTestBehavior = hitTestBehavior;
}

_PlatformViewState _state = _PlatformViewState.uninitialized;

get viewcontroller => _viewController;
TizenViewController get viewcontroller => _viewController;
TizenViewController _viewController;

set viewController(TizenViewController viewController) {
Expand Down Expand Up @@ -570,12 +571,12 @@ class _TizenPlatformTextureView extends LeafRenderObjectWidget {
@override
void updateRenderObject(BuildContext context, RenderTizenView renderObject) {
renderObject.viewController = controller;
// renderObject.hitTestBehavior = hitTestBehavior;
renderObject.hitTestBehavior = hitTestBehavior;
renderObject.updateGestureRecognizers(gestureRecognizers);
}
}

class _TizenWebViewState extends State<TizenWebView_> {
class _TizenWebViewState extends State<TizenView> {
int _id;
TizenViewController _controller;
TextDirection _layoutDirection;
Expand Down Expand Up @@ -611,6 +612,7 @@ class _TizenWebViewState extends State<TizenWebView_> {

@override
void didChangeDependencies() {
print('_TizenWebViewState::didChangeDependencies()');
super.didChangeDependencies();
final TextDirection newLayoutDirection = _findLayoutDirection();
final bool didChangeLayoutDirection =
Expand All @@ -624,8 +626,8 @@ class _TizenWebViewState extends State<TizenWebView_> {
}

@override
void didUpdateWidget(TizenWebView_ oldWidget) {
// print('webview: didUpdateWidget()');
void didUpdateWidget(TizenView oldWidget) {
print('_TizenWebViewState::didUpdateWidget()');
super.didUpdateWidget(oldWidget);

final TextDirection newLayoutDirection = _findLayoutDirection();
Expand All @@ -652,6 +654,7 @@ class _TizenWebViewState extends State<TizenWebView_> {

@override
void dispose() {
print('_TizenWebViewState::dispose()');
_controller.dispose();
super.dispose();
}
Expand All @@ -665,6 +668,7 @@ class _TizenWebViewState extends State<TizenWebView_> {
creationParams: widget.creationParams,
creationParamsCodec: widget.creationParamsCodec,
onFocus: () {
print('_TizenWebViewState::_createNewTizenWebView() - onFocus()');
_focusNode.requestFocus();
},
);
Expand All @@ -675,9 +679,11 @@ class _TizenWebViewState extends State<TizenWebView_> {
}

void _onFocusChange(bool isFocused) {
print('_TizenWebViewState::_onFocusChange(isFocused:$isFocused)');
if (!_controller.isCreated) {
return;
}

if (!isFocused) {
_controller.clearFocus().catchError((dynamic e) {
if (e is MissingPluginException) {
Expand All @@ -686,7 +692,6 @@ class _TizenWebViewState extends State<TizenWebView_> {
});
return;
}
// print('_onFocusChange - viewId : $_id');
SystemChannels.textInput
.invokeMethod<void>(
'TextInput.setPlatformViewClient',
Expand Down Expand Up @@ -725,7 +730,7 @@ class TizenWebView implements WebViewPlatform {
return GestureDetector(
onLongPress: () {},
excludeFromSemantics: true,
child: TizenWebView_(
child: TizenView(
viewType: 'plugins.flutter.io/webview',
onPlatformViewCreated: (int id) {
if (onWebViewPlatformCreated == null) {
Expand Down Expand Up @@ -769,7 +774,7 @@ mixin _PlatformViewGestureMixin on RenderBox implements MouseTrackerAnnotation {
if (value != _hitTestBehavior) {
_hitTestBehavior = value;
if (owner != null) {
//RendererBinding.instance.mouseTracker.schedulePostFrameCheck();
markNeedsPaint();
}
}
}
Expand Down