Commit 22f26be8 authored by Jason Simmons's avatar Jason Simmons

Update the interactive_flex example for the new event handlers

parent 4b03a9ee
...@@ -4,9 +4,13 @@ ...@@ -4,9 +4,13 @@
import 'dart:ui' as ui; import 'dart:ui' as ui;
import 'dart:math' as math; import 'dart:math' as math;
import 'dart:typed_data';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:mojo/bindings.dart' as bindings;
import 'package:mojo/core.dart' as core;
import 'package:sky_services/pointer/pointer.mojom.dart';
import 'lib/solid_color_box.dart'; import 'lib/solid_color_box.dart';
...@@ -33,15 +37,24 @@ class RenderImageGrow extends RenderImage { ...@@ -33,15 +37,24 @@ class RenderImageGrow extends RenderImage {
RenderImageGrow image; RenderImageGrow image;
final Map<int, Touch> touches = <int, Touch>{}; void handleEvent(String eventType, double timeStamp) {
void handleEvent(event) { if (eventType == "back")
if (event is ui.PointerEvent) {
if (event.type == 'pointermove')
image.growth = math.max(0.0, image.growth + event.x - touches[event.pointer].x);
touches[event.pointer] = new Touch(event.x, event.y);
}
if (event.type == "back") {
activity.finishCurrentActivity(); activity.finishCurrentActivity();
}
final Map<int, Touch> touches = <int, Touch>{};
void handlePointerPacket(ByteData serializedPacket) {
bindings.Message message = new bindings.Message(
serializedPacket,
<core.MojoHandle>[]
);
PointerPacket packet = PointerPacket.deserialize(message);
for (Pointer pointer in packet.pointers) {
if (pointer.type == PointerType.MOVE)
image.growth = math.max(0.0, image.growth + pointer.x - touches[pointer.pointer].x);
touches[pointer.pointer] = new Touch(pointer.x, pointer.y);
} }
} }
...@@ -102,4 +115,5 @@ Pancetta meatball tongue tenderloin rump tail jowl boudin."""; ...@@ -102,4 +115,5 @@ Pancetta meatball tongue tenderloin rump tail jowl boudin.""";
updateTaskDescription('Interactive Flex', topColor); updateTaskDescription('Interactive Flex', topColor);
new FlutterBinding(root: root); new FlutterBinding(root: root);
ui.window.onEvent = handleEvent; ui.window.onEvent = handleEvent;
ui.window.onPointerPacket = handlePointerPacket;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment