Skip to content
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

Fix/input click #575

Merged
merged 3 commits into from Aug 10, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions integration_tests/specs/dom/elements/input.ts
Expand Up @@ -364,4 +364,15 @@ describe('Tags input', () => {
});
});
});

it('support work with click', (done) => {
const input = document.createElement('input');
input.setAttribute('value', 'Input 1');
document.body.appendChild(input);
input.addEventListener('click', function handler() {
done();
});

simulateClick(10, 10);
});
});
21 changes: 20 additions & 1 deletion kraken/lib/src/dom/elements/input.dart
Expand Up @@ -8,6 +8,7 @@ import 'dart:collection';
import 'dart:ui';
import 'dart:ffi';
import 'dart:math' as math;
import 'package:flutter/gestures.dart';
import 'package:kraken/bridge.dart';
import 'package:flutter/animation.dart';
import 'package:flutter/foundation.dart';
Expand Down Expand Up @@ -304,12 +305,29 @@ class InputElement extends Element implements TextInputClient, TickerProvider {
void dispatchEvent(Event event) {
super.dispatchEvent(event);
if (event.type == EVENT_TOUCH_START) {
InputElement.setFocus(this);
TouchEvent e = (event as TouchEvent);
if (e.touches.length == 1) {
InputElement.setFocus(this);

Touch touch = e.touches[0];
final TapDownDetails details = TapDownDetails(
globalPosition: Offset(touch.screenX, touch.screenY),
localPosition: Offset(touch.clientX, touch.clientY),
kind: PointerDeviceKind.touch,
);

_renderEditable!.handleTapDown(details);
}

// @TODO: selection.
} else if (event.type == EVENT_TOUCH_MOVE) {
// @TODO: selection.
} else if (event.type == EVENT_TOUCH_END) {
// @TODO: selection.
} else if (event.type == EVENT_CLICK) {
_renderEditable!.handleTap();
} else if (event.type == EVENT_LONG_PRESS) {
_renderEditable!.handleLongPress();
}
}

Expand Down Expand Up @@ -411,6 +429,7 @@ class InputElement extends Element implements TextInputClient, TickerProvider {
devicePixelRatio: window.devicePixelRatio,
startHandleLayerLink: LayerLink(),
endHandleLayerLink: LayerLink(),
ignorePointer: true,
);
return _renderEditable!;
}
Expand Down