mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Implement quantum ink splashes
These aren't 100% correct, but they look somewhat reasonable. R=eseidel@chromium.org Review URL: https://codereview.chromium.org/954023002
This commit is contained in:
parent
d8b20c7f2b
commit
c149c2802d
@ -3,6 +3,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
-->
|
||||
<import src="/sky/framework/material-element.sky" />
|
||||
<import src="/sky/framework/sky-element.sky" />
|
||||
<import src="stock-arrow.sky" />
|
||||
|
||||
@ -46,7 +47,7 @@
|
||||
import "dart:sky";
|
||||
|
||||
@Tagname('stock')
|
||||
class Stock extends SkyElement {
|
||||
class Stock extends MaterialElement {
|
||||
var model; // model.Stock
|
||||
|
||||
void shadowRootReady() {
|
||||
|
||||
30
framework/material-element.sky
Normal file
30
framework/material-element.sky
Normal file
@ -0,0 +1,30 @@
|
||||
<!--
|
||||
// Copyright 2015 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
-->
|
||||
<import src="sky-element.sky" />
|
||||
<import src="sky-ink-splash.sky" />
|
||||
<script>
|
||||
import "dart:sky";
|
||||
|
||||
HTMLStyleElement _kStyleElement;
|
||||
|
||||
class MaterialElement extends SkyElement {
|
||||
MaterialElement() {
|
||||
addEventListener('pointerdown', _handlePointerDown);
|
||||
}
|
||||
|
||||
void _handlePointerDown(PointerEvent event) {
|
||||
// We set the transform here to become a container for absolutely positioned
|
||||
// elements. We should either have a better way of becoming such a container
|
||||
// or we should make every RenderBlock be such a container.
|
||||
style['transform'] = 'translateX(0)';
|
||||
|
||||
ClientRect rect = getBoundingClientRect();
|
||||
SkyInkSplash splash = new SkyInkSplash();
|
||||
shadowRoot.prependChild(splash);
|
||||
splash.start(event.x, event.y, rect);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@ -144,7 +144,7 @@ class SkyDrawer extends SkyElement implements AnimationDelegate {
|
||||
}
|
||||
|
||||
void _handleFlingStart(event) {
|
||||
double direction = event.velocityX.sign();
|
||||
double direction = event.velocityX.sign;
|
||||
double velocityX = event.velocityX.abs() / 1000;
|
||||
if (velocityX < _kMinFlingVelocity)
|
||||
return;
|
||||
|
||||
84
framework/sky-ink-splash.sky
Normal file
84
framework/sky-ink-splash.sky
Normal file
@ -0,0 +1,84 @@
|
||||
<!--
|
||||
// Copyright 2015 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
-->
|
||||
<import src="sky-element.sky" />
|
||||
|
||||
<sky-element>
|
||||
<template>
|
||||
<style>
|
||||
:host {
|
||||
position: absolute;
|
||||
pointer-events: none;
|
||||
overflow: hidden;
|
||||
top: 0;
|
||||
left: 0;
|
||||
bottom: 0;
|
||||
right: 0;
|
||||
}
|
||||
|
||||
#splash {
|
||||
position: absolute;
|
||||
background-color: rgba(0, 0, 0, 0.4);
|
||||
border-radius: 0;
|
||||
top: 0;
|
||||
left: 0;
|
||||
height: 0;
|
||||
width: 0;
|
||||
}
|
||||
</style>
|
||||
<div id="splash" />
|
||||
</template>
|
||||
<script>
|
||||
import "animation/controller.dart";
|
||||
import "animation/curves.dart";
|
||||
import "animation/timer.dart";
|
||||
import "dart:math" as math;
|
||||
import "dart:sky";
|
||||
|
||||
const double _kSplashSize = 400.0;
|
||||
const double _kSplashDuration = 500.0;
|
||||
|
||||
@Tagname('sky-ink-splash')
|
||||
class SkyInkSplash extends SkyElement implements AnimationDelegate {
|
||||
AnimationController _animation;
|
||||
Element _splash;
|
||||
double _offsetX;
|
||||
double _offsetY;
|
||||
|
||||
SkyInkSplash() {
|
||||
_animation = new AnimationController(this);
|
||||
}
|
||||
|
||||
void shadowRootReady() {
|
||||
_splash = shadowRoot.getElementById('splash');
|
||||
}
|
||||
|
||||
void start(double x, double y, ClientRect rect) {
|
||||
_offsetX = x - rect.left;
|
||||
_offsetY = y - rect.top;
|
||||
_animation.start(
|
||||
begin: 0.0,
|
||||
end: _kSplashSize,
|
||||
duration: _kSplashDuration,
|
||||
curve: easeOut);
|
||||
}
|
||||
|
||||
void updateAnimation(double p) {
|
||||
if (p == _kSplashSize) {
|
||||
remove();
|
||||
return;
|
||||
}
|
||||
_splash.style['top'] = '${_offsetY - p/2}px';
|
||||
_splash.style['left'] = '${_offsetX - p/2}px';
|
||||
_splash.style['width'] = '${p}px';
|
||||
_splash.style['height'] = '${p}px';
|
||||
_splash.style['border-radius'] = '${p}px';
|
||||
_splash.style['opacity'] = '${1.0 - (p / _kSplashSize)}';
|
||||
}
|
||||
}
|
||||
|
||||
_init(script) => register(script, SkyInkSplash);
|
||||
</script>
|
||||
</sky-element>
|
||||
Loading…
x
Reference in New Issue
Block a user